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, List<Object> 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 and Type | Field and Description |
|---|---|
| private final TypeParameterMatcher |
| Access | Constructor and Description |
|---|---|
| protected | MessageToMessageEncoder()
Create a new instance which will try to detect the types to match out of the type parameter of the class. |
| protected | MessageToMessageEncoder(Class<? extends I>
The type of messages to match and so encode outboundMessageType)Create a new instance |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| protected abstract void | encode(ChannelHandlerContext
the ctx, I ChannelHandlerContext which this MessageToMessageEncoder belongs tothe message to encode to an other one msg, List<Object> the out)List into which the encoded msg should be added
needs to do some kind of aggregationEncode from one message to an other. |
| public void | write(ChannelHandlerContext
the ctx, Object ChannelHandlerContext for which the write operation is madethe message to write msg, ChannelPromise the promise)ChannelPromise to notify once the operation completesOverrides io. Implements io. ChannelHandlerContext#write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
|
| private static void | |
| private static void |
| matcher | back to summary |
|---|---|
| private final TypeParameterMatcher matcher | |
| MessageToMessageEncoder | back to summary |
|---|---|
| protected MessageToMessageEncoder() Create a new instance which will try to detect the types to match out of the type parameter of the class. | |
| MessageToMessageEncoder | back to summary |
|---|---|
| protected MessageToMessageEncoder(Class<? extends I> outboundMessageType) Create a new instance
| |
| acceptOutboundMessage | back to summary |
|---|---|
| public boolean acceptOutboundMessage(Object msg) throws Exception Returns | |
| encode | back to summary |
|---|---|
| protected abstract void encode(ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception Encode from one message to an other. This method will be called for each written message that can be handled by this encoder.
| |
| write | back to summary |
|---|---|
| public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| writePromiseCombiner | back to summary |
|---|---|
| private static void writePromiseCombiner(ChannelHandlerContext ctx, CodecOutputList out, ChannelPromise promise) | |
| writeVoidPromise | back to summary |
|---|---|
| private static void writeVoidPromise(ChannelHandlerContext ctx, CodecOutputList out) | |