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
ChannelInboundHandlerAdapter
which allows to conveniently only handle a specific type of user events. For example, here is an implementation which only handleString
user events.public class StringEventHandler extends
Be 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 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 protected
SimpleUserEventChannelHandler()
seeSimpleUserEventChannelHandler(boolean)
withtrue
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)
seeSimpleUserEventChannelHandler(Class, boolean)
withtrue
as boolean value.protected
SimpleUserEventChannelHandler(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 boolean
acceptEvent(java.lang.Object evt)
Returnstrue
if the given user event should be handled.protected abstract void
eventReceived(ChannelHandlerContext ctx, I evt)
Is called for each user event triggered of typeSimpleUserEventChannelHandler
.void
userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt)
CallsChannelHandlerContext.fireUserEventTriggered(Object)
to forward to the nextChannelInboundHandler
in 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)
withtrue
as 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
-true
if handled events should be released automatically by passing them toReferenceCountUtil.release(Object)
.
-
SimpleUserEventChannelHandler
protected SimpleUserEventChannelHandler(java.lang.Class<? extends I> eventType)
seeSimpleUserEventChannelHandler(Class, boolean)
withtrue
as 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
-true
if 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.Exception
Returnstrue
if the given user event should be handled. Iffalse
it will be passed to the nextChannelInboundHandler
in theChannelPipeline
.- Throws:
java.lang.Exception
-
userEventTriggered
public final void userEventTriggered(ChannelHandlerContext ctx, java.lang.Object evt) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireUserEventTriggered(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
userEventTriggered
in interfaceChannelInboundHandler
- Overrides:
userEventTriggered
in 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
- theChannelHandlerContext
which thisSimpleUserEventChannelHandler
belongs toevt
- the user event to handle- Throws:
java.lang.Exception
- is thrown if an error occurred
-
-