public abstract class SimpleUserEventChannelHandler<I> extends ChannelInboundHandlerAdapter
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.ChannelHandler.Sharable| Modifier | Constructor and Description |
|---|---|
protected |
SimpleUserEventChannelHandler()
see
SimpleUserEventChannelHandler(boolean) with true as boolean parameter. |
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.
|
protected |
SimpleUserEventChannelHandler(Class<? extends I> eventType)
see
SimpleUserEventChannelHandler(Class, boolean) with true as boolean value. |
protected |
SimpleUserEventChannelHandler(Class<? extends I> eventType,
boolean autoRelease)
Create a new instance
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
acceptEvent(Object evt)
Returns
true if the given user event should be handled. |
protected abstract void |
eventReceived(ChannelHandlerContext ctx,
I evt)
Is called for each user event triggered of type
I. |
void |
userEventTriggered(ChannelHandlerContext ctx,
Object evt)
Calls
ChannelHandlerContext.fireUserEventTriggered(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline. |
channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaughtensureNotSharable, handlerAdded, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerAdded, handlerRemovedprotected SimpleUserEventChannelHandler()
SimpleUserEventChannelHandler(boolean) with true as boolean parameter.protected SimpleUserEventChannelHandler(boolean autoRelease)
autoRelease - true if handled events should be released automatically by passing them to
ReferenceCountUtil.release(Object).protected SimpleUserEventChannelHandler(Class<? extends I> eventType)
SimpleUserEventChannelHandler(Class, boolean) with true as boolean value.protected SimpleUserEventChannelHandler(Class<? extends I> eventType, boolean autoRelease)
eventType - The type of events to matchautoRelease - true if handled events should be released automatically by passing them to
ReferenceCountUtil.release(Object).protected boolean acceptEvent(Object evt) throws Exception
true if the given user event should be handled. If false it will be passed to the next
ChannelInboundHandler in the ChannelPipeline.Exceptionpublic final void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireUserEventTriggered(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.userEventTriggered in interface ChannelInboundHandleruserEventTriggered in class ChannelInboundHandlerAdapterExceptionprotected abstract void eventReceived(ChannelHandlerContext ctx, I evt) throws Exception
I.ctx - the ChannelHandlerContext which this SimpleUserEventChannelHandler belongs toevt - the user event to handleException - is thrown if an error occurredCopyright © 2008–2025 The Netty Project. All rights reserved.