优化命名

This commit is contained in:
Redkale
2023-01-10 13:13:41 +08:00
parent 6a605359d7
commit eeaefb1ed2
11 changed files with 80 additions and 80 deletions

View File

@@ -71,7 +71,7 @@ public class ServerWatchService extends AbstractWatchService {
server.changeAddress(application, newAddr);
} catch (IOException e) {
e.printStackTrace();
return new RetResult(RET_SERVER_CHANGEPORT_ERROR, "changeaddress error");
return new RetResult(RET_SERVER_CHANGEPORT_ERROR, "changeAddress error");
}
return RetResult.success();
}
@@ -97,8 +97,8 @@ public class ServerWatchService extends AbstractWatchService {
rs.put("bufferCapacity", server.getBufferCapacity());
rs.put("bufferPoolSize", server.getBufferPoolSize());
rs.put("charset", server.getCharset() == null ? "UTF-8" : server.getCharset().name());
rs.put("maxbody", server.getMaxbody());
rs.put("maxconns", server.getMaxconns());
rs.put("maxbody", server.getMaxBody());
rs.put("maxconns", server.getMaxConns());
rs.put("serverStartTime", server.getServerStartTime());
rs.put("responsePoolSize", server.getResponsePoolSize());
rs.put("readTimeoutSeconds", server.getReadTimeoutSeconds());

View File

@@ -5,9 +5,9 @@
*/
package org.redkale.net;
import java.net.*;
import java.net.InetSocketAddress;
import java.nio.charset.*;
import java.util.concurrent.*;
import java.util.concurrent.ExecutorService;
import java.util.logging.*;
import javax.net.ssl.SSLContext;
import org.redkale.convert.bson.*;
@@ -57,10 +57,10 @@ public class Context {
protected final ResourceFactory resourceFactory;
//最大连接数, 为0表示没限制
protected int maxconns;
protected int maxConns;
//请求内容的大小上限, 默认64K
protected int maxbody;
protected int maxBody;
//keep alive IO读取的超时时间
protected int aliveTimeoutSeconds;
@@ -79,12 +79,12 @@ public class Context {
public Context(ContextConfig config) {
this(config.serverStartTime, config.logger, config.workExecutor, config.sslBuilder, config.sslContext,
config.bufferCapacity, config.maxconns, config.maxbody, config.charset, config.serverAddress, config.resourceFactory,
config.bufferCapacity, config.maxConns, config.maxBody, config.charset, config.serverAddress, config.resourceFactory,
config.prepare, config.aliveTimeoutSeconds, config.readTimeoutSeconds, config.writeTimeoutSeconds);
}
public Context(long serverStartTime, Logger logger, ExecutorService workExecutor, SSLBuilder sslBuilder, SSLContext sslContext,
int bufferCapacity, final int maxconns, final int maxbody, Charset charset, InetSocketAddress address,
int bufferCapacity, final int maxConns, final int maxBody, Charset charset, InetSocketAddress address,
ResourceFactory resourceFactory, DispatcherServlet prepare, int aliveTimeoutSeconds, int readTimeoutSeconds, int writeTimeoutSeconds) {
this.serverStartTime = serverStartTime;
this.logger = logger;
@@ -92,8 +92,8 @@ public class Context {
this.sslBuilder = sslBuilder;
this.sslContext = sslContext;
this.bufferCapacity = bufferCapacity;
this.maxconns = maxconns;
this.maxbody = maxbody;
this.maxConns = maxConns;
this.maxBody = maxBody;
this.charset = StandardCharsets.UTF_8.equals(charset) ? null : charset;
this.serverAddress = address;
this.prepare = prepare;
@@ -171,12 +171,12 @@ public class Context {
return sslContext;
}
public int getMaxconns() {
return maxconns;
public int getMaxConns() {
return maxConns;
}
public int getMaxbody() {
return maxbody;
public int getMaxBody() {
return maxBody;
}
public InetSocketAddress getServerAddress() {
@@ -246,10 +246,10 @@ public class Context {
public Charset charset;
//请求内容的大小上限, 默认64K
public int maxbody;
public int maxBody;
//最大连接数, 为0表示没限制
public int maxconns;
public int maxConns;
//keep alive IO读取的超时时间
public int aliveTimeoutSeconds;

View File

@@ -25,7 +25,7 @@ public abstract class ProtocolServer {
protected final Context context;
//最大连接数小于1表示无限制
protected int maxconns;
protected int maxConns;
@Resource
protected Application application;
@@ -44,7 +44,7 @@ public abstract class ProtocolServer {
protected ProtocolServer(Context context) {
this.context = context;
this.maxconns = context.getMaxconns();
this.maxConns = context.getMaxConns();
}
//---------------------------------------------------------------------

View File

@@ -94,10 +94,10 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
protected int responsePoolSize;
//最大连接数, 为0表示没限制
protected int maxconns;
protected int maxConns;
//请求包大小的上限,单位:字节
protected int maxbody;
protected int maxBody;
//Keep-Alive IO读取的超时秒数小于1视为不设置
protected int aliveTimeoutSeconds;
@@ -122,12 +122,12 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
this.config = config;
this.address = new InetSocketAddress(config.getValue("host", "0.0.0.0"), config.getIntValue("port", 80));
this.charset = Charset.forName(config.getValue("charset", "UTF-8"));
this.maxconns = config.getIntValue("maxconns", 0);
this.maxConns = config.getIntValue("maxconns", 0);
this.aliveTimeoutSeconds = config.getIntValue("aliveTimeoutSeconds", 30);
this.readTimeoutSeconds = config.getIntValue("readTimeoutSeconds", 0);
this.writeTimeoutSeconds = config.getIntValue("writeTimeoutSeconds", 0);
this.backlog = parseLenth(config.getValue("backlog"), 1024);
this.maxbody = parseLenth(config.getValue("maxbody"), 64 * 1024);
this.maxBody = parseLenth(config.getValue("maxbody"), 64 * 1024);
int bufCapacity = parseLenth(config.getValue("bufferCapacity"), "UDP".equalsIgnoreCase(netprotocol) ? 1350 : 32 * 1024);
this.bufferCapacity = "UDP".equalsIgnoreCase(netprotocol) ? bufCapacity : (bufCapacity < 1024 ? 1024 : bufCapacity);
this.bufferPoolSize = config.getIntValue("bufferPoolSize", Utility.cpus() * 8);
@@ -271,8 +271,8 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
return responsePoolSize;
}
public int getMaxbody() {
return maxbody;
public int getMaxBody() {
return maxBody;
}
public int getAliveTimeoutSeconds() {
@@ -287,8 +287,8 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
return writeTimeoutSeconds;
}
public int getMaxconns() {
return maxconns;
public int getMaxConns() {
return maxConns;
}
@SuppressWarnings("unchecked")
@@ -309,7 +309,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
postStart();
logger.info(this.getClass().getSimpleName() + ("TCP".equalsIgnoreCase(netprotocol) ? "" : ("." + netprotocol)) + " listen: " + (address.getHostString() + ":" + address.getPort())
+ ", cpu: " + Utility.cpus() + ", responsePoolSize: " + responsePoolSize + ", bufferPoolSize: " + bufferPoolSize
+ ", bufferCapacity: " + formatLenth(bufferCapacity) + ", maxbody: " + formatLenth(context.maxbody)
+ ", bufferCapacity: " + formatLenth(bufferCapacity) + ", maxbody: " + formatLenth(context.maxBody)
+ ", started in " + (System.currentTimeMillis() - context.getServerStartTime()) + " ms\r\n");
}
@@ -355,13 +355,13 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
}
}
public void changeMaxconns(final int newmaxconns) {
this.maxconns = newmaxconns;
public void changeMaxconns(final int newMaxConns) {
this.maxConns = newMaxConns;
if (this.context != null) {
this.context.maxconns = newmaxconns;
this.context.maxConns = newMaxConns;
}
if (this.serverChannel != null) {
this.serverChannel.maxconns = newmaxconns;
this.serverChannel.maxConns = newMaxConns;
}
}
@@ -373,9 +373,9 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
}
public void changeMaxbody(final int newmaxbody) {
this.maxbody = newmaxbody;
this.maxBody = newmaxbody;
if (this.context != null) {
this.context.maxbody = newmaxbody;
this.context.maxBody = newmaxbody;
}
}
@@ -411,8 +411,8 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
contextConfig.sslBuilder = this.sslBuilder;
contextConfig.sslContext = this.sslContext;
contextConfig.bufferCapacity = this.bufferCapacity;
contextConfig.maxconns = this.maxconns;
contextConfig.maxbody = this.maxbody;
contextConfig.maxConns = this.maxConns;
contextConfig.maxBody = this.maxBody;
contextConfig.charset = this.charset;
contextConfig.serverAddress = this.address;
contextConfig.prepare = this.dispatcher;

View File

@@ -399,22 +399,22 @@ public final class Transport {
protected final ConcurrentHashMap<String, Object> attributes = new ConcurrentHashMap<>();
public TransportNode(int poolmaxconns, InetSocketAddress address) {
public TransportNode(int poolMaxConns, InetSocketAddress address) {
this.address = address;
this.disabletime = 0;
this.connQueue = new ArrayBlockingQueue<>(poolmaxconns);
this.connQueue = new ArrayBlockingQueue<>(poolMaxConns);
this.pollQueue = new ArrayBlockingQueue(this.connQueue.remainingCapacity() * 100);
}
@ConstructorParameters({"poolmaxconns", "address", "disabletime"})
public TransportNode(int poolmaxconns, InetSocketAddress address, long disabletime) {
@ConstructorParameters({"poolMaxConns", "address", "disabletime"})
public TransportNode(int poolMaxConns, InetSocketAddress address, long disabletime) {
this.address = address;
this.disabletime = disabletime;
this.connQueue = new LinkedBlockingQueue<>(poolmaxconns);
this.connQueue = new LinkedBlockingQueue<>(poolMaxConns);
this.pollQueue = new ArrayBlockingQueue(this.connQueue.remainingCapacity() * 100);
}
public int getPoolmaxconns() {
public int getPoolMaxConns() {
return this.connQueue.remainingCapacity() + this.connQueue.size();
}

View File

@@ -86,26 +86,26 @@ public abstract class Client<R extends ClientRequest, P> implements Resourcable
this(name, group, tcp, address, Utility.cpus(), DEFAULT_MAX_PIPELINES, null, null, null);
}
protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxconns) {
this(name, group, tcp, address, maxconns, DEFAULT_MAX_PIPELINES, null, null, null);
protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxConns) {
this(name, group, tcp, address, maxConns, DEFAULT_MAX_PIPELINES, null, null, null);
}
protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxconns, int maxPipelines) {
this(name, group, tcp, address, maxconns, maxPipelines, null, null, null);
protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxConns, int maxPipelines) {
this(name, group, tcp, address, maxConns, maxPipelines, null, null, null);
}
protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxconns,
protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxConns,
Function<CompletableFuture<ClientConnection>, CompletableFuture<ClientConnection>> authenticate) {
this(name, group, tcp, address, maxconns, DEFAULT_MAX_PIPELINES, null, null, authenticate);
this(name, group, tcp, address, maxConns, DEFAULT_MAX_PIPELINES, null, null, authenticate);
}
protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxconns,
protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxConns,
Supplier<R> closeRequestSupplier, Function<CompletableFuture<ClientConnection>, CompletableFuture<ClientConnection>> authenticate) {
this(name, group, tcp, address, maxconns, DEFAULT_MAX_PIPELINES, null, closeRequestSupplier, authenticate);
this(name, group, tcp, address, maxConns, DEFAULT_MAX_PIPELINES, null, closeRequestSupplier, authenticate);
}
@SuppressWarnings("OverridableMethodCallInConstructor")
protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxconns,
protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxConns,
int maxPipelines, Supplier<R> pingRequestSupplier, Supplier<R> closeRequestSupplier, Function<CompletableFuture<ClientConnection>, CompletableFuture<ClientConnection>> authenticate) {
if (maxPipelines < 1) {
throw new IllegalArgumentException("maxPipelines must bigger 0");
@@ -115,7 +115,7 @@ public abstract class Client<R extends ClientRequest, P> implements Resourcable
this.group = group;
this.tcp = tcp;
this.address = address;
this.connLimit = maxconns;
this.connLimit = maxConns;
this.maxPipelines = maxPipelines;
this.pingRequestSupplier = pingRequestSupplier;
this.closeRequestSupplier = closeRequestSupplier;

View File

@@ -362,7 +362,7 @@ public class HttpRequest extends Request<HttpContext> {
}
if (this.readState == READ_STATE_BODY) {
if (this.contentLength > 0 && (this.contentType == null || !this.boundary)) {
if (this.contentLength > context.getMaxbody()) {
if (this.contentLength > context.getMaxBody()) {
return -1;
}
bytes.put(buffer, Math.min((int) this.contentLength, buffer.remaining()));

View File

@@ -68,32 +68,32 @@ public class WebSocketEngine {
protected int liveinterval;
@Comment("最大连接数, 为0表示无限制")
protected int wsmaxconns;
protected int wsMaxConns;
@Comment("操作WebSocketNode对应CacheSource并发数, 为-1表示无限制为0表示系统默认值(CPU*8)")
protected int wsthreads;
protected int wsThreads;
@Comment("最大消息体长度, 小于1表示无限制")
protected int wsmaxbody;
protected int wsMaxBody;
@Comment("接收客户端的分包(last=false)消息时是否自动合并包")
protected boolean mergemsg = true;
protected boolean mergeMode = true;
@Comment("加密解密器")
protected Cryptor cryptor;
protected WebSocketEngine(String engineid, boolean single, HttpContext context, int liveinterval, int wsmaxconns,
int wsthreads, int wsmaxbody, boolean mergemsg, Cryptor cryptor, WebSocketNode node, Convert sendConvert, Logger logger) {
protected WebSocketEngine(String engineid, boolean single, HttpContext context, int liveinterval, int wsMaxConns,
int wsThreads, int wsMaxBody, boolean mergeMode, Cryptor cryptor, WebSocketNode node, Convert sendConvert, Logger logger) {
this.engineid = engineid;
this.single = single;
this.context = context;
this.sendConvert = sendConvert;
this.node = node;
this.liveinterval = liveinterval;
this.wsmaxconns = wsmaxconns;
this.wsthreads = wsthreads;
this.wsmaxbody = wsmaxbody;
this.mergemsg = mergemsg;
this.wsMaxConns = wsMaxConns;
this.wsThreads = wsThreads;
this.wsMaxBody = wsMaxBody;
this.mergeMode = mergeMode;
this.cryptor = cryptor;
this.logger = logger;
this.index = sequence.getAndIncrement();
@@ -109,13 +109,13 @@ public class WebSocketEngine {
return;
}
if (props != null) {
this.wsmaxconns = props.getIntValue(WEBPARAM__WSMAXCONNS, this.wsmaxconns);
this.wsMaxConns = props.getIntValue(WEBPARAM__WSMAXCONNS, this.wsMaxConns);
}
if (props != null) {
this.wsthreads = props.getIntValue(WEBPARAM__WSTHREADS, this.wsthreads);
this.wsThreads = props.getIntValue(WEBPARAM__WSTHREADS, this.wsThreads);
}
if (props != null) {
this.wsmaxbody = props.getIntValue(WEBPARAM__WSMAXBODY, this.wsmaxbody);
this.wsMaxBody = props.getIntValue(WEBPARAM__WSMAXBODY, this.wsMaxBody);
}
if (scheduler != null) {
return;
@@ -136,7 +136,7 @@ public class WebSocketEngine {
}
}, delay, liveinterval, TimeUnit.SECONDS);
if (logger.isLoggable(Level.FINEST)) {
logger.finest(this.getClass().getSimpleName() + "(" + engineid + ")" + " start keeplive(wsmaxconns:" + wsmaxconns + ", delay:" + delay + "s, interval:" + liveinterval + "s) scheduler executor");
logger.finest(this.getClass().getSimpleName() + "(" + engineid + ")" + " start keeplive(wsmaxconns:" + wsMaxConns + ", delay:" + delay + "s, interval:" + liveinterval + "s) scheduler executor");
}
}
@@ -467,16 +467,16 @@ public class WebSocketEngine {
}
@Comment("获取最大连接数")
public int getLocalWsmaxconns() {
return this.wsmaxconns;
public int getLocalWsMaxConns() {
return this.wsMaxConns;
}
@Comment("连接数是否达到上限")
public boolean isLocalConnLimited() {
if (this.wsmaxconns < 1) {
if (this.wsMaxConns < 1) {
return false;
}
return currconns.get() >= this.wsmaxconns;
return currconns.get() >= this.wsMaxConns;
}
@Comment("获取所有连接")

View File

@@ -74,7 +74,7 @@ public abstract class WebSocketNode {
this.tryAcquireSeconds = Integer.getInteger("redkale.http.websocket.tryAcquireSeconds", 12);
if (localEngine != null) {
int wsthreads = localEngine.wsthreads;
int wsthreads = localEngine.wsThreads;
if (wsthreads == 0) wsthreads = Utility.cpus() * 8;
if (wsthreads > 0) this.semaphore = new Semaphore(wsthreads);
}

View File

@@ -208,7 +208,7 @@ public abstract class WebSocketServlet extends HttpServlet implements Resourcabl
return;
}
if (this.node.localEngine.isLocalConnLimited()) {
if (debug) logger.finest("WebSocket connections limit, wsmaxconns=" + this.node.localEngine.getLocalWsmaxconns());
if (debug) logger.finest("WebSocket connections limit, wsmaxconns=" + this.node.localEngine.getLocalWsMaxConns());
response.finish(true);
return;
}

View File

@@ -2528,7 +2528,7 @@ public class DataJdbcSource extends DataSqlSource {
protected int connectTimeoutSeconds;
protected int maxconns;
protected int maxConns;
protected String url;
@@ -2538,8 +2538,8 @@ public class DataJdbcSource extends DataSqlSource {
public ConnectionPool(Properties prop) {
this.connectTimeoutSeconds = Integer.decode(prop.getProperty(DATA_SOURCE_CONNECTTIMEOUT_SECONDS, "6"));
this.maxconns = Math.max(1, Integer.decode(prop.getProperty(DATA_SOURCE_MAXCONNS, "" + Utility.cpus() * 4)));
this.queue = new ArrayBlockingQueue<>(maxconns);
this.maxConns = Math.max(1, Integer.decode(prop.getProperty(DATA_SOURCE_MAXCONNS, "" + Utility.cpus() * 4)));
this.queue = new ArrayBlockingQueue<>(maxConns);
this.url = prop.getProperty(DATA_SOURCE_URL);
String username = prop.getProperty(DATA_SOURCE_USER, "");
String password = prop.getProperty(DATA_SOURCE_PASSWORD, "");
@@ -2562,7 +2562,7 @@ public class DataJdbcSource extends DataSqlSource {
public synchronized void onResourceChange(ResourceEvent[] events) {
String newUrl = this.url;
int newConnectTimeoutSeconds = this.connectTimeoutSeconds;
int newMaxconns = this.maxconns;
int newMaxconns = this.maxConns;
String newUser = this.connectAttrs.getProperty("user");
String newPassword = this.connectAttrs.getProperty("password");
for (ResourceEvent event : events) {
@@ -2589,11 +2589,11 @@ public class DataJdbcSource extends DataSqlSource {
this.connectTimeoutSeconds = newConnectTimeoutSeconds;
this.connectAttrs.put("user", newUser);
this.connectAttrs.put("password", newPassword);
if (newMaxconns != this.maxconns) {
if (newMaxconns != this.maxConns) {
ArrayBlockingQueue<Connection> newQueue = new ArrayBlockingQueue<>(newMaxconns);
ArrayBlockingQueue<Connection> oldQueue = this.queue;
this.queue = newQueue;
this.maxconns = newMaxconns;
this.maxConns = newMaxconns;
Connection conn;
while ((conn = oldQueue.poll()) != null) {
offerConnection(conn);
@@ -2604,7 +2604,7 @@ public class DataJdbcSource extends DataSqlSource {
public synchronized Connection pollConnection() {
Connection conn = queue.poll();
if (conn == null) {
if (usingCounter.intValue() >= maxconns) {
if (usingCounter.intValue() >= maxConns) {
try {
conn = queue.poll(connectTimeoutSeconds, TimeUnit.SECONDS);
} catch (InterruptedException t) {