private void setActiveOnOpen(boolean activeOnOpen) { if (channel.isRegistered()) { throw new IllegalStateException("Can only changed before channel was registered"); } this.activeOnOpen = activeOnOpen; }
private void fireException(Throwable cause) { // Only fire the exception if the channel is open and registered // if not the pipeline is not setup and so it would hit the tail // of the pipeline. // See https://github.com/netty/netty/issues/1517 if (fireException && channel.isRegistered()) { channel.pipeline().fireExceptionCaught(cause); } } }
@Override protected void checkDeadLock() { if (channel().isRegistered()) { super.checkDeadLock(); } }
@Override protected void checkDeadLock() { if (channel().isRegistered()) { super.checkDeadLock(); } }
/** * {@inheritDoc} If override this method ensure you call super! */ @Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { if (ctx.channel().isRegistered()) { // This should always be true with our current DefaultChannelPipeline implementation. // The good thing about calling initChannel(...) in handlerAdded(...) is that there will be no ordering // surprises if a ChannelInitializer will add another ChannelInitializer. This is as all handlers // will be added in the expected order. initChannel(ctx); } }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { if (ctx.channel().isActive() && ctx.channel().isRegistered()) { // channelActive() event has been fired already, which means this.channelActive() will // not be invoked. We have to initialize here instead. initialize(ctx); } else { // channelActive() event has not been fired yet. this.channelActive() will be invoked // and initialization will occur there. } }
private static void registerDone(ChannelFuture future) { // Handle any errors that occurred on the local thread while registering. Even though // failures can happen after this point, they will be handled by the channel by closing the // childChannel. if (!future.isSuccess()) { Channel childChannel = future.channel(); if (childChannel.isRegistered()) { childChannel.close(); } else { childChannel.unsafe().closeForcibly(); } } }
@Override protected void run() { for (;;) { Runnable task = takeTask(); if (task != null) { task.run(); updateLastExecutionTime(); } Channel ch = this.ch; if (isShuttingDown()) { if (ch != null) { ch.unsafe().close(ch.unsafe().voidPromise()); } if (confirmShutdown()) { break; } } else { if (ch != null) { // Handle deregistration if (!ch.isRegistered()) { runAllTasks(); deregister(); } } } } }
if (channel.isRegistered()) { channel.close(); } else {