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 extendsBe aware that depending of the constructor parameters it will release all handled events by passing them toSimpleUserEventChannelHandler
<String
> {@Override
protected void eventReceived(ChannelHandlerContext
ctx,String
evt) throwsException
{ System.out.println(evt); } }
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, exceptionCaught
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded, handlerRemoved
protected 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
.Exception
public final void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireUserEventTriggered(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.userEventTriggered
in interface ChannelInboundHandler
userEventTriggered
in class ChannelInboundHandlerAdapter
Exception
protected 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–2021 The Netty Project. All rights reserved.