org.apache.qpid.client.protocol
Class BlockingMethodFrameListener

java.lang.Object
  extended by org.apache.qpid.client.util.BlockingWaiter<org.apache.qpid.protocol.AMQMethodEvent>
      extended by org.apache.qpid.client.protocol.BlockingMethodFrameListener
All Implemented Interfaces:
org.apache.qpid.protocol.AMQMethodListener
Direct Known Subclasses:
SpecificMethodFrameListener

public abstract class BlockingMethodFrameListener
extends BlockingWaiter<org.apache.qpid.protocol.AMQMethodEvent>
implements org.apache.qpid.protocol.AMQMethodListener

BlockingMethodFrameListener is a 'rendezvous' which acts as a AMQMethodListener that delegates handling of incoming methods to a method listener implemented as a sub-class of this and hands off the processed method or error to a consumer. The producer of the event does not have to wait for the consumer to take the event, so this differs from a 'rendezvous' in that sense.

BlockingMethodFrameListeners are used to coordinate waiting for replies to method calls that expect a response. They are always used in a 'one-shot' manner, that is, to recieve just one response. Usually the caller has to register them as method listeners with an event dispatcher and remember to de-register them (in a finally block) once they have been completed.

The processMethod(int, org.apache.qpid.framing.AMQMethodBody) must return true on any incoming method that it handles. This indicates to this listeners that the method it is waiting for has arrived. Incoming methods are also filtered by channel prior to being passed to the processMethod(int, org.apache.qpid.framing.AMQMethodBody) method, so responses are only received for a particular channel. The channel id must be passed to the constructor.

Errors from the producer are rethrown to the consumer.

CRC Card
Responsibilities Collaborations
Accept notification of AMQP method events. AMQMethodEvent
Delegate handling of the method to another method listener. AMQMethodBody
Block until a method is handled by the delegated to handler.
Propagate the most recent exception to the consumer.

Todo:
Might be neater if this method listener simply wrapped another that provided the method handling using a methodRecevied method. The processMethod takes an additional channelId, however none of the implementations seem to use it. So wrapping the listeners is possible., If the retrotranslator can handle it, could use a SynchronousQueue to implement this rendezvous. Need to check that SynchronousQueue has a non-blocking put method available.

Field Summary
protected  int _channelId
          Holds the channel id for the channel upon which this listener is waiting for a response.
 
Fields inherited from class org.apache.qpid.client.util.BlockingWaiter
_doneObject
 
Constructor Summary
BlockingMethodFrameListener(int channelId)
          Creates a new method listener, that filters incoming method to just those that match the specified channel id.
 
Method Summary
 org.apache.qpid.protocol.AMQMethodEvent blockForFrame(long timeout)
          Blocks until a method is received that is handled by the delegated to method listener, or the specified timeout has passed.
 boolean methodReceived(org.apache.qpid.protocol.AMQMethodEvent evt)
          Informs this listener that an AMQP method has been received.
 boolean process(org.apache.qpid.protocol.AMQMethodEvent evt)
          Delegates processing of the incomming object to the handler.
abstract  boolean processMethod(int channelId, org.apache.qpid.framing.AMQMethodBody frame)
          Delegates any additional handling of the incoming methods to another handler.
 
Methods inherited from class org.apache.qpid.client.util.BlockingWaiter
block, close, error, received
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.qpid.protocol.AMQMethodListener
error
 

Field Detail

_channelId

protected int _channelId
Holds the channel id for the channel upon which this listener is waiting for a response.

Constructor Detail

BlockingMethodFrameListener

public BlockingMethodFrameListener(int channelId)
Creates a new method listener, that filters incoming method to just those that match the specified channel id.

Parameters:
channelId - The channel id to filter incoming methods with.
Method Detail

processMethod

public abstract boolean processMethod(int channelId,
                                      org.apache.qpid.framing.AMQMethodBody frame)
Delegates any additional handling of the incoming methods to another handler.

Parameters:
channelId - The channel id of the incoming method.
frame - The method body.
Returns:
true if the method was handled, false otherwise.

process

public boolean process(org.apache.qpid.protocol.AMQMethodEvent evt)
Description copied from class: BlockingWaiter
Delegates processing of the incomming object to the handler.

Specified by:
process in class BlockingWaiter<org.apache.qpid.protocol.AMQMethodEvent>
Parameters:
evt - The object to process.
Returns:
true if the waiting is complete, false if waiting should continue.

methodReceived

public boolean methodReceived(org.apache.qpid.protocol.AMQMethodEvent evt)
Informs this listener that an AMQP method has been received.

Specified by:
methodReceived in interface org.apache.qpid.protocol.AMQMethodListener
Parameters:
evt - The AMQP method.
Returns:
true if this listener has handled the method, false otherwise.

blockForFrame

public org.apache.qpid.protocol.AMQMethodEvent blockForFrame(long timeout)
                                                      throws org.apache.qpid.AMQException,
                                                             FailoverException
Blocks until a method is received that is handled by the delegated to method listener, or the specified timeout has passed.

Parameters:
timeout - The timeout in milliseconds.
Returns:
The AMQP method that was received.
Throws:
org.apache.qpid.AMQException
FailoverException


Licensed to the Apache Software Foundation