org.apache.qpid.codec
Class AMQDecoder

java.lang.Object
  extended by org.apache.mina.filter.codec.ProtocolDecoderAdapter
      extended by org.apache.mina.filter.codec.CumulativeProtocolDecoder
          extended by org.apache.qpid.codec.AMQDecoder
All Implemented Interfaces:
org.apache.mina.filter.codec.ProtocolDecoder

public class AMQDecoder
extends org.apache.mina.filter.codec.CumulativeProtocolDecoder

AMQDecoder delegates the decoding of AMQP either to a data block decoder, or in the case of new connections, to a protocol initiation decoder. It is a cumulative decoder, which means that it can accumulate data to decode in the buffer until there is enough data to decode.

One instance of this class is created per session, so any changes or configuration done at run time to the decoder will only affect decoding of the protocol session data to which is it bound.

CRC Card
Responsibilities Collaborations
Delegate protocol initiation to its decoder. ProtocolInitiation.Decoder
Delegate AMQP data to its decoder. AMQDataBlockDecoder
Accept notification that protocol initiation has completed.

Todo:
If protocol initiation decoder not needed, then don't create it. Probably not a big deal, but it adds to the per-session overhead.

Constructor Summary
AMQDecoder(boolean expectProtocolInitiation, AMQVersionAwareProtocolSession session)
          Creates a new AMQP decoder.
 
Method Summary
 void decode(org.apache.mina.common.IoSession session, org.apache.mina.common.ByteBuffer in, org.apache.mina.filter.codec.ProtocolDecoderOutput out)
          Cumulates content of in into internal buffer and forwards decoding request to doDecode(IoSession, ByteBuffer, ProtocolDecoderOutput).
 ArrayList<AMQDataBlock> decodeBuffer(ByteBuffer buf)
           
 void dispose(org.apache.mina.common.IoSession session)
          Releases the cumulative buffer used by the specified session.
protected  boolean doDecode(org.apache.mina.common.IoSession session, org.apache.mina.common.ByteBuffer in, org.apache.mina.filter.codec.ProtocolDecoderOutput out)
          Delegates decoding AMQP from the data buffer that Mina has retrieved from the wire, to the data or protocol intiation decoders.
protected  boolean doDecodeDataBlock(org.apache.mina.common.IoSession session, org.apache.mina.common.ByteBuffer in, org.apache.mina.filter.codec.ProtocolDecoderOutput out)
          Decodes AMQP data, delegating the decoding to an AMQDataBlockDecoder.
 void setExpectProtocolInitiation(boolean expectProtocolInitiation)
          Sets the protocol initation flag, that determines whether decoding is handled by the data decoder of the protocol initation decoder.
 
Methods inherited from class org.apache.mina.filter.codec.ProtocolDecoderAdapter
finishDecode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AMQDecoder

public AMQDecoder(boolean expectProtocolInitiation,
                  AMQVersionAwareProtocolSession session)
Creates a new AMQP decoder.

Parameters:
expectProtocolInitiation - true if this decoder needs to handle protocol initiation.
Method Detail

doDecode

protected boolean doDecode(org.apache.mina.common.IoSession session,
                           org.apache.mina.common.ByteBuffer in,
                           org.apache.mina.filter.codec.ProtocolDecoderOutput out)
                    throws Exception
Delegates decoding AMQP from the data buffer that Mina has retrieved from the wire, to the data or protocol intiation decoders.

Specified by:
doDecode in class org.apache.mina.filter.codec.CumulativeProtocolDecoder
Parameters:
session - The Mina session.
in - The raw byte buffer.
out - The Mina object output gatherer to write decoded objects to.
Returns:
true if the data was decoded, false if more is needed and the data should accumulate.
Throws:
Exception - If the data cannot be decoded for any reason.

doDecodeDataBlock

protected boolean doDecodeDataBlock(org.apache.mina.common.IoSession session,
                                    org.apache.mina.common.ByteBuffer in,
                                    org.apache.mina.filter.codec.ProtocolDecoderOutput out)
                             throws Exception
Decodes AMQP data, delegating the decoding to an AMQDataBlockDecoder.

Parameters:
session - The Mina session.
in - The raw byte buffer.
out - The Mina object output gatherer to write decoded objects to.
Returns:
true if the data was decoded, false if more is needed and the data should accumulate.
Throws:
Exception - If the data cannot be decoded for any reason.

setExpectProtocolInitiation

public void setExpectProtocolInitiation(boolean expectProtocolInitiation)
Sets the protocol initation flag, that determines whether decoding is handled by the data decoder of the protocol initation decoder. This method is expected to be called with false once protocol initation completes.

Parameters:
expectProtocolInitiation - true to use the protocol initiation decoder, false to use the data decoder.

decode

public void decode(org.apache.mina.common.IoSession session,
                   org.apache.mina.common.ByteBuffer in,
                   org.apache.mina.filter.codec.ProtocolDecoderOutput out)
            throws Exception
Cumulates content of in into internal buffer and forwards decoding request to doDecode(IoSession, ByteBuffer, ProtocolDecoderOutput). doDecode() is invoked repeatedly until it returns false and the cumulative buffer is compacted after decoding ends.

Specified by:
decode in interface org.apache.mina.filter.codec.ProtocolDecoder
Overrides:
decode in class org.apache.mina.filter.codec.CumulativeProtocolDecoder
Throws:
IllegalStateException - if your doDecode() returned true not consuming the cumulative buffer.
Exception

dispose

public void dispose(org.apache.mina.common.IoSession session)
             throws Exception
Releases the cumulative buffer used by the specified session. Please don't forget to call super.dispose( session ) when you override this method.

Specified by:
dispose in interface org.apache.mina.filter.codec.ProtocolDecoder
Overrides:
dispose in class org.apache.mina.filter.codec.CumulativeProtocolDecoder
Throws:
Exception

decodeBuffer

public ArrayList<AMQDataBlock> decodeBuffer(ByteBuffer buf)
                                     throws AMQFrameDecodingException,
                                            AMQProtocolVersionException
Throws:
AMQFrameDecodingException
AMQProtocolVersionException


Licensed to the Apache Software Foundation