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| 限定符 | 构造器和说明 |
|---|---|
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(java.lang.Class<? extends I> eventType)
see
SimpleUserEventChannelHandler(Class, boolean) with true as boolean value. |
protected |
SimpleUserEventChannelHandler(java.lang.Class<? extends I> eventType,
boolean autoRelease)
Create a new instance
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected boolean |
acceptEvent(java.lang.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,
java.lang.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(java.lang.Class<? extends I> eventType)
SimpleUserEventChannelHandler(Class, boolean) with true as boolean value.protected SimpleUserEventChannelHandler(java.lang.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(java.lang.Object evt)
throws java.lang.Exception
true if the given user event should be handled. If false it will be passed to the next
ChannelInboundHandler in the ChannelPipeline.java.lang.Exceptionpublic final void userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt) throws java.lang.Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireUserEventTriggered(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.userEventTriggered 在接口中 ChannelInboundHandleruserEventTriggered 在类中 ChannelInboundHandlerAdapterjava.lang.Exceptionprotected abstract void eventReceived(ChannelHandlerContext ctx, I evt) throws java.lang.Exception
I.ctx - the ChannelHandlerContext which this SimpleUserEventChannelHandler belongs toevt - the user event to handlejava.lang.Exception - is thrown if an error occurred