Top Description Fields Constructors Methods
io.netty.channel

public abstract Class SimpleChannelInboundHandler<I>

extends ChannelInboundHandlerAdapter
Class Inheritance
Imports
io.netty.util.ReferenceCountUtil, io.netty.util.internal.TypeParameterMatcher

ChannelInboundHandlerAdapter which allows to explicit only handle a specific type of messages. For example here is an implementation which only handle String messages.
    public class StringHandler extends
            SimpleChannelInboundHandler<String> {

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, String message)
                throws Exception {
            System.out.println(message);
        }
    }
Be aware that depending of the constructor parameters it will release all handled messages by passing them to ReferenceCountUtil#release(Object). In this case you may need to use ReferenceCountUtil#retain(Object) if you pass the object to the next handler in the ChannelPipeline.

Field Summary

Modifier and TypeField and Description
private final boolean
private final TypeParameterMatcher

Constructor Summary

AccessConstructor and Description
protected
protected
SimpleChannelInboundHandler(boolean
true if handled messages should be released automatically by passing them to ReferenceCountUtil#release(Object).
autoRelease
)

Create a new instance which will try to detect the types to match out of the type parameter of the class.

protected
SimpleChannelInboundHandler(Class<? extends I> inboundMessageType)

see SimpleChannelInboundHandler(Class, boolean) with true as boolean value.

protected
SimpleChannelInboundHandler(Class<? extends I>
The type of messages to match
inboundMessageType
,
boolean
true if handled messages should be released automatically by passing them to ReferenceCountUtil#release(Object).
autoRelease
)

Create a new instance

Method Summary

Modifier and TypeMethod and Description
public boolean
acceptInboundMessage(Object msg)

Returns true if the given message should be handled.

public void
protected abstract void
channelRead0(ChannelHandlerContext ctx, I
the message to handle
msg
)

Is called for each message of type I.

Inherited from io.netty.channel.ChannelInboundHandlerAdapter:
channelActivechannelInactivechannelReadCompletechannelRegisteredchannelUnregisteredchannelWritabilityChangedexceptionCaughtuserEventTriggered

Field Detail

autoReleaseback to summary
private final boolean autoRelease
matcherback to summary
private final TypeParameterMatcher matcher

Constructor Detail

SimpleChannelInboundHandlerback to summary
protected SimpleChannelInboundHandler()

see SimpleChannelInboundHandler(boolean) with true as boolean parameter.

SimpleChannelInboundHandlerback to summary
protected SimpleChannelInboundHandler(boolean autoRelease)

Create a new instance which will try to detect the types to match out of the type parameter of the class.

Parameters
autoRelease:boolean

true if handled messages should be released automatically by passing them to ReferenceCountUtil#release(Object).

SimpleChannelInboundHandlerback to summary
protected SimpleChannelInboundHandler(Class<? extends I> inboundMessageType)

see SimpleChannelInboundHandler(Class, boolean) with true as boolean value.

SimpleChannelInboundHandlerback to summary
protected SimpleChannelInboundHandler(Class<? extends I> inboundMessageType, boolean autoRelease)

Create a new instance

Parameters
inboundMessageType:Class<? extends I>

The type of messages to match

autoRelease:boolean

true if handled messages should be released automatically by passing them to ReferenceCountUtil#release(Object).

Method Detail

acceptInboundMessageback to summary
public boolean acceptInboundMessage(Object msg) throws Exception

Returns true if the given message should be handled. If false it will be passed to the next ChannelInboundHandler in the ChannelPipeline.

channelReadback to summary
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Implements io.netty.channel.ChannelInboundHandler.channelRead.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Calls ChannelHandlerContext#fireChannelRead(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
channelRead0back to summary
protected abstract void channelRead0(ChannelHandlerContext ctx, I msg) throws Exception

Is called for each message of type I.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this SimpleChannelInboundHandler belongs to

msg:I

the message to handle

Exceptions
Exception:
is thrown if an error occurred