public abstract class BlockingMethodFrameListener extends BlockingWaiter<AMQMethodEvent> implements AMQMethodListener
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.
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.
TODO 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.
Constructor and Description |
---|
BlockingMethodFrameListener(int channelId)
Creates a new method listener, that filters incoming method to just those that match the specified channel id.
|
Modifier and Type | Method and Description |
---|---|
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(AMQMethodEvent evt)
Informs this listener that an AMQP method has been received.
|
boolean |
process(AMQMethodEvent evt)
Delegates processing of the incoming object to the handler.
|
abstract boolean |
processMethod(int channelId,
AMQMethodBody frame)
Delegates any additional handling of the incoming methods to another handler.
|
block, close, error, received
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
error
public BlockingMethodFrameListener(int channelId)
channelId
- The channel id to filter incoming methods with.public abstract boolean processMethod(int channelId, AMQMethodBody frame)
channelId
- The channel id of the incoming method.frame
- The method body.public boolean process(AMQMethodEvent evt)
BlockingWaiter
process
in class BlockingWaiter<AMQMethodEvent>
evt
- The object to process.public boolean methodReceived(AMQMethodEvent evt)
methodReceived
in interface AMQMethodListener
evt
- The AMQP method.public AMQMethodEvent blockForFrame(long timeout) throws QpidException, FailoverException
timeout
- The timeout in milliseconds.QpidException
FailoverException
Copyright © 2006–2016 The Apache Software Foundation. All rights reserved.