org.exolab.jmscts.core
Class CountingListener
java.lang.Object
|
+--org.exolab.jmscts.core.CountingListener
- All Implemented Interfaces:
- javax.jms.MessageListener
- Direct Known Subclasses:
- AckingListener, CachingListener
- public class CountingListener
- extends java.lang.Object
- implements javax.jms.MessageListener
Helper class for counting the number of messages received.
Clients waiting on this will be notified when the expected number of
messages are received.
- Version:
- $Revision: 1.3 $ $Date: 2004/01/31 13:44:24 $
- Author:
- Tim Anderson
|
Constructor Summary |
CountingListener(int expected)
Construct an instance of the listener, with the number of messages
expected to be received. |
|
Method Summary |
int |
getExpected()
Returns the no. |
int |
getReceived()
Returns the count of received messages |
void |
onMessage(javax.jms.Message message)
This method is asynchronously invoked by the message consumer when
a message becomes available. |
void |
waitForCompletion()
Wait indefinitely for the listener to complete processing |
boolean |
waitForCompletion(long timeout)
Wait for the listener to complete processing |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CountingListener
public CountingListener(int expected)
- Construct an instance of the listener, with the number of messages
expected to be received. When this count is reached, the listener
notifies the waiting client (if any)
- Parameters:
expected - the number of messages expected
onMessage
public void onMessage(javax.jms.Message message)
- This method is asynchronously invoked by the message consumer when
a message becomes available.
If the number of expected messages are received, it notifies
the waiting client (if any)
- Specified by:
onMessage in interface javax.jms.MessageListener
- Parameters:
message - the received message
getExpected
public int getExpected()
- Returns the no. of messages expected
- Returns:
- the no. of messages expected
getReceived
public int getReceived()
- Returns the count of received messages
- Returns:
- the number of messages received
waitForCompletion
public boolean waitForCompletion(long timeout)
throws java.lang.InterruptedException
- Wait for the listener to complete processing
- Parameters:
timeout - the number of milleseconds to wait. An argument less
than or equal to zero means not to wait at all- Returns:
true if the listener completed in the given time
frame- Throws:
java.lang.InterruptedException - if interrupted while waiting
waitForCompletion
public void waitForCompletion()
throws java.lang.InterruptedException
- Wait indefinitely for the listener to complete processing
- Throws:
java.lang.InterruptedException - if interrupted while waiting
Copyright © 2001-2004 JMS CTS Team. All Rights Reserved.