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
ChannelInboundHandlerAdapterwhich allows to explicit only handle a specific type of messages. For example here is an implementation which only handleStringmessages.public class StringHandler extendsBe aware that depending of the constructor parameters it will release all handled messages by passing them toSimpleChannelInboundHandler<String> {@Overrideprotected void channelRead0(ChannelHandlerContextctx,Stringmessage) 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 protectedSimpleChannelInboundHandler()seeSimpleChannelInboundHandler(boolean)withtrueas boolean parameter.protectedSimpleChannelInboundHandler(boolean autoRelease)Create a new instance which will try to detect the types to match out of the type parameter of the class.protectedSimpleChannelInboundHandler(java.lang.Class<? extends I> inboundMessageType)seeSimpleChannelInboundHandler(Class, boolean)withtrueas boolean value.protectedSimpleChannelInboundHandler(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 booleanacceptInboundMessage(java.lang.Object msg)Returnstrueif the given message should be handled.voidchannelRead(ChannelHandlerContext ctx, java.lang.Object msg)CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.protected abstract voidchannelRead0(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)withtrueas 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-trueif handled messages should be released automatically by passing them toReferenceCountUtil.release(Object).
-
SimpleChannelInboundHandler
protected SimpleChannelInboundHandler(java.lang.Class<? extends I> inboundMessageType)
seeSimpleChannelInboundHandler(Class, boolean)withtrueas 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-trueif 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.ExceptionReturnstrueif the given message should be handled. Iffalseit will be passed to the nextChannelInboundHandlerin theChannelPipeline.- Throws:
java.lang.Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelReadin interfaceChannelInboundHandler- Overrides:
channelReadin 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- theChannelHandlerContextwhich thisSimpleChannelInboundHandlerbelongs tomsg- the message to handle- Throws:
java.lang.Exception- is thrown if an error occurred
-
-