- java.lang.Object
-
- io.netty5.channel.SimpleChannelInboundHandler<I>
-
- All Implemented Interfaces:
ChannelHandler
public abstract class SimpleChannelInboundHandler<I> extends Object implements ChannelHandler
ChannelHandlerwhich 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 messageReceived(ChannelHandlerContextctx,Stringmessage) throwsException{ System.out.println(message); } }Resource.dispose(Object).
-
-
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(Class<? extends I> inboundMessageType)seeSimpleChannelInboundHandler(Class, boolean)withtrueas boolean value.protectedSimpleChannelInboundHandler(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(Object msg)Returnstrueif the given message should be handled.voidchannelRead(ChannelHandlerContext ctx, Object msg)Invoked when the currentChannelhas read a message from the peer.protected abstract voidmessageReceived(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)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 toResource.dispose(Object).
-
SimpleChannelInboundHandler
protected SimpleChannelInboundHandler(Class<? extends I> inboundMessageType)
seeSimpleChannelInboundHandler(Class, boolean)withtrueas boolean value.
-
SimpleChannelInboundHandler
protected SimpleChannelInboundHandler(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 toResource.dispose(Object).
-
-
Method Detail
-
acceptInboundMessage
public boolean acceptInboundMessage(Object msg) throws Exception
Returnstrueif the given message should be handled. Iffalseit will be passed to the nextChannelHandlerin theChannelPipeline.- Throws:
Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
Description copied from interface:ChannelHandlerInvoked when the currentChannelhas read a message from the peer.- Specified by:
channelReadin interfaceChannelHandler- Throws:
Exception
-
messageReceived
protected abstract void messageReceived(ChannelHandlerContext ctx, I msg) throws Exception
Is called for each message of typeSimpleChannelInboundHandler.- Parameters:
ctx- theChannelHandlerContextwhich thisSimpleChannelInboundHandlerbelongs tomsg- the message to handle- Throws:
Exception- is thrown if an error occurred
-
-