Top Description Methods
io.netty5.channel

public Interface ChannelHandlerContext

extends ChannelInboundInvoker, ChannelOutboundInvoker
Known Direct Implementers
io.netty5.channel.DefaultChannelHandlerContext, io.netty5.channel.internal.DelegatingChannelHandlerContext
Imports
io.netty5.buffer.Buffer, .BufferAllocator

Enables a 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.

Notify

You can notify the closest handler in the same ChannelPipeline by calling one of the various methods provided here. Please refer to ChannelPipeline to understand how an event flows.

Modifying a pipeline

You can get the ChannelPipeline your handler belongs to by calling pipeline(). A non-trivial application could insert, remove, or replace handlers in the pipeline dynamically at runtime.

Retrieving for later use

You can keep the ChannelHandlerContext for later use, such as triggering an event outside the handler methods, even from a different thread.
public class MyHandler extends ChannelHandler {

    private ChannelHandlerContext 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 a 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 ChannelHandlerContexts if it is added to one or more ChannelPipelines more than once.

Additional resources worth reading

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.

Method Summary

Modifier and TypeMethod and Description
public default BufferAllocator
bufferAllocator()

Return the assigned BufferAllocator which will be used to allocate Buffers.

public default Channel
channel()

Return the Channel which is bound to the ChannelHandlerContext.

public ChannelHandlerContext
fireChannelActive()

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelActive.

A Channel is active now, which means it is connected.
public ChannelHandlerContext
public ChannelHandlerContext
fireChannelInactive()

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelInactive.

A Channel is inactive now, which means it is closed.
public ChannelHandlerContext
public ChannelHandlerContext
public ChannelHandlerContext
public ChannelHandlerContext
public ChannelHandlerContext
public ChannelHandlerContext
public ChannelHandlerContext
public ChannelHandlerContext
flush()

Redeclares io.netty5.channel.ChannelOutboundInvoker.flush.

Request to flush all pending messages via this ChannelOutboundInvoker.
public ChannelHandler
handler()

The ChannelHandler that is bound this ChannelHandlerContext.

public boolean
isRemoved()

Return true if the ChannelHandler which belongs to this context was removed from the ChannelPipeline.

public String
name()

The unique name of the ChannelHandlerContext.The name was used when then ChannelHandler was added to the ChannelPipeline.

public ChannelPipeline
pipeline()

Return the assigned ChannelPipeline

public ChannelHandlerContext
read(ReadBufferAllocator
The ReadBufferAllocator that should be used to allocate a Buffer if needed (for reading the data).
readBufferAllocator
)

Redeclares io.netty5.channel.ChannelOutboundInvoker.read.

Request to read data from the Channel, triggers an ChannelHandler#channelRead(ChannelHandlerContext, Object) event if data was read, and triggers a channelReadComplete event so the handler can decide to continue reading.
public ChannelHandlerContext
Inherited from io.netty5.channel.ChannelOutboundInvoker:
bindcloseconnectconnectderegisterdisconnectexecutornewFailedFuturenewPromisenewSucceededFuturenewSucceededFutureregistersendOutboundEventshutdownwritewriteAndFlush

Method Detail

bufferAllocatorback to summary
public default BufferAllocator bufferAllocator()

Return the assigned BufferAllocator which will be used to allocate Buffers.

channelback to summary
public default Channel channel()

Return the Channel which is bound to the ChannelHandlerContext.

fireChannelActiveback to summary
public ChannelHandlerContext fireChannelActive()

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelActive.

Doc from io.netty5.channel.ChannelInboundInvoker.fireChannelActive.

A Channel is active now, which means it is connected. This will result in having the ChannelHandler#channelActive(ChannelHandlerContext) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelExceptionCaughtback to summary
public ChannelHandlerContext fireChannelExceptionCaught(Throwable cause)

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelExceptionCaught.

Doc from io.netty5.channel.ChannelInboundInvoker.fireChannelExceptionCaught.

A Channel received an Throwable in one of its inbound operations. This will result in having the ChannelHandler#channelExceptionCaught(ChannelHandlerContext, Throwable) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelInactiveback to summary
public ChannelHandlerContext fireChannelInactive()

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelInactive.

Doc from io.netty5.channel.ChannelInboundInvoker.fireChannelInactive.

A Channel is inactive now, which means it is closed. This will result in having the ChannelHandler#channelInactive(ChannelHandlerContext) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelInboundEventback to summary
public ChannelHandlerContext fireChannelInboundEvent(Object evt)

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelInboundEvent.

Doc from io.netty5.channel.ChannelInboundInvoker.fireChannelInboundEvent.

A Channel received a custom defined inbound event. This will result in having the ChannelHandler#channelInboundEvent(ChannelHandlerContext, Object) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelReadback to summary
public ChannelHandlerContext fireChannelRead(Object msg)

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelRead.

Doc from io.netty5.channel.ChannelInboundInvoker.fireChannelRead.

A Channel received a message. This will result in having the ChannelHandler#channelRead(ChannelHandlerContext, Object) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelReadCompleteback to summary
public ChannelHandlerContext fireChannelReadComplete()

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelReadComplete.

Doc from io.netty5.channel.ChannelInboundInvoker.fireChannelReadComplete.

Triggers an ChannelHandler#channelReadComplete(ChannelHandlerContext) event to the next ChannelHandler in the ChannelPipeline.

Annotations
@Override
fireChannelRegisteredback to summary
public ChannelHandlerContext fireChannelRegistered()

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelRegistered.

Doc from io.netty5.channel.ChannelInboundInvoker.fireChannelRegistered.

A Channel was registered to its EventLoop. This will result in having the ChannelHandler#channelRegistered(ChannelHandlerContext) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelShutdownback to summary
public ChannelHandlerContext fireChannelShutdown(ChannelShutdownDirection direction)

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelShutdown.

Doc from io.netty5.channel.ChannelInboundInvoker.fireChannelShutdown.

A Channel was shutdown in a specific direction. This will result in having the ChannelHandler#channelShutdown(ChannelHandlerContext, ChannelShutdownDirection) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelUnregisteredback to summary
public ChannelHandlerContext fireChannelUnregistered()

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelUnregistered.

Doc from io.netty5.channel.ChannelInboundInvoker.fireChannelUnregistered.

A Channel was unregistered from its EventLoop. This will result in having the ChannelHandler#channelUnregistered(ChannelHandlerContext) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Annotations
@Override
fireChannelWritabilityChangedback to summary
public ChannelHandlerContext fireChannelWritabilityChanged()

Redeclares io.netty5.channel.ChannelInboundInvoker.fireChannelWritabilityChanged.

Doc from io.netty5.channel.ChannelInboundInvoker.fireChannelWritabilityChanged.

Triggers an ChannelHandler#channelWritabilityChanged(ChannelHandlerContext) event to the next ChannelHandler in the ChannelPipeline.

Annotations
@Override
flushback to summary
public ChannelHandlerContext flush()

Redeclares io.netty5.channel.ChannelOutboundInvoker.flush.

Doc from io.netty5.channel.ChannelOutboundInvoker.flush.

Request to flush all pending messages via this ChannelOutboundInvoker.

Annotations
@Override
handlerback to summary
public ChannelHandler handler()

The ChannelHandler that is bound this ChannelHandlerContext.

isRemovedback to summary
public boolean isRemoved()

Return true if the ChannelHandler which belongs to this context was removed from the ChannelPipeline.

nameback to summary
public String name()

The unique name of the 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.

pipelineback to summary
public ChannelPipeline pipeline()

Return the assigned ChannelPipeline

readback to summary
public ChannelHandlerContext read(ReadBufferAllocator readBufferAllocator)

Redeclares io.netty5.channel.ChannelOutboundInvoker.read.

Doc from io.netty5.channel.ChannelOutboundInvoker.read.

Request to read data from the Channel, triggers an ChannelHandler#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 ChannelHandler#read(ChannelHandlerContext, ReadBufferAllocator) method called of the next ChannelHandler contained in the ChannelPipeline of the Channel.

Parameters
readBufferAllocator:ReadBufferAllocator

The ReadBufferAllocator that should be used to allocate a Buffer if needed (for reading the data).

Annotations
@Override
readback to summary
public ChannelHandlerContext read()

Redeclares io.netty5.channel.ChannelOutboundInvoker.read.

Annotations
@Override