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 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
.-
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
ConstructorsModifierConstructorDescriptionprotected
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
(Class<? extends I> inboundMessageType) seeSimpleChannelInboundHandler(Class, boolean)
withtrue
as boolean value.protected
SimpleChannelInboundHandler
(Class<? extends I> inboundMessageType, boolean autoRelease) Create a new instance -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if the given message should be handled.void
channelRead
(ChannelHandlerContext ctx, 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
-
Field Details
-
matcher
-
autoRelease
private final boolean autoRelease
-
-
Constructor Details
-
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
seeSimpleChannelInboundHandler(Class, boolean)
withtrue
as boolean value. -
SimpleChannelInboundHandler
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 Details
-
acceptInboundMessage
Returnstrue
if the given message should be handled. Iffalse
it will be passed to the nextChannelInboundHandler
in theChannelPipeline
.- Throws:
Exception
-
channelRead
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:
Exception
-
channelRead0
Is called for each message of typeSimpleChannelInboundHandler
.- Parameters:
ctx
- theChannelHandlerContext
which thisSimpleChannelInboundHandler
belongs tomsg
- the message to handle- Throws:
Exception
- is thrown if an error occurred
-