public abstract class MessageToMessageEncoder<I>
extends io.netty.channel.ChannelOutboundHandlerAdapter
ChannelOutboundHandlerAdapter which encodes from one message to an other message
For example here is an implementation which decodes an Integer to an String.
public class IntegerToStringEncoder extends
MessageToMessageEncoder<Integer> {
@Override
public void encode(ChannelHandlerContext ctx, Integer message, MessageList out)
throws Exception {
out.add(message.toString());
}
}
Be aware that you need to call ReferenceCounted.retain() on messages that are just passed through if they
are of type ReferenceCounted. This is needed as the MessageToMessageEncoder will call
ReferenceCounted.release() on encoded messages.| Modifier | Constructor and Description |
|---|---|
protected |
MessageToMessageEncoder() |
protected |
MessageToMessageEncoder(Class<? extends I> outboundMessageType) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptOutboundMessage(Object msg) |
protected abstract void |
encode(io.netty.channel.ChannelHandlerContext ctx,
I msg,
io.netty.channel.MessageList<Object> out)
Encode from one message to an other.
|
void |
write(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.MessageList<Object> msgs,
io.netty.channel.ChannelPromise promise) |
bind, close, connect, deregister, disconnect, readexceptionCaught, handlerAdded, handlerRemovedpublic boolean acceptOutboundMessage(Object msg) throws Exception
Exceptionpublic void write(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.MessageList<Object> msgs,
io.netty.channel.ChannelPromise promise)
throws Exception
write in interface io.netty.channel.ChannelOutboundHandlerwrite in class io.netty.channel.ChannelOutboundHandlerAdapterExceptionprotected abstract void encode(io.netty.channel.ChannelHandlerContext ctx,
I msg,
io.netty.channel.MessageList<Object> out)
throws Exception
MessageList has nothing
left or till this method returns null.ctx - the ChannelHandlerContext which this MessageToMessageEncoder belongs tomsg - the message to encode to an other oneout - the MessageList into which the encoded msg should be added
needs to do some kind of aggragationException - is thrown if an error accourCopyright © 2008-2013 The Netty Project. All Rights Reserved.