public interface ChannelHandlerContext extends AttributeMap, ChannelInboundInvoker, ChannelOutboundInvoker
ChannelHandler to interact with its ChannelPipeline
and other handlers. Among other things a handler can notify the next ChannelHandler in the
ChannelPipeline as well as modify the ChannelPipeline it belongs to dynamically.
ChannelPipeline by calling one of the various methods
provided here.
Please refer to ChannelPipeline to understand how an event flows.
ChannelPipeline your handler belongs to by calling
pipeline(). A non-trivial application could insert, remove, or
replace handlers in the pipeline dynamically at runtime.
ChannelHandlerContext for later use, such as
triggering an event outside the handler methods, even from a different thread.
public class MyHandler extendsChannelDuplexHandler{ privateChannelHandlerContextctx; public void beforeAdd(ChannelHandlerContextctx) { this.ctx = ctx; } public void login(String username, password) { ctx.write(new LoginMessage(username, password)); } ... }
attr(AttributeKey) allow you to
store and access stateful information that is related with a ChannelHandler / Channel and its
context. Please refer to ChannelHandler to learn various recommended
ways to manage stateful information.
ChannelHandlerContextChannelHandler instance can be added to more than
one ChannelPipeline. It means a single ChannelHandler
instance can have more than one ChannelHandlerContext and therefore
the single instance can be invoked with different
ChannelHandlerContexts if it is added to one or more ChannelPipelines more than once.
Also note that a ChannelHandler that is supposed to be added to multiple ChannelPipelines should
be marked as ChannelHandler.Sharable.
Please refer to the ChannelHandler, and
ChannelPipeline to find out more about inbound and outbound operations,
what fundamental differences they have, how they flow in a pipeline, and how to handle
the operation in your application.
bind, bind, close, close, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, voidPromise, write, write, writeAndFlush, writeAndFlushChannel channel()
Channel which is bound to the ChannelHandlerContext.EventExecutor executor()
EventExecutor which is used to execute an arbitrary task.String name()
ChannelHandlerContext.The name was used when then ChannelHandler
was added to the ChannelPipeline. This name can also be used to access the registered
ChannelHandler from the ChannelPipeline.ChannelHandler handler()
ChannelHandler that is bound this ChannelHandlerContext.boolean isRemoved()
true if the ChannelHandler which belongs to this context was removed
from the ChannelPipeline. Note that this method is only meant to be called from with in the
EventLoop.ChannelHandlerContext fireChannelRegistered()
ChannelInboundInvokerChannel was registered to its EventLoop.
This will result in having the ChannelInboundHandler.channelRegistered(ChannelHandlerContext) method
called of the next ChannelInboundHandler contained in the ChannelPipeline of the
Channel.fireChannelRegistered in interface ChannelInboundInvokerChannelHandlerContext fireChannelUnregistered()
ChannelInboundInvokerChannel was unregistered from its EventLoop.
This will result in having the ChannelInboundHandler.channelUnregistered(ChannelHandlerContext) method
called of the next ChannelInboundHandler contained in the ChannelPipeline of the
Channel.fireChannelUnregistered in interface ChannelInboundInvokerChannelHandlerContext fireChannelActive()
ChannelInboundInvokerChannel is active now, which means it is connected.
This will result in having the ChannelInboundHandler.channelActive(ChannelHandlerContext) method
called of the next ChannelInboundHandler contained in the ChannelPipeline of the
Channel.fireChannelActive in interface ChannelInboundInvokerChannelHandlerContext fireChannelInactive()
ChannelInboundInvokerChannel is inactive now, which means it is closed.
This will result in having the ChannelInboundHandler.channelInactive(ChannelHandlerContext) method
called of the next ChannelInboundHandler contained in the ChannelPipeline of the
Channel.fireChannelInactive in interface ChannelInboundInvokerChannelHandlerContext fireExceptionCaught(Throwable cause)
ChannelInboundInvokerChannel received an Throwable in one of its inbound operations.
This will result in having the ChannelInboundHandler.exceptionCaught(ChannelHandlerContext, Throwable)
method called of the next ChannelInboundHandler contained in the ChannelPipeline of the
Channel.fireExceptionCaught in interface ChannelInboundInvokerChannelHandlerContext fireUserEventTriggered(Object evt)
ChannelInboundInvokerChannel received an user defined event.
This will result in having the ChannelInboundHandler.userEventTriggered(ChannelHandlerContext, Object)
method called of the next ChannelInboundHandler contained in the ChannelPipeline of the
Channel.fireUserEventTriggered in interface ChannelInboundInvokerChannelHandlerContext fireChannelRead(Object msg)
ChannelInboundInvokerChannel received a message.
This will result in having the ChannelInboundHandler.channelRead(ChannelHandlerContext, Object)
method called of the next ChannelInboundHandler contained in the ChannelPipeline of the
Channel.fireChannelRead in interface ChannelInboundInvokerChannelHandlerContext fireChannelReadComplete()
ChannelInboundInvokerChannelInboundHandler.channelReadComplete(ChannelHandlerContext)
event to the next ChannelInboundHandler in the ChannelPipeline.fireChannelReadComplete in interface ChannelInboundInvokerChannelHandlerContext fireChannelWritabilityChanged()
ChannelInboundInvokerChannelInboundHandler.channelWritabilityChanged(ChannelHandlerContext)
event to the next ChannelInboundHandler in the ChannelPipeline.fireChannelWritabilityChanged in interface ChannelInboundInvokerChannelHandlerContext read()
ChannelOutboundInvokerChannel into the first inbound buffer, triggers an
ChannelInboundHandler.channelRead(ChannelHandlerContext, Object) event if data was
read, and triggers a
channelReadComplete event so the
handler can decide to continue reading. If there's a pending read operation already, this method does nothing.
This will result in having the
ChannelOutboundHandler.read(ChannelHandlerContext)
method called of the next ChannelOutboundHandler contained in the ChannelPipeline of the
Channel.
read in interface ChannelOutboundInvokerChannelHandlerContext flush()
ChannelOutboundInvokerflush in interface ChannelOutboundInvokerChannelPipeline pipeline()
ChannelPipelineByteBufAllocator alloc()
ByteBufAllocator which will be used to allocate ByteBufs.@Deprecated <T> Attribute<T> attr(AttributeKey<T> key)
AttributeMap.attr(AttributeKey)AttributeMapAttribute for the given AttributeKey. This method will never return null, but may return
an Attribute which does not have a value set yet.attr in interface AttributeMap@Deprecated <T> boolean hasAttr(AttributeKey<T> key)
AttributeMap.hasAttr(AttributeKey)AttributeMaphasAttr in interface AttributeMapCopyright © 2008–2025 The Netty Project. All rights reserved.