ChannelHandler which decodes from one message to another message.
For example here is an implementation which decodes a String to an Integer which represent
the length of the String.
public class StringToIntegerDecoder extends
MessageToMessageDecoder<String> {
@Override
public void decode(ChannelHandlerContext ctx, String message,
List<Object> out) throws Exception {
out.add(message.length());
}
}
Note that messages passed to decode(ChannelHandlerContext, Object) will be
disposed of automatically.
To take control of the message lifetime, you should instead override the
decodeAndClose(ChannelHandlerContext, Object) method.
Do not override both.
| Modifier and Type | Field and Description |
|---|---|
| private final TypeParameterMatcher |
| Access | Constructor and Description |
|---|---|
| protected | MessageToMessageDecoder()
Create a new instance which will try to detect the types to match out of the type parameter of the class. |
| protected | MessageToMessageDecoder(Class<? extends I>
The type of messages to match and so decode inboundMessageType)Create a new instance |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public void | channelRead(ChannelHandlerContext ctx, Object msg)
Overrides default io. Channel has read a message from the peer.
|
| protected void | decode(ChannelHandlerContext
the ctx, I ChannelHandlerContext which this MessageToMessageDecoder belongs tothe message to decode to another one msg)Decode from one message to another. |
| protected void | decodeAndClose(ChannelHandlerContext
the ctx, I ChannelHandlerContext which this MessageToMessageDecoder belongs tothe message to decode to another one msg)Decode from one message to another. |
| matcher | back to summary |
|---|---|
| private final TypeParameterMatcher matcher | |
| MessageToMessageDecoder | back to summary |
|---|---|
| protected MessageToMessageDecoder() Create a new instance which will try to detect the types to match out of the type parameter of the class. | |
| MessageToMessageDecoder | back to summary |
|---|---|
| protected MessageToMessageDecoder(Class<? extends I> inboundMessageType) Create a new instance
| |
| acceptInboundMessage | back to summary |
|---|---|
| public boolean acceptInboundMessage(Object msg) throws Exception Returns | |
| channelRead | back to summary |
|---|---|
| public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception Overrides default io. Doc from io. Invoked when the current
| |
| decode | back to summary |
|---|---|
| protected void decode(ChannelHandlerContext ctx, I msg) throws Exception Decode from one message to another. This method will be called for each written message that can be handled by this decoder. The message will be disposed of after this call.
Subclasses that wish to sometimes pass messages through, should instead override the
| |
| decodeAndClose | back to summary |
|---|---|
| protected void decodeAndClose(ChannelHandlerContext ctx, I msg) throws Exception Decode from one message to another. This method will be called for each written message that can be handled by this decoder. 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
| |