Class SimpleChannelOutboundHandler<O>
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelOutboundHandlerAdapter
org.drasyl.peer.connection.handler.SimpleChannelOutboundHandler<O>
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelOutboundHandler
- Direct Known Subclasses:
RelayableMessageGuard
public abstract class SimpleChannelOutboundHandler<O>
extends io.netty.channel.ChannelOutboundHandlerAdapter
ChannelOutboundHandlerAdapter
which allows to explicit only handle a specific type of
messages.
For example here is an implementation which only handle String
messages.
public class StringHandler extendsSimpleChannelOutboundHandler
<String
> {@Override
protected void channelWrite0(ChannelHandlerContext
ctx,String
message) throwsException
{ System.out.println(message); } }
Be aware that depending of the constructor parameters it will release all handled messages 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
.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
seeSimpleChannelOutboundHandler(boolean, boolean)
withfalse
as boolean parameters.protected
SimpleChannelOutboundHandler
(boolean outboundAutoRelease, boolean autoFulfillPromise) Create a new instance which will try to detect the types to match out of the type parameter of the class.protected
SimpleChannelOutboundHandler
(Class<? extends O> outboundMessageType) seeSimpleChannelOutboundHandler(Class, boolean, boolean)
withfalse
as boolean parameters.protected
SimpleChannelOutboundHandler
(Class<? extends O> outboundMessageType, boolean outboundAutoRelease, boolean autoFulfillPromise) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if the given message should be handled.protected abstract void
channelWrite0
(io.netty.channel.ChannelHandlerContext ctx, O msg, io.netty.channel.ChannelPromise promise) Is called for each message of typeSimpleChannelOutboundHandler
on the outbound channel.void
write
(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, read
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, 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
exceptionCaught, handlerAdded, handlerRemoved
-
Constructor Details
-
SimpleChannelOutboundHandler
protected SimpleChannelOutboundHandler()seeSimpleChannelOutboundHandler(boolean, boolean)
withfalse
as boolean parameters. -
SimpleChannelOutboundHandler
protected SimpleChannelOutboundHandler(boolean outboundAutoRelease, boolean autoFulfillPromise) Create a new instance which will try to detect the types to match out of the type parameter of the class.- Parameters:
outboundAutoRelease
-true
if handled messages should be released automatically by passing them toReferenceCountUtil.release(Object)
.autoFulfillPromise
-true
if handled promise should be released automatically by callingChannelPromise.setSuccess()
.
-
SimpleChannelOutboundHandler
seeSimpleChannelOutboundHandler(Class, boolean, boolean)
withfalse
as boolean parameters. -
SimpleChannelOutboundHandler
protected SimpleChannelOutboundHandler(Class<? extends O> outboundMessageType, boolean outboundAutoRelease, boolean autoFulfillPromise) Create a new instance.- Parameters:
outboundMessageType
- type of messagesoutboundAutoRelease
-true
if handled messages should be released automatically by passing them toReferenceCountUtil.release(Object)
.autoFulfillPromise
-true
if handled promise should be released automatically by callingChannelPromise.setSuccess()
.
-
-
Method Details
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception - Specified by:
write
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
write
in classio.netty.channel.ChannelOutboundHandlerAdapter
- Throws:
Exception
-
acceptOutboundMessage
Returnstrue
if the given message should be handled. Iffalse
it will be passed to the nextChannelOutboundHandler
in theChannelPipeline
. -
channelWrite0
protected abstract void channelWrite0(io.netty.channel.ChannelHandlerContext ctx, O msg, io.netty.channel.ChannelPromise promise) throws Exception Is called for each message of typeSimpleChannelOutboundHandler
on the outbound channel.- Parameters:
ctx
- theChannelHandlerContext
which thisSimpleChannelDuplexHandler
belongs tomsg
- the message to handlepromise
- the corresponding promise- Throws:
Exception
- is thrown if an error occurred
-