ChannelHandler which encodes from one message to another 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());
}
}
Note that messages passed to encode(ChannelHandlerContext, Object, List) will be
disposed of automatically.
To take control of the message lifetime, you should instead override the
encodeAndClose(ChannelHandlerContext, Object, List) method.
Do not override both.
| 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 void | encode(ChannelHandlerContext
the ctx, I ChannelHandlerContext which this MessageToMessageEncoder belongs to.the message to encode to another one. msg, List<Object> the out)List into which produced output messages should be added.Encode from one message to another. |
| protected void | encodeAndClose(ChannelHandlerContext
the ctx, I ChannelHandlerContext which this MessageToMessageEncoder belongs to.the message to encode to another one. msg, List<Object> the out)List into which produced output messages should be added.Encode from one message to another. |
| public Future | write(ChannelHandlerContext
the ctx, Object ChannelHandlerContext for which the write operation is madethe message to write msg)Overrides default io. |
| 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 void encode(ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception Encode from one message to another. This method will be called for each written message that can be handled by this encoder. The message will be disposed of after this call.
Subclasses that wish to sometimes pass messages through, should instead override the
| |
| encodeAndClose | back to summary |
|---|---|
| protected void encodeAndClose(ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception Encode from one message to another. This method will be called for each written message that can be handled by this encoder. The message will not be automatically disposed of after this call. Instead, the responsibility of ensuring that messages are disposed of falls upon the implementor of this method.
Subclasses that wish to have incoming messages automatically disposed of should instead override the
| |
| write | back to summary |
|---|---|
| public Future Overrides default io. Doc from io. Called once a write operation is made. The write operation will write the messages through the
| |
| writePromiseCombiner | back to summary |
|---|---|
| private static void writePromiseCombiner(ChannelHandlerContext ctx, CodecOutputList out, Promise<Void> promise) | |