public abstract class SimpleChannelInboundHandler<I> extends ChannelHandlerAdapter
ChannelHandler 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 messageReceived(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 pass 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.
Since 5.0, channelRead0(ChannelHandlerContext, I) has been renamed to
#messageReceived(ChannelHandlerContext, I).
ChannelHandler.Sharable, ChannelHandler.Skip| Modifier | Constructor and Description |
|---|---|
protected |
SimpleChannelInboundHandler() |
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.
|
protected |
SimpleChannelInboundHandler(Class<? extends I> inboundMessageType) |
protected |
SimpleChannelInboundHandler(Class<? extends I> inboundMessageType,
boolean autoRelease)
Create a new instance
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptInboundMessage(Object msg)
Returns
true if the given message should be handled. |
void |
channelRead(ChannelHandlerContext ctx,
Object msg)
Calls
ChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelHandler in the ChannelPipeline. |
protected abstract void |
messageReceived(ChannelHandlerContext ctx,
I msg)
Is called for each message of type
I. |
bind, channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, handlerAdded, handlerRemoved, isSharable, read, userEventTriggered, writeprotected SimpleChannelInboundHandler()
#SimpleChannelInboundHandler(boolean)} with {@code true} as boolean parameter.protected SimpleChannelInboundHandler(boolean autoRelease)
autoRelease - true if handled messages should be released automatically by pass them to
ReferenceCountUtil.release(Object).protected SimpleChannelInboundHandler(Class<? extends I> inboundMessageType)
#SimpleChannelInboundHandler(Class, boolean)} with {@code true} as boolean value.protected SimpleChannelInboundHandler(Class<? extends I> inboundMessageType, boolean autoRelease)
inboundMessageType - The type of messages to matchautoRelease - true if handled messages should be released automatically by pass them to
ReferenceCountUtil.release(Object).public boolean acceptInboundMessage(Object msg) throws Exception
true if the given message should be handled. If false it will be passed to the next
ChannelHandler in the ChannelPipeline.Exceptionpublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
ChannelHandlerAdapterChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelRead in interface ChannelHandlerchannelRead in class ChannelHandlerAdapterExceptionprotected abstract void messageReceived(ChannelHandlerContext ctx, I msg) throws Exception
I.ctx - the ChannelHandlerContext which this SimpleChannelInboundHandler
belongs tomsg - the message to handleException - is thrown if an error occurredCopyright © 2008–2015 The Netty Project. All rights reserved.