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
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
.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsFields inherited from class io.netty.channel.ChannelHandlerAdapter
added
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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
(Class<? extends I> eventType) seeSimpleUserEventChannelHandler(Class, boolean)
withtrue
as boolean value.protected
SimpleUserEventChannelHandler
(Class<? extends I> eventType, boolean autoRelease) Create a new instance -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
acceptEvent
(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
.final void
userEventTriggered
(ChannelHandlerContext ctx, 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
-
Field Details
-
matcher
-
autoRelease
private final boolean autoRelease
-
-
Constructor Details
-
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
seeSimpleUserEventChannelHandler(Class, boolean)
withtrue
as boolean value. -
SimpleUserEventChannelHandler
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 Details
-
acceptEvent
Returnstrue
if the given user event should be handled. Iffalse
it will be passed to the nextChannelInboundHandler
in theChannelPipeline
.- Throws:
Exception
-
userEventTriggered
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:
Exception
-
eventReceived
Is called for each user event triggered of typeSimpleUserEventChannelHandler
.- Parameters:
ctx
- theChannelHandlerContext
which thisSimpleUserEventChannelHandler
belongs toevt
- the user event to handle- Throws:
Exception
- is thrown if an error occurred
-