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
{ privateChannelHandlerContext
ctx; public void beforeAdd(ChannelHandlerContext
ctx) { 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.
ChannelHandlerContext
ChannelHandler
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
ChannelHandlerContext
s if it is added to one or more ChannelPipeline
s more than once.
Also note that a ChannelHandler
that is supposed to be added to multiple ChannelPipeline
s 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, writeAndFlush
Channel channel()
Channel
which is bound to the ChannelHandlerContext
.EventExecutor executor()
EventExecutor
which is used to execute an arbitrary task.java.lang.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()
ChannelInboundInvoker
Channel
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
在接口中 ChannelInboundInvoker
ChannelHandlerContext fireChannelUnregistered()
ChannelInboundInvoker
Channel
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
在接口中 ChannelInboundInvoker
ChannelHandlerContext fireChannelActive()
ChannelInboundInvoker
Channel
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
在接口中 ChannelInboundInvoker
ChannelHandlerContext fireChannelInactive()
ChannelInboundInvoker
Channel
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
在接口中 ChannelInboundInvoker
ChannelHandlerContext fireExceptionCaught(java.lang.Throwable cause)
ChannelInboundInvoker
Channel
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
在接口中 ChannelInboundInvoker
ChannelHandlerContext fireUserEventTriggered(java.lang.Object evt)
ChannelInboundInvoker
Channel
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
在接口中 ChannelInboundInvoker
ChannelHandlerContext fireChannelRead(java.lang.Object msg)
ChannelInboundInvoker
Channel
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
在接口中 ChannelInboundInvoker
ChannelHandlerContext fireChannelReadComplete()
ChannelInboundInvoker
ChannelInboundHandler.channelReadComplete(ChannelHandlerContext)
event to the next ChannelInboundHandler
in the ChannelPipeline
.fireChannelReadComplete
在接口中 ChannelInboundInvoker
ChannelHandlerContext fireChannelWritabilityChanged()
ChannelInboundInvoker
ChannelInboundHandler.channelWritabilityChanged(ChannelHandlerContext)
event to the next ChannelInboundHandler
in the ChannelPipeline
.ChannelHandlerContext read()
ChannelOutboundInvoker
Channel
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
在接口中 ChannelOutboundInvoker
ChannelHandlerContext flush()
ChannelOutboundInvoker
flush
在接口中 ChannelOutboundInvoker
ChannelPipeline pipeline()
ChannelPipeline
ByteBufAllocator alloc()
ByteBufAllocator
which will be used to allocate ByteBuf
s.@Deprecated <T> Attribute<T> attr(AttributeKey<T> key)
AttributeMap.attr(AttributeKey)
AttributeMap
Attribute
for the given AttributeKey
. This method will never return null, but may return
an Attribute
which does not have a value set yet.attr
在接口中 AttributeMap
@Deprecated <T> boolean hasAttr(AttributeKey<T> key)
AttributeMap.hasAttr(AttributeKey)
AttributeMap
hasAttr
在接口中 AttributeMap