Package io.netty.channel
Class SimpleUserEventChannelHandler<I>
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.SimpleUserEventChannelHandler<I>
-
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler
public abstract class SimpleUserEventChannelHandler<I> extends ChannelInboundHandlerAdapter
ChannelInboundHandlerAdapterwhich allows to conveniently only handle a specific type of user events. For example, here is an implementation which only handleStringuser events.public class StringEventHandler extendsBe aware that depending of the constructor parameters it will release all handled events by passing them toSimpleUserEventChannelHandler<String> {@Overrideprotected void eventReceived(ChannelHandlerContextctx,Stringevt) throwsException{ System.out.println(evt); } }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 protectedSimpleUserEventChannelHandler()seeSimpleUserEventChannelHandler(boolean)withtrueas boolean parameter.protectedSimpleUserEventChannelHandler(boolean autoRelease)Create a new instance which will try to detect the types to match out of the type parameter of the class.protectedSimpleUserEventChannelHandler(java.lang.Class<? extends I> eventType)seeSimpleUserEventChannelHandler(Class, boolean)withtrueas boolean value.protectedSimpleUserEventChannelHandler(java.lang.Class<? extends I> eventType, boolean autoRelease)Create a new instance
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleanacceptEvent(java.lang.Object evt)Returnstrueif the given user event should be handled.protected abstract voideventReceived(ChannelHandlerContext ctx, I evt)Is called for each user event triggered of typeSimpleUserEventChannelHandler.voiduserEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt)CallsChannelHandlerContext.fireUserEventTriggered(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught
-
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
-
SimpleUserEventChannelHandler
protected SimpleUserEventChannelHandler()
seeSimpleUserEventChannelHandler(boolean)withtrueas boolean parameter.
-
SimpleUserEventChannelHandler
protected SimpleUserEventChannelHandler(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 events should be released automatically by passing them toReferenceCountUtil.release(Object).
-
SimpleUserEventChannelHandler
protected SimpleUserEventChannelHandler(java.lang.Class<? extends I> eventType)
seeSimpleUserEventChannelHandler(Class, boolean)withtrueas boolean value.
-
SimpleUserEventChannelHandler
protected SimpleUserEventChannelHandler(java.lang.Class<? extends I> eventType, boolean autoRelease)
Create a new instance- Parameters:
eventType- The type of events to matchautoRelease-trueif handled events should be released automatically by passing them toReferenceCountUtil.release(Object).
-
-
Method Detail
-
acceptEvent
protected boolean acceptEvent(java.lang.Object evt) throws java.lang.ExceptionReturnstrueif the given user event should be handled. Iffalseit will be passed to the nextChannelInboundHandlerin theChannelPipeline.- Throws:
java.lang.Exception
-
userEventTriggered
public final void userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireUserEventTriggered(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
userEventTriggeredin interfaceChannelInboundHandler- Overrides:
userEventTriggeredin classChannelInboundHandlerAdapter- Throws:
java.lang.Exception
-
eventReceived
protected abstract void eventReceived(ChannelHandlerContext ctx, I evt) throws java.lang.Exception
Is called for each user event triggered of typeSimpleUserEventChannelHandler.- Parameters:
ctx- theChannelHandlerContextwhich thisSimpleUserEventChannelHandlerbelongs toevt- the user event to handle- Throws:
java.lang.Exception- is thrown if an error occurred
-
-