- java.lang.Object
-
- io.netty5.channel.SimpleUserEventChannelHandler<I>
-
- All Implemented Interfaces:
ChannelHandler
public abstract class SimpleUserEventChannelHandler<I> extends Object implements ChannelHandler
ChannelHandlerwhich allows to conveniently only handle a specific type of user events. For example, here is an implementation which only handleStringuser events.public class StringEventHandler extendsBe aware that depending of the constructor parameters it will release all handled events by passing them toSimpleUserEventChannelHandler<String> {@Overrideprotected void eventReceived(ChannelHandlerContextctx,Stringevt) throwsException{ System.out.println(evt); } }Resource.dispose(Object).
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSimpleUserEventChannelHandler()seeSimpleUserEventChannelHandler(boolean)withtrueas boolean parameter.protectedSimpleUserEventChannelHandler(boolean autoRelease)Create a new instance which will try to detect the types to match out of the type parameter of the class.protectedSimpleUserEventChannelHandler(Class<? extends I> eventType)seeSimpleUserEventChannelHandler(Class, boolean)withtrueas boolean value.protectedSimpleUserEventChannelHandler(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 booleanacceptEvent(Object evt)Returnstrueif the given user event should be handled.voidchannelInboundEvent(ChannelHandlerContext ctx, Object evt)Gets called if a custom inbound event happened.protected abstract voideventReceived(ChannelHandlerContext ctx, I evt)Is called for each user event triggered of typeSimpleUserEventChannelHandler.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelExceptionCaught, channelInactive, channelRead, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Constructor Detail
-
SimpleUserEventChannelHandler
protected SimpleUserEventChannelHandler()
seeSimpleUserEventChannelHandler(boolean)withtrueas 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-trueif handled events should be released automatically by passing them toResource.dispose(Object).
-
SimpleUserEventChannelHandler
protected SimpleUserEventChannelHandler(Class<? extends I> eventType)
seeSimpleUserEventChannelHandler(Class, boolean)withtrueas boolean value.
-
SimpleUserEventChannelHandler
protected SimpleUserEventChannelHandler(Class<? extends I> eventType, boolean autoRelease)
Create a new instance- Parameters:
eventType- The type of events to matchautoRelease-trueif handled events should be released automatically by passing them toResource.dispose(Object).
-
-
Method Detail
-
acceptEvent
protected boolean acceptEvent(Object evt) throws Exception
Returnstrueif the given user event should be handled. Iffalseit will be passed to the nextChannelHandlerin theChannelPipeline.- Throws:
Exception
-
channelInboundEvent
public final void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception
Description copied from interface:ChannelHandlerGets called if a custom inbound event happened.- Specified by:
channelInboundEventin interfaceChannelHandler- Throws:
Exception
-
eventReceived
protected abstract void eventReceived(ChannelHandlerContext ctx, I evt) throws Exception
Is called for each user event triggered of typeSimpleUserEventChannelHandler.- Parameters:
ctx- theChannelHandlerContextwhich thisSimpleUserEventChannelHandlerbelongs toevt- the user event to handle- Throws:
Exception- is thrown if an error occurred
-
-