Class SimpleUserEventChannelHandler<I>
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleUserEventChannelHandler<I>
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler
ChannelInboundHandlerAdapter which allows to conveniently only handle a specific type of user events.
For example, here is an implementation which only handle String user events.
public class StringEventHandler extends
SimpleUserEventChannelHandler<String> {
@Override
protected void eventReceived(ChannelHandlerContext ctx, String evt)
throws Exception {
System.out.println(evt);
}
}
Be aware that depending of the constructor parameters it will release all handled events 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 ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedseeSimpleUserEventChannelHandler(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(Class<? extends I> eventType) seeSimpleUserEventChannelHandler(Class, boolean)withtrueas boolean value.protectedSimpleUserEventChannelHandler(Class<? extends I> eventType, boolean autoRelease) Create a new instance -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanacceptEvent(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 typeI.final voiduserEventTriggered(ChannelHandlerContext ctx, Object evt) CallsChannelHandlerContext.fireUserEventTriggered(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.Methods inherited from class ChannelInboundHandlerAdapter
channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaughtMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChannelHandler
handlerAdded, handlerRemoved
-
Constructor Details
-
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
seeSimpleUserEventChannelHandler(Class, boolean)withtrueas boolean value. -
SimpleUserEventChannelHandler
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 Details
-
acceptEvent
Returnstrueif the given user event should be handled. Iffalseit will be passed to the nextChannelInboundHandlerin theChannelPipeline.- Throws:
Exception
-
userEventTriggered
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:
Exception
-
eventReceived
Is called for each user event triggered of typeI.- Parameters:
ctx- theChannelHandlerContextwhich thisSimpleUserEventChannelHandlerbelongs toevt- the user event to handle- Throws:
Exception- is thrown if an error occurred
-