public abstract class SimpleChannelInboundHandler<I> extends ChannelInboundHandlerAdapter
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 extendsBe aware that depending of the constructor parameters it will release all handled messages by passing them toSimpleChannelInboundHandler
<String
> {@Override
protected void channelRead0(ChannelHandlerContext
ctx,String
message) throwsException
{ System.out.println(message); } }
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
.
Please keep in mind that #channelRead0(ChannelHandlerContext, I)
will be renamed to
messageReceived(ChannelHandlerContext, I)
in 5.0.
ChannelHandler.Sharable
Modifier | Constructor and Description |
---|---|
protected |
SimpleChannelInboundHandler()
see
SimpleChannelInboundHandler(boolean) with true as boolean parameter. |
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(java.lang.Class<? extends I> inboundMessageType)
see
SimpleChannelInboundHandler(Class, boolean) with true as boolean value. |
protected |
SimpleChannelInboundHandler(java.lang.Class<? extends I> inboundMessageType,
boolean autoRelease)
Create a new instance
|
Modifier and Type | Method and Description |
---|---|
boolean |
acceptInboundMessage(java.lang.Object msg)
Returns
true if the given message should be handled. |
void |
channelRead(ChannelHandlerContext ctx,
java.lang.Object msg)
Calls
ChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
protected abstract void |
channelRead0(ChannelHandlerContext ctx,
I msg)
Please keep in mind that this method will be renamed to
messageReceived(ChannelHandlerContext, I) in 5.0. |
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded, handlerRemoved
protected SimpleChannelInboundHandler()
SimpleChannelInboundHandler(boolean)
with true
as boolean parameter.protected SimpleChannelInboundHandler(boolean autoRelease)
autoRelease
- true
if handled messages should be released automatically by passing them to
ReferenceCountUtil.release(Object)
.protected SimpleChannelInboundHandler(java.lang.Class<? extends I> inboundMessageType)
SimpleChannelInboundHandler(Class, boolean)
with true
as boolean value.protected SimpleChannelInboundHandler(java.lang.Class<? extends I> inboundMessageType, boolean autoRelease)
inboundMessageType
- The type of messages to matchautoRelease
- true
if handled messages should be released automatically by passing them to
ReferenceCountUtil.release(Object)
.public boolean acceptInboundMessage(java.lang.Object msg) throws java.lang.Exception
true
if the given message should be handled. If false
it will be passed to the next
ChannelInboundHandler
in the ChannelPipeline
.java.lang.Exception
public void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
in interface ChannelInboundHandler
channelRead
in class ChannelInboundHandlerAdapter
java.lang.Exception
protected abstract void channelRead0(ChannelHandlerContext ctx, I msg) throws java.lang.Exception
messageReceived(ChannelHandlerContext, I)
in 5.0.
Is called for each message of type I
.ctx
- the ChannelHandlerContext
which this SimpleChannelInboundHandler
belongs tomsg
- the message to handlejava.lang.Exception
- is thrown if an error occurredCopyright © 2008–2018 The Netty Project. All rights reserved.