|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.mina.filter.codec.ProtocolDecoderAdapter
org.apache.mina.filter.codec.CumulativeProtocolDecoder
org.apache.mina.filter.codec.demux.DemuxingProtocolDecoder
public class DemuxingProtocolDecoder
A composite ProtocolDecoder that demultiplexes incoming IoBuffer
decoding requests into an appropriate MessageDecoder.
MessageDecoder selection
DemuxingProtocolDecoder iterates the list of candidate
MessageDecoders and calls MessageDecoder.decodable(IoSession, IoBuffer).
Initially, all registered MessageDecoders are candidates.MessageDecoderResult.NOT_OK is returned, it is removed from the candidate
list.MessageDecoderResult.NEED_DATA is returned, it is retained in the candidate
list, and its MessageDecoder.decodable(IoSession, IoBuffer) will be invoked
again when more data is received.MessageDecoderResult.OK is returned, DemuxingProtocolDecoder
found the right MessageDecoder.DemuxingProtocolDecoder will keep iterating the candidate list.
IoBuffer
in MessageDecoder.decodable(IoSession, IoBuffer) will be reverted back to its
original value.
Once a MessageDecoder is selected, DemuxingProtocolDecoder calls
MessageDecoder.decode(IoSession, IoBuffer, ProtocolDecoderOutput) continuously
reading its return value:
MessageDecoderResult.NOT_OK - protocol violation; ProtocolDecoderException
is raised automatically.MessageDecoderResult.NEED_DATA - needs more data to read the whole message;
MessageDecoder.decode(IoSession, IoBuffer, ProtocolDecoderOutput)
will be invoked again when more data is received.MessageDecoderResult.OK - successfully decoded a message; the candidate list will
be reset and the selection process will start over.
MessageDecoderFactory,
MessageDecoder| Constructor Summary | |
|---|---|
DemuxingProtocolDecoder()
|
|
| Method Summary | |
|---|---|
void |
addMessageDecoder(Class<? extends MessageDecoder> decoderClass)
|
void |
addMessageDecoder(MessageDecoder decoder)
|
void |
addMessageDecoder(MessageDecoderFactory factory)
|
void |
dispose(IoSession session)
Releases the cumulative buffer used by the specified session. |
protected boolean |
doDecode(IoSession session,
IoBuffer in,
ProtocolDecoderOutput out)
Implement this method to consume the specified cumulative buffer and decode its content into message(s). |
void |
finishDecode(IoSession session,
ProtocolDecoderOutput out)
Override this method to deal with the closed connection. |
| Methods inherited from class org.apache.mina.filter.codec.CumulativeProtocolDecoder |
|---|
decode |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DemuxingProtocolDecoder()
| Method Detail |
|---|
public void addMessageDecoder(Class<? extends MessageDecoder> decoderClass)
public void addMessageDecoder(MessageDecoder decoder)
public void addMessageDecoder(MessageDecoderFactory factory)
protected boolean doDecode(IoSession session,
IoBuffer in,
ProtocolDecoderOutput out)
throws Exception
CumulativeProtocolDecoder
doDecode in class CumulativeProtocolDecoderin - the cumulative buffer
Exception - if cannot decode in.
public void finishDecode(IoSession session,
ProtocolDecoderOutput out)
throws Exception
ProtocolDecoderAdapter
finishDecode in interface ProtocolDecoderfinishDecode in class ProtocolDecoderAdapterException - if the read data violated protocol specification
public void dispose(IoSession session)
throws Exception
CumulativeProtocolDecoder
dispose in interface ProtocolDecoderdispose in class CumulativeProtocolDecoderException - if failed to dispose all resources
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||