Skip to content

Instantly share code, notes, and snippets.

@zeroFruit
Created July 23, 2022 00:34
Show Gist options
  • Save zeroFruit/4fb8f9f9342cb1bc67ce850b92b09020 to your computer and use it in GitHub Desktop.
Save zeroFruit/4fb8f9f9342cb1bc67ce850b92b09020 to your computer and use it in GitHub Desktop.
Channel concept & implementation— el Project (2)
public abstract class AbstractChannelHandlerContext implements ChannelHandlerContext {
...
@Override
public ChannelPromise bind(SocketAddress localAddress, ChannelPromise promise) {
ObjectUtil.checkNotNull(localAddress, "localAddress");
if (isNotValidPromise(promise)) {
// canceled
return promise;
}
final AbstractChannelHandlerContext next = findContextOutbound();
final EventLoop eventLoop = next.eventLoop();
if (eventLoop.inEventLoop()) {
next.invokeBind(localAddress, promise);
} else {
safeExecute(eventLoop, () -> next.invokeBind(localAddress, promise), promise);
}
return promise;
}
private void invokeBind(SocketAddress localAddress, ChannelPromise promise) {
try {
((ChannelOutboundHandler) handler()).bind(this, localAddress, promise);
} catch (Throwable t) {
promise.setFailure(t);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment