A composite {@link ProtocolDecoder} that demultiplexes incoming {@link IoBuffer}decoding requests into an appropriate {@link MessageDecoder}.
Internal mechanism of {@link MessageDecoder} selection
- {@link DemuxingProtocolDecoder} iterates the list of candidate{@link MessageDecoder}s and calls {@link MessageDecoder#decodable(IoSession,IoBuffer)}. Initially, all registered {@link MessageDecoder}s are candidates.
- If {@link MessageDecoderResult#NOT_OK} is returned, it is removed from the candidatelist.
- If {@link MessageDecoderResult#NEED_DATA} is returned, it is retained in the candidatelist, and its {@link MessageDecoder#decodable(IoSession,IoBuffer)} will be invokedagain when more data is received.
- If {@link MessageDecoderResult#OK} is returned, {@link DemuxingProtocolDecoder}found the right {@link MessageDecoder}.
- If there's no candidate left, an exception is raised. Otherwise, {@link DemuxingProtocolDecoder} will keep iterating the candidate list.
Please note that any change of position and limit of the specified {@link IoBuffer}in {@link MessageDecoder#decodable(IoSession,IoBuffer)} will be reverted back to itsoriginal value.
Once a {@link MessageDecoder} is selected, {@link DemuxingProtocolDecoder} calls{@link MessageDecoder#decode(IoSession,IoBuffer,ProtocolDecoderOutput)} continuouslyreading its return value:
- {@link MessageDecoderResult#NOT_OK} - protocol violation; {@link ProtocolDecoderException}is raised automatically.
- {@link MessageDecoderResult#NEED_DATA} - needs more data to read the whole message;{@link MessageDecoder#decode(IoSession,IoBuffer,ProtocolDecoderOutput)}will be invoked again when more data is received.
- {@link MessageDecoderResult#OK} - successfully decoded a message; the candidate list willbe reset and the selection process will start over.
@author The Apache MINA Project (dev@mina.apache.org)
@version $Rev: 612026 $, $Date: 2008-01-15 15:16:14 +0900 (화, 15 1월 2008) $
@see MessageDecoderFactory
@see MessageDecoder