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
- Direct Known Subclasses:
OcspHttpHandler
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.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable -
Field Summary
FieldsFields inherited from class io.netty.channel.ChannelHandlerAdapter
added -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedseeSimpleChannelInboundHandler(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(Class<? extends I> inboundMessageType) seeSimpleChannelInboundHandler(Class, boolean)withtrueas boolean value.protectedSimpleChannelInboundHandler(Class<? extends I> inboundMessageType, boolean autoRelease) Create a new instance -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrueif the given message should be handled.voidchannelRead(ChannelHandlerContext ctx, 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, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
matcher
-
autoRelease
private final boolean autoRelease
-
-
Constructor Details
-
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
seeSimpleChannelInboundHandler(Class, boolean)withtrueas boolean value. -
SimpleChannelInboundHandler
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 Details
-
acceptInboundMessage
Returnstrueif the given message should be handled. Iffalseit will be passed to the nextChannelInboundHandlerin theChannelPipeline.- Throws:
Exception
-
channelRead
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:
Exception
-
channelRead0
Is called for each message of typeSimpleChannelInboundHandler.- Parameters:
ctx- theChannelHandlerContextwhich thisSimpleChannelInboundHandlerbelongs tomsg- the message to handle- Throws:
Exception- is thrown if an error occurred
-