Created
July 23, 2022 00:25
-
-
Save zeroFruit/4a85651b78fbbacb90bc35b361497e33 to your computer and use it in GitHub Desktop.
Channel concept & implementation— el Project (2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DefaultChannelPipeline implements ChannelPipeline { | |
private final Channel channel; | |
private final HeadContext headContext; | |
private final TailContext tailContext; | |
public DefaultChannelPipeline(Channel channel) { | |
this.channel = channel; | |
this.tailContext = new TailContext(this); | |
this.headContext = new HeadContext(this); | |
this.tailContext.prev = this.headContext; | |
this.headContext.next = this.tailContext; | |
} | |
@Override | |
public ChannelPipeline addLast(ChannelHandler... handlers) { | |
for (ChannelHandler handler : handlers) { | |
this.addLast(handler); | |
} | |
return this; | |
} | |
private ChannelPipeline addLast(ChannelHandler handler) { | |
final AbstractChannelHandlerContext prev = this.tailContext.prev; | |
final AbstractChannelHandlerContext newHandlerContext = | |
new DefaultChannelHandlerContext(name, this, eventLoop, handler); | |
this.tailContext.prev = newHandlerContext; | |
newHandlerContext.next = this.tailContext; | |
prev.next = newHandlerContext; | |
newHandlerContext.prev = prev; | |
return this; | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment