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 extends
             SimpleChannelOutboundHandler<String> {
         @Override
         protected void channelWrite0(ChannelHandlerContext ctx, String message)
                 throws Exception {
             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
ConstructorsModifierConstructorDescriptionprotectedseeSimpleChannelOutboundHandler(boolean, boolean)withfalseas boolean parameters.protectedSimpleChannelOutboundHandler(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.protectedSimpleChannelOutboundHandler(Class<? extends O> outboundMessageType) seeSimpleChannelOutboundHandler(Class, boolean, boolean)withfalseas boolean parameters.protectedSimpleChannelOutboundHandler(Class<? extends O> outboundMessageType, boolean outboundAutoRelease, boolean autoFulfillPromise) Create a new instance. - 
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrueif the given message should be handled.protected abstract voidchannelWrite0(io.netty.channel.ChannelHandlerContext ctx, O msg, io.netty.channel.ChannelPromise promise) Is called for each message of typeSimpleChannelOutboundHandleron the outbound channel.voidwrite(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, readMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
exceptionCaught, handlerAdded, handlerRemoved 
- 
Constructor Details
- 
SimpleChannelOutboundHandler
protected SimpleChannelOutboundHandler()seeSimpleChannelOutboundHandler(boolean, boolean)withfalseas 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-trueif handled messages should be released automatically by passing them toReferenceCountUtil.release(Object).autoFulfillPromise-trueif handled promise should be released automatically by callingChannelPromise.setSuccess().
 - 
SimpleChannelOutboundHandler
seeSimpleChannelOutboundHandler(Class, boolean, boolean)withfalseas boolean parameters. - 
SimpleChannelOutboundHandler
protected SimpleChannelOutboundHandler(Class<? extends O> outboundMessageType, boolean outboundAutoRelease, boolean autoFulfillPromise) Create a new instance.- Parameters:
 outboundMessageType- type of messagesoutboundAutoRelease-trueif handled messages should be released automatically by passing them toReferenceCountUtil.release(Object).autoFulfillPromise-trueif 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:
 writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
 writein classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
 Exception
 - 
acceptOutboundMessage
Returnstrueif the given message should be handled. Iffalseit will be passed to the nextChannelOutboundHandlerin 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 typeSimpleChannelOutboundHandleron the outbound channel.- Parameters:
 ctx- theChannelHandlerContextwhich thisSimpleChannelDuplexHandlerbelongs tomsg- the message to handlepromise- the corresponding promise- Throws:
 Exception- is thrown if an error occurred
 
 -