org.osesb.connectors.jms
Class JMSQueueReceiver

java.lang.Object
  extended by org.osesb.connectors.jms.JMSConsumerBase
      extended by org.osesb.connectors.jms.JMSQueueReceiver
All Implemented Interfaces:
java.lang.Runnable, javax.jms.ExceptionListener, javax.jms.MessageListener

public class JMSQueueReceiver
extends JMSConsumerBase

This descendant of JMSConsumerBase is a blocking, Queue receiver.

An instance of a JMSQueueReceiver is associated with a particular JMS Destination. The JMS Session object is cached (but can be reset) and JMSQueueReceiver(s) can be pooled. See the org.osesb.objectpools package for JMS producer and consumer pools.

Instances of JMSQueueReceiver are constructed with a org.osesb.configuration.JMSClientConfiguration, which contains properties for creating a JMS connection.

JMSQueueReceiver implements startJMS(), close(), and receiveJMSMessage() methods that are Queue-specific.

JMSQueueReceiver(s) can be pooled. See org.osesb.objectpools.JMSClientKeyedPoolFactory.

Since:
Version .9

Field Summary
protected  javax.jms.Queue queue
          The Queue for this JMS client.
protected  javax.jms.QueueConnection queueConnection
          The QueueConnection for this JMS client.
protected  javax.jms.QueueSession queueSession
          The QueueSession for this JMS client.
 
Fields inherited from class org.osesb.connectors.jms.JMSConsumerBase
connectionStarted, dateTimeOfLastMessage, dateTimeServiceStarted, heartbeatInterval, jmsClientConfiguration, jmsMessage, log, messageID, messageText, MIN_HEARTBEAT_INTERVAL, numberOfMessagesReceived, session, thisClassName
 
Constructor Summary
JMSQueueReceiver(JMSClientConfiguration jmsClientConfiguration)
          Creates a new instance of JMSQueueReceiver and starts JMS.
JMSQueueReceiver(JMSClientConfiguration jmsClientConfiguration, javax.jms.Queue queue)
          Creates a new instance of JMSQueueReceiver and starts JMS using the specified Queue.
 
Method Summary
protected  void checkSession()
          Checks the QueueSession and restarts JMS connection, if required.
 void close()
          Release JMS resources.
 javax.jms.Connection getConnection()
          Returns the JMS Connection for this JMS client.
 javax.jms.Destination getDestination()
          Returns the JMS Destination for this JMS client.
 java.lang.String getDestinationName()
          Returns the name of the JMS Destination for this JMS client.
protected  void logConsumerStartupMessage()
          Logs a JMS startup message for JMS consumers.
protected  void logMessage(java.lang.String logMessage)
          Log the message.
static void main(java.lang.String[] args)
          main() - for testing.
 javax.jms.Message receiveJMSMessage()
          Receive a JMS Message using the configured Queue; waits for a message indefinitely.
 javax.jms.Message receiveJMSMessage(long receiveTimeoutMilliseconds, java.lang.String messageSelector)
          Receive a JMS Message using the configured Queue.
protected  javax.jms.Message retryReceiveJMSMessage(long receiveTimeoutMilliseconds, java.lang.String messageSelector)
          Retry receiving a message using the configured Queue.
 void startJMS()
          Initialize JMS objects according to JMSClientConfiguration and start the connection.
 
Methods inherited from class org.osesb.connectors.jms.JMSConsumerBase
checkJMSConnection, consumerStartupMessage, finalize, getDateTimeOfLastMessage, getDateTimeServiceStarted, getHeartbeatInterval, getJMSClientConfiguration, getNumberOfMessagesReceived, getSession, isConnectionStarted, onException, onMessage, run, setNumberOfMessagesReceived, setSession
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queueConnection

protected javax.jms.QueueConnection queueConnection
The QueueConnection for this JMS client.


queueSession

protected javax.jms.QueueSession queueSession
The QueueSession for this JMS client.


queue

protected javax.jms.Queue queue
The Queue for this JMS client.

Constructor Detail

JMSQueueReceiver

