- java.lang.Object
-
- io.netty5.channel.SimpleChannelInboundHandler<I>
-
- All Implemented Interfaces:
ChannelHandler
public abstract class SimpleChannelInboundHandler<I> extends Object implements ChannelHandler
ChannelHandler
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 messageReceived(ChannelHandlerContext
ctx,String
message) throwsException
{ System.out.println(message); } }Resource.dispose(Object)
.
-
-
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(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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
acceptInboundMessage(Object msg)
Returnstrue
if the given message should be handled.void
channelRead(ChannelHandlerContext ctx, Object msg)
Invoked when the currentChannel
has read a message from the peer.protected abstract void
messageReceived(ChannelHandlerContext ctx, I msg)
Is called for each message of typeSimpleChannelInboundHandler
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelExceptionCaught, channelInactive, channelInboundEvent, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
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 toResource.dispose(Object)
.
-
SimpleChannelInboundHandler
protected SimpleChannelInboundHandler(Class<? extends I> inboundMessageType)
seeSimpleChannelInboundHandler(Class, boolean)
withtrue
as boolean value.
-
SimpleChannelInboundHandler
protected SimpleChannelInboundHandler(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 toResource.dispose(Object)
.
-
-
Method Detail
-
acceptInboundMessage
public boolean acceptInboundMessage(Object msg) throws Exception
Returnstrue
if the given message should be handled. Iffalse
it will be passed to the nextChannelHandler
in theChannelPipeline
.- Throws:
Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
Description copied from interface:ChannelHandler
Invoked when the currentChannel
has read a message from the peer.- Specified by:
channelRead
in interfaceChannelHandler
- Throws:
Exception
-
messageReceived
protected abstract void messageReceived(ChannelHandlerContext ctx, I msg) throws Exception
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
-
-