ChannelInboundHandlerAdapter which decodes from one message to an other 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());
}
}
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 MessageToMessageDecoder will call
ReferenceCounted#release() on decoded messages.
| 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 io. Implements io. ChannelHandlerContext#fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline.
|
| protected abstract void | decode(ChannelHandlerContext
the ctx, I ChannelHandlerContext which this MessageToMessageDecoder belongs tothe message to decode to an other one msg, List<Object> the out)List to which decoded messages should be addedDecode from one message to an other. |
| 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 io. Implements io. Doc from io. Calls
| |
| decode | back to summary |
|---|---|
| protected abstract void decode(ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception Decode from one message to an other. This method will be called for each written message that can be handled by this decoder.
| |