Created
July 23, 2022 00:34
-
-
Save zeroFruit/4fb8f9f9342cb1bc67ce850b92b09020 to your computer and use it in GitHub Desktop.
Channel concept & implementation— el Project (2)
This file contains 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 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