优化AsyncConnection的Thread
This commit is contained in:
@@ -16,8 +16,6 @@ import javax.net.ssl.SSLEngineResult.HandshakeStatus;
|
|||||||
import static javax.net.ssl.SSLEngineResult.HandshakeStatus.*;
|
import static javax.net.ssl.SSLEngineResult.HandshakeStatus.*;
|
||||||
import static javax.net.ssl.SSLEngineResult.Status.*;
|
import static javax.net.ssl.SSLEngineResult.Status.*;
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
import static javax.net.ssl.SSLEngineResult.HandshakeStatus.*;
|
|
||||||
import static javax.net.ssl.SSLEngineResult.Status.*;
|
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,14 +42,14 @@ public abstract class AsyncConnection implements ChannelContext, Channel, AutoCl
|
|||||||
|
|
||||||
protected final AsyncGroup ioGroup;
|
protected final AsyncGroup ioGroup;
|
||||||
|
|
||||||
protected final AsyncIOThread ioReadThread;
|
|
||||||
|
|
||||||
protected final AsyncIOThread ioWriteThread;
|
|
||||||
|
|
||||||
protected final boolean client;
|
protected final boolean client;
|
||||||
|
|
||||||
protected final int bufferCapacity;
|
protected final int bufferCapacity;
|
||||||
|
|
||||||
|
protected final AsyncIOThread ioReadThread;
|
||||||
|
|
||||||
|
protected final AsyncIOThread ioWriteThread;
|
||||||
|
|
||||||
private final Supplier<ByteBuffer> readBufferSupplier;
|
private final Supplier<ByteBuffer> readBufferSupplier;
|
||||||
|
|
||||||
private final Consumer<ByteBuffer> readBufferConsumer;
|
private final Consumer<ByteBuffer> readBufferConsumer;
|
||||||
@@ -84,32 +82,18 @@ public abstract class AsyncConnection implements ChannelContext, Channel, AutoCl
|
|||||||
|
|
||||||
protected AsyncConnection(boolean client, AsyncGroup ioGroup, AsyncIOThread ioReadThread, AsyncIOThread ioWriteThread,
|
protected AsyncConnection(boolean client, AsyncGroup ioGroup, AsyncIOThread ioReadThread, AsyncIOThread ioWriteThread,
|
||||||
final int bufferCapacity, SSLBuilder sslBuilder, SSLContext sslContext, final LongAdder livingCounter, final LongAdder closedCounter) {
|
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<ByteBuffer> readBufferSupplier, Consumer<ByteBuffer> readBufferConsumer,
|
|
||||||
Supplier<ByteBuffer> writeBufferSupplier, Consumer<ByteBuffer> writeBufferConsumer,
|
|
||||||
SSLBuilder sslBuilder, SSLContext sslContext, final LongAdder livingCounter, final LongAdder closedCounter) {
|
|
||||||
Objects.requireNonNull(ioGroup);
|
Objects.requireNonNull(ioGroup);
|
||||||
Objects.requireNonNull(ioReadThread);
|
Objects.requireNonNull(ioReadThread);
|
||||||
Objects.requireNonNull(ioWriteThread);
|
Objects.requireNonNull(ioWriteThread);
|
||||||
Objects.requireNonNull(readBufferSupplier);
|
|
||||||
Objects.requireNonNull(readBufferConsumer);
|
|
||||||
Objects.requireNonNull(writeBufferSupplier);
|
|
||||||
Objects.requireNonNull(writeBufferConsumer);
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.ioGroup = ioGroup;
|
this.ioGroup = ioGroup;
|
||||||
this.ioReadThread = ioReadThread;
|
this.ioReadThread = ioReadThread;
|
||||||
this.ioWriteThread = ioWriteThread;
|
this.ioWriteThread = ioWriteThread;
|
||||||
this.bufferCapacity = bufferCapacity;
|
this.bufferCapacity = bufferCapacity;
|
||||||
this.readBufferSupplier = readBufferSupplier;
|
this.readBufferSupplier = ioReadThread.getBufferSupplier();
|
||||||
this.readBufferConsumer = readBufferConsumer;
|
this.readBufferConsumer = ioReadThread.getBufferConsumer();
|
||||||
this.writeBufferSupplier = writeBufferSupplier;
|
this.writeBufferSupplier = ioWriteThread.getBufferSupplier();
|
||||||
this.writeBufferConsumer = writeBufferConsumer;
|
this.writeBufferConsumer = ioWriteThread.getBufferConsumer();
|
||||||
this.livingCounter = livingCounter;
|
this.livingCounter = livingCounter;
|
||||||
this.closedCounter = closedCounter;
|
this.closedCounter = closedCounter;
|
||||||
if (client) { //client模式下无SSLBuilder
|
if (client) { //client模式下无SSLBuilder
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ public abstract class ClientConnection<R extends ClientRequest, P> implements Co
|
|||||||
|
|
||||||
protected abstract ClientCodec createCodec();
|
protected abstract ClientCodec createCodec();
|
||||||
|
|
||||||
protected CompletableFuture<P> writeChannel(R request) {
|
protected final CompletableFuture<P> writeChannel(R request) {
|
||||||
ClientFuture respFuture;
|
ClientFuture respFuture;
|
||||||
if (request == client.closeRequest) {
|
if (request == client.closeRequest) {
|
||||||
respFuture = createClientFuture(null);
|
respFuture = createClientFuture(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user