Skip to content

Commit

Permalink
美化
Browse files Browse the repository at this point in the history
  • Loading branch information
seaswalker committed Jul 14, 2020
1 parent 7549eea commit e248d5b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/main/java/context/HandlerContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,15 @@ public void setChannel(SocketChannel channel) {
* 添加Handler,用于HandlerInitializer,对HandlerContext的添加并不会影响HandlerChain.
*
* @param handler {@link Handler}
* @return this {@link HandlerContext}
*/
public HandlerContext addHandler(Handler handler) {
public void addHandler(Handler handler) {
if (handler instanceof InBoundHandler) {
inBoundHandlers.add((InBoundHandler) handler);
++inBoundSize;
} else if (handler instanceof OutBoundHandler) {
outBoundHandlers.add((OutBoundHandler) handler);
++outBoundSize;
}
return this;
}

/**
Expand Down Expand Up @@ -128,9 +126,9 @@ public void fireChannelRead(Object message) {
public void fireChannelReads(List<byte[]> messages) {
if (messages != null) {
int oldIndex = index;
for (int i = 0, s = messages.size(); i < s; i++) {
for (byte[] message : messages) {
index = oldIndex;
fireChannelRead(messages.get(i));
fireChannelRead(message);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/handler/HandlerInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public void channelActive(HandlerContext context) {
Handler[] handlers = init();
Objects.requireNonNull(handlers);
context.removeHandlerInitializer(this);
for (int i = 0, l = handlers.length; i < l; i++) {
context.addHandler(handlers[i]);
for (Handler handler : handlers) {
context.addHandler(handler);
}
context.fireChannelActive();
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/selector/QueuedSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ public void run() {
HandlerChain handlerChain = selectorManager.getHandlerChain();
HandlerContext context = new HandlerContext(
handlerChain.getInBoundHandlers(),
handlerChain.getOutBoundHandlers(), true);
handlerChain.getOutBoundHandlers(),
true
);
context.setChannel(channel);
context.setWorkerManager(workerManager);
key.attach(context);
Expand Down Expand Up @@ -207,8 +209,11 @@ private HandlerContext checkAttachment(Object attachment, SocketChannel channel)
HandlerContext context;
if (attachment == null) {
HandlerChain handlerChain = selectorManager.getHandlerChain();
context = new HandlerContext(handlerChain.getInBoundHandlers(),
handlerChain.getOutBoundHandlers(), true);
context = new HandlerContext(
handlerChain.getInBoundHandlers(),
handlerChain.getOutBoundHandlers(),
true
);
context.setChannel(channel);
context.setWorkerManager(workerManager);
} else {
Expand Down

0 comments on commit e248d5b

Please sign in to comment.