From eeaefb1ed2bee18edfb546d12af14ac672b96957 Mon Sep 17 00:00:00 2001 From: Redkale Date: Tue, 10 Jan 2023 13:13:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boot/watch/ServerWatchService.java | 6 ++-- src/main/java/org/redkale/net/Context.java | 28 +++++++-------- .../java/org/redkale/net/ProtocolServer.java | 4 +-- src/main/java/org/redkale/net/Server.java | 34 +++++++++--------- src/main/java/org/redkale/net/Transport.java | 12 +++---- .../java/org/redkale/net/client/Client.java | 20 +++++------ .../org/redkale/net/http/HttpRequest.java | 2 +- .../org/redkale/net/http/WebSocketEngine.java | 36 +++++++++---------- .../org/redkale/net/http/WebSocketNode.java | 2 +- .../redkale/net/http/WebSocketServlet.java | 2 +- .../org/redkale/source/DataJdbcSource.java | 14 ++++---- 11 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/main/java/org/redkale/boot/watch/ServerWatchService.java b/src/main/java/org/redkale/boot/watch/ServerWatchService.java index 421c2bee4..d45ef69e7 100644 --- a/src/main/java/org/redkale/boot/watch/ServerWatchService.java +++ b/src/main/java/org/redkale/boot/watch/ServerWatchService.java @@ -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()); diff --git a/src/main/java/org/redkale/net/Context.java b/src/main/java/org/redkale/net/Context.java index 1e95cb44a..e374616b1 100644 --- a/src/main/java/org/redkale/net/Context.java +++ b/src/main/java/org/redkale/net/Context.java @@ -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; diff --git a/src/main/java/org/redkale/net/ProtocolServer.java b/src/main/java/org/redkale/net/ProtocolServer.java index 3e043c8b5..c95689e8f 100644 --- a/src/main/java/org/redkale/net/ProtocolServer.java +++ b/src/main/java/org/redkale/net/ProtocolServer.java @@ -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(); } //--------------------------------------------------------------------- diff --git a/src/main/java/org/redkale/net/Server.java b/src/main/java/org/redkale/net/Server.java index 173f7b256..82ae9cf05 100644 --- a/src/main/java/org/redkale/net/Server.java +++ b/src/main/java/org/redkale/net/Server.java @@ -94,10 +94,10 @@ public abstract class Server 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(); } diff --git a/src/main/java/org/redkale/net/client/Client.java b/src/main/java/org/redkale/net/client/Client.java index 01788c5cf..501d10696 100644 --- a/src/main/java/org/redkale/net/client/Client.java +++ b/src/main/java/org/redkale/net/client/Client.java @@ -86,26 +86,26 @@ public abstract class Client 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> 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 closeRequestSupplier, Function, CompletableFuture> 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 pingRequestSupplier, Supplier closeRequestSupplier, Function, CompletableFuture> authenticate) { if (maxPipelines < 1) { throw new IllegalArgumentException("maxPipelines must bigger 0"); @@ -115,7 +115,7 @@ public abstract class Client 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; diff --git a/src/main/java/org/redkale/net/http/HttpRequest.java b/src/main/java/org/redkale/net/http/HttpRequest.java index 83db96a34..63f43ade2 100644 --- a/src/main/java/org/redkale/net/http/HttpRequest.java +++ b/src/main/java/org/redkale/net/http/HttpRequest.java @@ -362,7 +362,7 @@ public class HttpRequest extends Request { } 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())); diff --git a/src/main/java/org/redkale/net/http/WebSocketEngine.java b/src/main/java/org/redkale/net/http/WebSocketEngine.java index bd7cf6da8..02aeb9b59 100644 --- a/src/main/java/org/redkale/net/http/WebSocketEngine.java +++ b/src/main/java/org/redkale/net/http/WebSocketEngine.java @@ -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("获取所有连接") diff --git a/src/main/java/org/redkale/net/http/WebSocketNode.java b/src/main/java/org/redkale/net/http/WebSocketNode.java index b776a384e..f98d27b79 100644 --- a/src/main/java/org/redkale/net/http/WebSocketNode.java +++ b/src/main/java/org/redkale/net/http/WebSocketNode.java @@ -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); } diff --git a/src/main/java/org/redkale/net/http/WebSocketServlet.java b/src/main/java/org/redkale/net/http/WebSocketServlet.java index d5125eefe..d2380e7c4 100644 --- a/src/main/java/org/redkale/net/http/WebSocketServlet.java +++ b/src/main/java/org/redkale/net/http/WebSocketServlet.java @@ -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; } diff --git a/src/main/java/org/redkale/source/DataJdbcSource.java b/src/main/java/org/redkale/source/DataJdbcSource.java index c5e062f58..0d2499d16 100644 --- a/src/main/java/org/redkale/source/DataJdbcSource.java +++ b/src/main/java/org/redkale/source/DataJdbcSource.java @@ -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 newQueue = new ArrayBlockingQueue<>(newMaxconns); ArrayBlockingQueue 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) {