org.exolab.jms.client
Class JmsMessageConsumer

java.lang.Object
  |
  +--org.exolab.jms.client.JmsMessageConsumer
All Implemented Interfaces:
javax.jms.MessageConsumer, javax.jms.MessageListener
Direct Known Subclasses:
JmsQueueReceiver, JmsTopicSubscriber

public abstract class JmsMessageConsumer
extends java.lang.Object
implements javax.jms.MessageListener, javax.jms.MessageConsumer

This is an abstract class that defines the generic behaviour of a consumer. A consumer is created and controlled through a session

Instances of these class pertain to a Destination, whether it is a queue or a topic. In addition a consumer can only be created through a valid session.

Version:
$Revision: 1.36 $ $Date: 2003/08/07 13:32:49 $
Author:
Jim Alateras
See Also:
JmsQueueReceiver

Field Summary
protected  org.exolab.jms.client.JmsSession _session
          A consumer needs to be allocated through the session.
 
Method Summary
 void close()
           
 void destroy()
          Release all resources used by this consumer
 long getClientId()
          Return the session allocated consumer identifier
 java.lang.String getConsumerId()
          This accessor will return a reference to the consumer id.
abstract  JmsDestination getJmsDestination()
          This is an anstratc message that returns a reference to the destination
 java.lang.String getLastMessageDelivered()
          Return the last message asynchronously delivered to the consumer
 javax.jms.MessageListener getMessageListener()
           
 java.lang.String getMessageSelector()
           
 boolean isClosed()
          Determines if the consumer is closed
 void onMessage(javax.jms.Message message)
          Whenever a message is received for this destination it is processed as follows.
 javax.jms.Message receive()
           
 javax.jms.Message receive(long timeout)
           
 javax.jms.Message receiveNoWait()
           
 javax.jms.Message retrieveMessage(long wait)
          This method will make a synchronous call to the server and retrieve the first message in the cache.
 void setMessageListener(javax.jms.MessageListener listener)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_session

protected org.exolab.jms.client.JmsSession _session
A consumer needs to be allocated through the session. This instance is aa back pointer to the session
Method Detail

getConsumerId

public java.lang.String getConsumerId()
This accessor will return a reference to the consumer id. It could be null.
Returns:
String

getClientId

public long getClientId()
Return the session allocated consumer identifier
Returns:
the identifier allocated to this by the session

getMessageSelector

public java.lang.String getMessageSelector()
                                    throws javax.jms.JMSException
Specified by:
getMessageSelector in interface javax.jms.MessageConsumer

getMessageListener

public javax.jms.MessageListener getMessageListener()
                                             throws javax.jms.JMSException
Specified by:
getMessageListener in interface javax.jms.MessageConsumer

setMessageListener

public void setMessageListener(javax.jms.MessageListener listener)
                        throws javax.jms.JMSException
Specified by:
setMessageListener in interface javax.jms.MessageConsumer

receive

public javax.jms.Message receive()
                          throws javax.jms.JMSException
Specified by:
receive in interface javax.jms.MessageConsumer

receive

public javax.jms.Message receive(long timeout)
                          throws javax.jms.JMSException
Specified by:
receive in interface javax.jms.MessageConsumer

receiveNoWait

public javax.jms.Message receiveNoWait()
                                throws javax.jms.JMSException
Specified by:
receiveNoWait in interface javax.jms.MessageConsumer

close

public void close()
           throws javax.jms.JMSException
Specified by:
close in interface javax.jms.MessageConsumer

destroy

public void destroy()
             throws javax.jms.JMSException
Release all resources used by this consumer
Throws:
javax.jms.JMSException -  

onMessage

public void onMessage(javax.jms.Message message)
Whenever a message is received for this destination it is processed as follows. If a message listener has been designated then it is sent straight to the message listener. If a message listener has not been registered for this destination it is placed on the cache.
Specified by:
onMessage in interface javax.jms.MessageListener
Parameters:
message - message received

retrieveMessage

public javax.jms.Message retrieveMessage(long wait)
                                  throws javax.jms.JMSException
This method will make a synchronous call to the server and retrieve the first message in the cache. It will return null if there are no messages yet.

If there are any problems then return JMSException

Parameters:
wait - the maximum time to wait for a message, in milliseconds. If -1, don't wait, if 0 wait indefinitely, otherwise wait the specified time.
Returns:
the received message, or null, if no message is available
Throws:
javax.jms.JMSException - if an error occurs retrieving the message, the session is closed, or a message listener is set.

getLastMessageDelivered

public java.lang.String getLastMessageDelivered()
Return the last message asynchronously delivered to the consumer
Returns:
String - last message delivered

isClosed

public boolean isClosed()
Determines if the consumer is closed
Returns:
true if the consumer is closed

getJmsDestination

public abstract JmsDestination getJmsDestination()
This is an anstratc message that returns a reference to the destination
Returns:
JmsDestination


Copyright © 1999-2004 The OpenJMS Group. All Rights Reserved.