public JMSQueueReceiver(JMSClientConfiguration jmsClientConfiguration)
                 throws java.lang.Exception
Creates a new instance of JMSQueueReceiver and starts JMS.

Parameters:
jmsClientConfiguration - The JMSClientConfiguration object to use for this JMS client.
Throws:
java.lang.Exception - if constructed with a null JMSClientConfiguration.

JMSQueueReceiver

public JMSQueueReceiver(JMSClientConfiguration jmsClientConfiguration,
                        javax.jms.Queue queue)
                 throws java.lang.Exception
Creates a new instance of JMSQueueReceiver and starts JMS using the specified Queue. This constructor is used by synchronous senders, where the replyTo Destination is configured in the portion of the JMSClientConfiguration.

Parameters:
jmsClientConfiguration - The JMSClientConfiguration object to use for this client.
queue - The Queue to start the JMS connection for.
Throws:
java.lang.Exception - if constructed with a null JMSClientConfiguration.
Method Detail

receiveJMSMessage

public javax.jms.Message receiveJMSMessage()
                                    throws java.lang.Exception
Receive a JMS Message using the configured Queue; waits for a message indefinitely.

Specified by:
receiveJMSMessage in class JMSConsumerBase
Returns:
the Message that was received.
Throws:
java.lang.Exception - if a general is error encountered.

receiveJMSMessage

public javax.jms.Message receiveJMSMessage(long receiveTimeoutMilliseconds,
                                           java.lang.String messageSelector)
                                    throws java.lang.Exception
Receive a JMS Message using the configured Queue.

Specified by:
receiveJMSMessage in class JMSConsumerBase
Parameters:
receiveTimeoutMilliseconds - receive timeout in milliseconds. If receiveTimeout > 0, then the receiver waits for a message for the specified number of milliseconds, otherwise, the receiver waits for a message indefinitely.
messageSelector - The JMS messageSelector.
Returns:
the Message that was received.
Throws:
java.lang.Exception - if a general is error encountered.

retryReceiveJMSMessage

protected javax.jms.Message retryReceiveJMSMessage(long receiveTimeoutMilliseconds,
                                                   java.lang.String messageSelector)
                                            throws java.lang.Exception
Retry receiving a message using the configured Queue.

Parameters:
receiveTimeoutMilliseconds - receive timeout in milliseconds. If receiveTimeout > 0, then the receiver waits for a message for the specified number of milliseconds, otherwise, the receiver waits for a message indefinitely.
messageSelector - The JMS messageSelector.
Returns:
the Message that was received.
Throws:
java.lang.Exception - if a general is error encountered.

getDestinationName

public java.lang.String getDestinationName()
Returns the name of the JMS Destination for this JMS client.

Specified by:
getDestinationName in class JMSConsumerBase
Returns:
the name of the JMS Destination for this JMS client.

getConnection

public javax.jms.Connection getConnection()
Returns the JMS Connection for this JMS client.

Specified by:
getConnection in class JMSConsumerBase
Returns:
the JMS Connection for this JMS client.

getDestination

public javax.jms.Destination getDestination()
Returns the JMS Destination for this JMS client.

Specified by:
getDestination in class JMSConsumerBase
Returns:
the JMS Destination for this JMS client.

logMessage

protected void logMessage(java.lang.String logMessage)
Log the message. Override this method to log differently.

Overrides:
logMessage in class JMSConsumerBase
Parameters:
logMessage - The message to log.

startJMS

public void startJMS()
Initialize JMS objects according to JMSClientConfiguration and start the connection.

Specified by:
startJMS in class JMSConsumerBase

logConsumerStartupMessage

protected void logConsumerStartupMessage()
Logs a JMS startup message for JMS consumers.


checkSession

protected void checkSession()
                     throws java.lang.Exception
Checks the QueueSession and restarts JMS connection, if required.

Specified by:
checkSession in class JMSConsumerBase
Throws:
java.lang.Exception - if there was a problem getting a QueueSession.

close

public void close()
Release JMS resources.

Specified by:
close in class JMSConsumerBase

main

public static void main(java.lang.String[] args)
main() - for testing.

Parameters:
args - commandline arguments