优化命名
This commit is contained in:
@@ -13,8 +13,6 @@ import java.util.*;
|
|||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
|
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 javax.net.ssl.*;
|
||||||
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.*;
|
||||||
@@ -42,7 +40,7 @@ public abstract class AsyncConnection implements ChannelContext, Channel, AutoCl
|
|||||||
|
|
||||||
private Object subobject; //用于存储绑定在Connection上的对象, 同attributes, 只绑定单个对象时尽量使用subobject而非attributes
|
private Object subobject; //用于存储绑定在Connection上的对象, 同attributes, 只绑定单个对象时尽量使用subobject而非attributes
|
||||||
|
|
||||||
protected final AsyncGroup ioGroup;
|
protected final AsyncIOGroup ioGroup;
|
||||||
|
|
||||||
protected final boolean client;
|
protected final boolean client;
|
||||||
|
|
||||||
@@ -82,7 +80,7 @@ public abstract class AsyncConnection implements ChannelContext, Channel, AutoCl
|
|||||||
//用于服务端的Socket, 等同于一直存在的readCompletionHandler
|
//用于服务端的Socket, 等同于一直存在的readCompletionHandler
|
||||||
ProtocolCodec protocolCodec;
|
ProtocolCodec protocolCodec;
|
||||||
|
|
||||||
protected AsyncConnection(boolean client, AsyncGroup ioGroup, AsyncIOThread ioReadThread, AsyncIOThread ioWriteThread,
|
protected AsyncConnection(boolean client, AsyncIOGroup 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) {
|
||||||
Objects.requireNonNull(ioGroup);
|
Objects.requireNonNull(ioGroup);
|
||||||
Objects.requireNonNull(ioReadThread);
|
Objects.requireNonNull(ioReadThread);
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ abstract class AsyncNioConnection extends AsyncConnection {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
((AsyncIOGroup) ioGroup).interestOpsOr(ioReadThread, readKey, SelectionKey.OP_READ);
|
ioGroup.interestOpsOr(ioReadThread, readKey, SelectionKey.OP_READ);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleRead(0, e);
|
handleRead(0, e);
|
||||||
@@ -301,7 +301,7 @@ abstract class AsyncNioConnection extends AsyncConnection {
|
|||||||
final boolean invokeDirect = direct;
|
final boolean invokeDirect = direct;
|
||||||
int totalCount = 0;
|
int totalCount = 0;
|
||||||
boolean hasRemain = true;
|
boolean hasRemain = true;
|
||||||
boolean writeOver = true;
|
boolean writeCompleted = true;
|
||||||
if (invokeDirect) {
|
if (invokeDirect) {
|
||||||
currWriteInvoker++;
|
currWriteInvoker++;
|
||||||
}
|
}
|
||||||
@@ -373,7 +373,7 @@ abstract class AsyncNioConnection extends AsyncConnection {
|
|||||||
}
|
}
|
||||||
if (writeCount == 0) {
|
if (writeCount == 0) {
|
||||||
if (hasRemain) {
|
if (hasRemain) {
|
||||||
writeOver = false;
|
writeCompleted = false;
|
||||||
writeTotal = totalCount;
|
writeTotal = totalCount;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -390,7 +390,7 @@ abstract class AsyncNioConnection extends AsyncConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writeOver && (totalCount != 0 || !hasRemain)) {
|
if (writeCompleted && (totalCount != 0 || !hasRemain)) {
|
||||||
handleWrite(writeTotal + totalCount, null);
|
handleWrite(writeTotal + totalCount, null);
|
||||||
} else if (writeKey == null) {
|
} else if (writeKey == null) {
|
||||||
ioWriteThread.register(selector -> {
|
ioWriteThread.register(selector -> {
|
||||||
@@ -402,7 +402,7 @@ abstract class AsyncNioConnection extends AsyncConnection {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
((AsyncIOGroup) ioGroup).interestOpsOr(ioWriteThread, writeKey, SelectionKey.OP_WRITE);
|
ioGroup.interestOpsOr(ioWriteThread, writeKey, SelectionKey.OP_WRITE);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
handleWrite(0, e);
|
handleWrite(0, e);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public abstract class Request<C extends Context> {
|
|||||||
|
|
||||||
protected int pipelineCount;
|
protected int pipelineCount;
|
||||||
|
|
||||||
protected boolean pipelineOver;
|
protected boolean pipelineCompleted;
|
||||||
|
|
||||||
protected int hashid;
|
protected int hashid;
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ public abstract class Request<C extends Context> {
|
|||||||
this.keepAlive = request.keepAlive;
|
this.keepAlive = request.keepAlive;
|
||||||
this.pipelineIndex = request.pipelineIndex;
|
this.pipelineIndex = request.pipelineIndex;
|
||||||
this.pipelineCount = request.pipelineCount;
|
this.pipelineCount = request.pipelineCount;
|
||||||
this.pipelineOver = request.pipelineOver;
|
this.pipelineCompleted = request.pipelineCompleted;
|
||||||
this.hashid = request.hashid;
|
this.hashid = request.hashid;
|
||||||
this.traceid = request.traceid;
|
this.traceid = request.traceid;
|
||||||
this.channel = request.channel;
|
this.channel = request.channel;
|
||||||
@@ -101,7 +101,7 @@ public abstract class Request<C extends Context> {
|
|||||||
createTime = 0;
|
createTime = 0;
|
||||||
pipelineIndex = 0;
|
pipelineIndex = 0;
|
||||||
pipelineCount = 0;
|
pipelineCount = 0;
|
||||||
pipelineOver = false;
|
pipelineCompleted = false;
|
||||||
keepAlive = false;
|
keepAlive = false;
|
||||||
attributes.clear();
|
attributes.clear();
|
||||||
channel = null; // close it by response
|
channel = null; // close it by response
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public abstract class Response<C extends Context, R extends Request<C>> {
|
|||||||
this.output = null;
|
this.output = null;
|
||||||
this.filter = null;
|
this.filter = null;
|
||||||
this.servlet = null;
|
this.servlet = null;
|
||||||
boolean notpipeline = request.pipelineIndex == 0 || request.pipelineOver;
|
boolean notpipeline = request.pipelineIndex == 0 || request.pipelineCompleted;
|
||||||
request.recycle();
|
request.recycle();
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
if (notpipeline) {
|
if (notpipeline) {
|
||||||
@@ -224,7 +224,7 @@ public abstract class Response<C extends Context, R extends Request<C>> {
|
|||||||
}
|
}
|
||||||
this.recycleListener = null;
|
this.recycleListener = null;
|
||||||
}
|
}
|
||||||
if (request.keepAlive && (request.pipelineIndex == 0 || request.pipelineOver)) {
|
if (request.keepAlive && (request.pipelineIndex == 0 || request.pipelineCompleted)) {
|
||||||
AsyncConnection conn = removeChannel();
|
AsyncConnection conn = removeChannel();
|
||||||
if (conn != null && conn.protocolCodec != null) {
|
if (conn != null && conn.protocolCodec != null) {
|
||||||
this.responseConsumer.accept(this);
|
this.responseConsumer.accept(this);
|
||||||
|
|||||||
@@ -258,8 +258,8 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
return maybews && "Upgrade".equalsIgnoreCase(getHeader("Connection")) && "GET".equalsIgnoreCase(method);
|
return maybews && "Upgrade".equalsIgnoreCase(getHeader("Connection")) && "GET".equalsIgnoreCase(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setPipelineOver(boolean pipelineOver) {
|
protected void setPipelineCompleted(boolean pipelineCompleted) {
|
||||||
this.pipelineOver = pipelineOver;
|
this.pipelineCompleted = pipelineCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setKeepAlive(boolean keepAlive) {
|
protected void setKeepAlive(boolean keepAlive) {
|
||||||
|
|||||||
@@ -963,7 +963,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
if (pipelineIndex > 0) {
|
if (pipelineIndex > 0) {
|
||||||
boolean over = this.channel.writePipelineData(pipelineIndex, request.getPipelineCount(), data);
|
boolean over = this.channel.writePipelineData(pipelineIndex, request.getPipelineCount(), data);
|
||||||
if (over) {
|
if (over) {
|
||||||
request.setPipelineOver(true);
|
request.setPipelineCompleted(true);
|
||||||
this.channel.flushPipelineData(this.pipelineWriteHandler);
|
this.channel.flushPipelineData(this.pipelineWriteHandler);
|
||||||
} else {
|
} else {
|
||||||
removeChannel();
|
removeChannel();
|
||||||
|
|||||||
Reference in New Issue
Block a user