From d6d3fd09667cc99c3ede4a9912d7ed9f6d7bb5df Mon Sep 17 00:00:00 2001 From: Redkale Date: Tue, 3 Jan 2023 16:57:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96AsyncConnection=E7=9A=84Threa?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/redkale/net/AsyncConnection.java | 32 +++++-------------- .../redkale/net/client/ClientConnection.java | 2 +- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/redkale/net/AsyncConnection.java b/src/main/java/org/redkale/net/AsyncConnection.java index 4bc7e31a4..f6f27b0ed 100644 --- a/src/main/java/org/redkale/net/AsyncConnection.java +++ b/src/main/java/org/redkale/net/AsyncConnection.java @@ -16,8 +16,6 @@ import javax.net.ssl.SSLEngineResult.HandshakeStatus; import static javax.net.ssl.SSLEngineResult.HandshakeStatus.*; import static javax.net.ssl.SSLEngineResult.Status.*; import javax.net.ssl.*; -import static javax.net.ssl.SSLEngineResult.HandshakeStatus.*; -import static javax.net.ssl.SSLEngineResult.Status.*; import org.redkale.util.*; /** @@ -44,14 +42,14 @@ public abstract class AsyncConnection implements ChannelContext, Channel, AutoCl protected final AsyncGroup ioGroup; - protected final AsyncIOThread ioReadThread; - - protected final AsyncIOThread ioWriteThread; - protected final boolean client; protected final int bufferCapacity; + protected final AsyncIOThread ioReadThread; + + protected final AsyncIOThread ioWriteThread; + private final Supplier readBufferSupplier; private final Consumer readBufferConsumer; @@ -84,32 +82,18 @@ public abstract class AsyncConnection implements ChannelContext, Channel, AutoCl protected AsyncConnection(boolean client, AsyncGroup ioGroup, AsyncIOThread ioReadThread, AsyncIOThread ioWriteThread, final int bufferCapacity, SSLBuilder sslBuilder, SSLContext sslContext, final LongAdder livingCounter, final LongAdder closedCounter) { - this(client, ioGroup, ioReadThread, ioWriteThread, bufferCapacity, - ioReadThread.getBufferSupplier(), ioReadThread.getBufferConsumer(), - ioWriteThread.getBufferSupplier(), ioWriteThread.getBufferConsumer(), - sslBuilder, sslContext, livingCounter, closedCounter); - } - - protected AsyncConnection(boolean client, AsyncGroup ioGroup, AsyncIOThread ioReadThread, AsyncIOThread ioWriteThread, final int bufferCapacity, - Supplier readBufferSupplier, Consumer readBufferConsumer, - Supplier writeBufferSupplier, Consumer writeBufferConsumer, - SSLBuilder sslBuilder, SSLContext sslContext, final LongAdder livingCounter, final LongAdder closedCounter) { Objects.requireNonNull(ioGroup); Objects.requireNonNull(ioReadThread); Objects.requireNonNull(ioWriteThread); - Objects.requireNonNull(readBufferSupplier); - Objects.requireNonNull(readBufferConsumer); - Objects.requireNonNull(writeBufferSupplier); - Objects.requireNonNull(writeBufferConsumer); this.client = client; this.ioGroup = ioGroup; this.ioReadThread = ioReadThread; this.ioWriteThread = ioWriteThread; this.bufferCapacity = bufferCapacity; - this.readBufferSupplier = readBufferSupplier; - this.readBufferConsumer = readBufferConsumer; - this.writeBufferSupplier = writeBufferSupplier; - this.writeBufferConsumer = writeBufferConsumer; + this.readBufferSupplier = ioReadThread.getBufferSupplier(); + this.readBufferConsumer = ioReadThread.getBufferConsumer(); + this.writeBufferSupplier = ioWriteThread.getBufferSupplier(); + this.writeBufferConsumer = ioWriteThread.getBufferConsumer(); this.livingCounter = livingCounter; this.closedCounter = closedCounter; if (client) { //client模式下无SSLBuilder diff --git a/src/main/java/org/redkale/net/client/ClientConnection.java b/src/main/java/org/redkale/net/client/ClientConnection.java index 2570aa505..a4457d31b 100644 --- a/src/main/java/org/redkale/net/client/ClientConnection.java +++ b/src/main/java/org/redkale/net/client/ClientConnection.java @@ -348,7 +348,7 @@ public abstract class ClientConnection implements Co protected abstract ClientCodec createCodec(); - protected CompletableFuture

writeChannel(R request) { + protected final CompletableFuture

writeChannel(R request) { ClientFuture respFuture; if (request == client.closeRequest) { respFuture = createClientFuture(null);