Package io.netty.channel
Class SimpleChannelInboundHandler<I>
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.SimpleChannelInboundHandler<I>
-
- All Implemented Interfaces:
ChannelHandler
,ChannelInboundHandler
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 handleString
messages.public class StringHandler extends
Be 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 useReferenceCountUtil.retain(Object)
if you pass the object to the next handler in theChannelPipeline
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SimpleChannelInboundHandler()
seeSimpleChannelInboundHandler(boolean)
withtrue
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)
seeSimpleChannelInboundHandler(Class, boolean)
withtrue
as boolean value.protected
SimpleChannelInboundHandler(java.lang.Class<? extends I> inboundMessageType, boolean autoRelease)
Create a new instance
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
acceptInboundMessage(java.lang.Object msg)
Returnstrue
if the given message should be handled.void
channelRead(ChannelHandlerContext ctx, java.lang.Object msg)
CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
.protected abstract void
channelRead0(ChannelHandlerContext ctx, I msg)
Is called for each message of typeSimpleChannelInboundHandler
.-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
-
-
-
Constructor Detail
-
SimpleChannelInboundHandler
protected SimpleChannelInboundHandler()
seeSimpleChannelInboundHandler(boolean)
withtrue
as boolean parameter.
-
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.- Parameters:
autoRelease
-true
if handled messages should be released automatically by passing them toReferenceCountUtil.release(Object)
.
-
SimpleChannelInboundHandler
protected SimpleChannelInboundHandler(java.lang.Class<? extends I> inboundMessageType)
seeSimpleChannelInboundHandler(Class, boolean)
withtrue
as boolean value.
-
SimpleChannelInboundHandler
protected SimpleChannelInboundHandler(java.lang.Class<? extends I> inboundMessageType, boolean autoRelease)
Create a new instance- Parameters:
inboundMessageType
- The type of messages to matchautoRelease
-true
if handled messages should be released automatically by passing them toReferenceCountUtil.release(Object)
.
-
-
Method Detail
-
acceptInboundMessage
public boolean acceptInboundMessage(java.lang.Object msg) throws java.lang.Exception
Returnstrue
if the given message should be handled. Iffalse
it will be passed to the nextChannelInboundHandler
in theChannelPipeline
.- Throws:
java.lang.Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelRead
in interfaceChannelInboundHandler
- Overrides:
channelRead
in classChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
channelRead0
protected abstract void channelRead0(ChannelHandlerContext ctx, I msg) throws java.lang.Exception
Is called for each message of typeSimpleChannelInboundHandler
.- Parameters:
ctx
- theChannelHandlerContext
which thisSimpleChannelInboundHandler
belongs tomsg
- the message to handle- Throws:
java.lang.Exception
- is thrown if an error occurred
-
-