org.exolab.jmscts.core
Class WaitingListener

java.lang.Object
  |
  +--org.exolab.jmscts.core.DelegatingListener
        |
        +--org.exolab.jmscts.core.WaitingListener
All Implemented Interfaces:
javax.jms.MessageListener

public class WaitingListener
extends DelegatingListener

This class implements the MessageListener interface and enables clients to synchronize behaviour with the onMessage(javax.jms.Message) method.

Version:
$Revision: 1.3 $
Author:
Tim Anderson

Constructor Summary
WaitingListener(javax.jms.MessageListener listener)
          Construct an instance with the listener to delegate messages.
WaitingListener(javax.jms.MessageListener listener, int count)
          Construct an instance with the listener to delegate messages, and the expected number of times that onMessage(javax.jms.Message) will be invoked.
 
Method Summary
 void notifyContinue()
          Notify the listener that it may continue processing
 void onMessage(javax.jms.Message message)
          Invoked when the consumer asynchronously receives a message.
 void waitForCompletion()
          Wait for the listener to complete processing
 void waitForReceipt()
          Wait for the listener to receive a message
 
Methods inherited from class org.exolab.jmscts.core.DelegatingListener
addMessageListener, removeMessageListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WaitingListener

public WaitingListener(javax.jms.MessageListener listener)
Construct an instance with the listener to delegate messages. The onMessage(javax.jms.Message) method may be called any number of times.
Parameters:
listener - the message listener that messages will be delegated to

WaitingListener

public WaitingListener(javax.jms.MessageListener listener,
                       int count)
Construct an instance with the listener to delegate messages, and the expected number of times that onMessage(javax.jms.Message) will be invoked.
Parameters:
listener - the message listener that messages will be delegated to
count - the expected number of times that the onMessage(javax.jms.Message) will be called
Method Detail

waitForReceipt

public void waitForReceipt()
                    throws java.lang.InterruptedException
Wait for the listener to receive a message
Throws:
java.lang.InterruptedException - if interrupted

notifyContinue

public void notifyContinue()
Notify the listener that it may continue processing

waitForCompletion

public void waitForCompletion()
                       throws java.lang.InterruptedException
Wait for the listener to complete processing
Throws:
java.lang.InterruptedException - if interrupted

onMessage

public void onMessage(javax.jms.Message message)
Invoked when the consumer asynchronously receives a message. On entry, it notifies the client blocked on waitForReceipt(). It then waits for the client to invoke notifyContinue(), before invoking the listener passed at construction. This enables clients to synchronize their behaviour with the listener.
On completion of the listener, it notifies the client blocked on waitForCompletion()

If an invocation count was specified at construction, and onMessage(javax.jms.Message) is invoked more than the specified count, an error is logged, and the method returns immediately.

Overrides:
onMessage in class DelegatingListener
Parameters:
message - the received message


Copyright © 2001-2004 JMS CTS Team. All Rights Reserved.