-
- All Superinterfaces:
ChannelInboundInvoker
,ChannelOutboundInvoker
,FuturePromiseFactory
- All Known Implementing Classes:
DelegatingChannelHandlerContext
public interface ChannelHandlerContext extends ChannelInboundInvoker, ChannelOutboundInvoker
Enables aChannelHandler
to interact with itsChannelPipeline
and other handlers. Among other things a handler can notify the nextChannelHandler
in theChannelPipeline
as well as modify theChannelPipeline
it belongs to dynamically.Notify
You can notify the closest handler in the sameChannelPipeline
by calling one of the various methods provided here. Please refer toChannelPipeline
to understand how an event flows.Modifying a pipeline
You can get theChannelPipeline
your handler belongs to by callingpipeline()
. A non-trivial application could insert, remove, or replace handlers in the pipeline dynamically at runtime.Retrieving for later use
You can keep theChannelHandlerContext
for later use, such as triggering an event outside the handler methods, even from a different thread.public class MyHandler extends
ChannelHandler
{ privateChannelHandlerContext
ctx; public void handlerAdded(ChannelHandlerContext
ctx) { this.ctx = ctx; } public void login(String username, password) { ctx.write(new LoginMessage(username, password)); } ... }A handler can have more than one context
Please note that aChannelHandler
instance can be added to more than oneChannelPipeline
. It means a singleChannelHandler
instance can have more than oneChannelHandlerContext
and therefore the single instance can be invoked with differentChannelHandlerContext
s if it is added to one or moreChannelPipeline
s more than once.Additional resources worth reading
Please refer to the
ChannelHandler
, andChannelPipeline
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.
-
-
Method Summary
-
Methods inherited from interface io.netty5.channel.ChannelOutboundInvoker
bind, close, connect, connect, deregister, disconnect, executor, newFailedFuture, newPromise, newSucceededFuture, newSucceededFuture, register, sendOutboundEvent, shutdown, write, writeAndFlush
-
-
-
-
Method Detail
-
channel
default Channel channel()
Return theChannel
which is bound to theChannelHandlerContext
.
-
name
String name()
The unique name of theChannelHandlerContext
.The name was used when thenChannelHandler
was added to theChannelPipeline
. This name can also be used to access the registeredChannelHandler
from theChannelPipeline
.
-
handler
ChannelHandler handler()
TheChannelHandler
that is bound thisChannelHandlerContext
.
-
isRemoved
boolean isRemoved()
Returntrue
if theChannelHandler
which belongs to this context was removed from theChannelPipeline
.
-
fireChannelRegistered
ChannelHandlerContext fireChannelRegistered()
Description copied from interface:ChannelInboundInvoker
AChannel
was registered to itsEventLoop
. This will result in having theChannelHandler.channelRegistered(ChannelHandlerContext)
method called of the nextChannelHandler
contained in theChannelPipeline
of theChannel
.- Specified by:
fireChannelRegistered
in interfaceChannelInboundInvoker
-
fireChannelUnregistered
ChannelHandlerContext fireChannelUnregistered()
Description copied from interface:ChannelInboundInvoker
AChannel
was unregistered from itsEventLoop
. This will result in having theChannelHandler.channelUnregistered(ChannelHandlerContext)
method called of the nextChannelHandler
contained in theChannelPipeline
of theChannel
.- Specified by:
fireChannelUnregistered
in interfaceChannelInboundInvoker
-
fireChannelActive
ChannelHandlerContext fireChannelActive()
Description copied from interface:ChannelInboundInvoker
AChannel
is active now, which means it is connected. This will result in having theChannelHandler.channelActive(ChannelHandlerContext)
method called of the nextChannelHandler
contained in theChannelPipeline
of theChannel
.- Specified by:
fireChannelActive
in interfaceChannelInboundInvoker
-
fireChannelInactive
ChannelHandlerContext fireChannelInactive()
Description copied from interface:ChannelInboundInvoker
AChannel
is inactive now, which means it is closed. This will result in having theChannelHandler.channelInactive(ChannelHandlerContext)
method called of the nextChannelHandler
contained in theChannelPipeline
of theChannel
.- Specified by:
fireChannelInactive
in interfaceChannelInboundInvoker
-
fireChannelShutdown
ChannelHandlerContext fireChannelShutdown(ChannelShutdownDirection direction)
Description copied from interface:ChannelInboundInvoker
AChannel
was shutdown in a specific direction. This will result in having theChannelHandler.channelShutdown(ChannelHandlerContext, ChannelShutdownDirection)
method called of the nextChannelHandler
contained in theChannelPipeline
of theChannel
.- Specified by:
fireChannelShutdown
in interfaceChannelInboundInvoker
-
fireChannelExceptionCaught
ChannelHandlerContext fireChannelExceptionCaught(Throwable cause)
Description copied from interface:ChannelInboundInvoker
AChannel
received anThrowable
in one of its inbound operations. This will result in having theChannelHandler.channelExceptionCaught(ChannelHandlerContext, Throwable)
method called of the nextChannelHandler
contained in theChannelPipeline
of theChannel
.- Specified by:
fireChannelExceptionCaught
in interfaceChannelInboundInvoker
-
fireChannelInboundEvent
ChannelHandlerContext fireChannelInboundEvent(Object evt)
Description copied from interface:ChannelInboundInvoker
AChannel
received a custom defined inbound event. This will result in having theChannelHandler.channelInboundEvent(ChannelHandlerContext, Object)
method called of the nextChannelHandler
contained in theChannelPipeline
of theChannel
.- Specified by:
fireChannelInboundEvent
in interfaceChannelInboundInvoker
-
fireChannelRead
ChannelHandlerContext fireChannelRead(Object msg)
Description copied from interface:ChannelInboundInvoker
AChannel
received a message. This will result in having theChannelHandler.channelRead(ChannelHandlerContext, Object)
method called of the nextChannelHandler
contained in theChannelPipeline
of theChannel
.- Specified by:
fireChannelRead
in interfaceChannelInboundInvoker
-
fireChannelReadComplete
ChannelHandlerContext fireChannelReadComplete()
Description copied from interface:ChannelInboundInvoker
Triggers anChannelHandler.channelReadComplete(ChannelHandlerContext)
event to the nextChannelHandler
in theChannelPipeline
.- Specified by:
fireChannelReadComplete
in interfaceChannelInboundInvoker
-
fireChannelWritabilityChanged
ChannelHandlerContext fireChannelWritabilityChanged()
Description copied from interface:ChannelInboundInvoker
Triggers anChannelHandler.channelWritabilityChanged(ChannelHandlerContext)
event to the nextChannelHandler
in theChannelPipeline
.- Specified by:
fireChannelWritabilityChanged
in interfaceChannelInboundInvoker
-
read
ChannelHandlerContext read()
Description copied from interface:ChannelOutboundInvoker
Request to Read data from theChannel
into the first inbound buffer, triggers anChannelHandler.channelRead(ChannelHandlerContext, Object)
event if data was read, and triggers achannelReadComplete
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
ChannelHandler.read(ChannelHandlerContext)
method called of the nextChannelHandler
contained in theChannelPipeline
of theChannel
.- Specified by:
read
in interfaceChannelOutboundInvoker
-
flush
ChannelHandlerContext flush()
Description copied from interface:ChannelOutboundInvoker
Request to flush all pending messages via this ChannelOutboundInvoker.- Specified by:
flush
in interfaceChannelOutboundInvoker
-
pipeline
ChannelPipeline pipeline()
Return the assignedChannelPipeline
-
bufferAllocator
default BufferAllocator bufferAllocator()
Return the assignedBufferAllocator
which will be used to allocateBuffer
s.
-
-