eu.semaine.jms.receiver
Class Receiver

java.lang.Object
  extended by eu.semaine.jms.IOBase
      extended by eu.semaine.jms.receiver.Receiver
Direct Known Subclasses:
BytesReceiver, FeatureReceiver, JMSLogReader, XMLReceiver

public class Receiver
extends IOBase

This class handles the common part to all message receivers in the SEMAINE system. Two models of use are possible:

The Receiver itself covers basic text messages only. Subclasses should override createSEMAINEMessage(Message) to do a meaningful analysis of the JMS message in terms of a suitable subclass of SEMAINEMessage.

Author:
marc

Nested Class Summary
 
Nested classes/interfaces inherited from class eu.semaine.jms.IOBase
IOBase.ConnectionStatus, IOBase.Event
 
Field Summary
protected  MessageConsumer consumer
           
protected  SEMAINEMessageAvailableListener listener
           
protected  JMSLogger log
           
protected  SEMAINEMessage message
           
 
Fields inherited from class eu.semaine.jms.IOBase
connection, exception, isConnectionStarted, jmsPassword, jmsUrl, jmsUser, session, topic, topicName
 
Constructor Summary
Receiver(java.lang.String topicName)
          Create a receiver that will listen for all messages in the given Topic on the default JMS server.
Receiver(java.lang.String topicName, java.lang.String messageSelector)
          Create a receiver that will listen only to the messages in the given Topic that will pass the given messageSelector, on the default JMS server.
Receiver(java.lang.String jmsUrl, java.lang.String jmsUser, java.lang.String jmsPassword, java.lang.String topicName)
          Create a receiver that will listen for all messages in the given Topic on the given JMS server.
Receiver(java.lang.String jmsUrl, java.lang.String jmsUser, java.lang.String jmsPassword, java.lang.String topicName, java.lang.String messageSelector)
          Create a receiver that will listen only to the messages in the given Topic that will pass the given messageSelector, on the given JMS server.
 
Method Summary
protected  SEMAINEMessage createSEMAINEMessage(Message message)
          Create a SEMAINE message from the given JMS message.
 SEMAINEMessage getMessage()
           
 SEMAINEMessageAvailableListener getMessageListener()
           
 java.lang.String getMessageSelector()
          Get the message selector pattern active in this receiver to filter messages.
static void main(java.lang.String[] args)
           
 boolean notPickedUp()
           
 void onMessage(Message m)
           
 SEMAINEMessage receive()
          Receives the next message produced for this message consumer.
 SEMAINEMessage receive(long timeout)
          Receives the next message that arrives within the specified timeout interval.
 SEMAINEMessage receiveNoWait()
          Receives the next message if one is immediately available.
 void setMessageListener(SEMAINEMessageAvailableListener aListener)
           
 
Methods inherited from class eu.semaine.jms.IOBase
createConnection, getConnection, getConnection, getConnectionStatus, getJMSPassword, getJMSUrl, getJMSUser, getSession, getTopic, getTopicName, isEmbeddedBroker, startConnection, useEmbeddedBroker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

consumer

protected MessageConsumer consumer

listener

protected SEMAINEMessageAvailableListener listener

log

protected JMSLogger log

message

protected SEMAINEMessage message
Constructor Detail

Receiver

public Receiver(java.lang.String topicName)
         throws JMSException
Create a receiver that will listen for all messages in the given Topic on the default JMS server. The default JMS server is determined as follows:

Parameters:
topic - the name of the JMS Topic to listen to.
Throws:
JMSException

Receiver

public Receiver(java.lang.String topicName,
                java.lang.String messageSelector)
         throws JMSException
Create a receiver that will listen only to the messages in the given Topic that will pass the given messageSelector, on the default JMS server. The default JMS server is determined as follows:

Parameters:
topicName - the name of the JMS Topic to listen to.
messageSelector - a message selector expression, see e.g. http://java.sun.com/javaee/5/docs/api/javax/jms/Message.html for the detailed description.
Throws:
JMSException

Receiver

public Receiver(java.lang.String jmsUrl,
                java.lang.String jmsUser,
                java.lang.String jmsPassword,
                java.lang.String topicName)
         throws JMSException
Create a receiver that will listen for all messages in the given Topic on the given JMS server.

Parameters:
jmsUrl - the url where to contact the JMS server
jmsUser - the username to use (can be null)
jmsPassword - the password to use (can be null)
topic - the name of the JMS Topic to listen to.
Throws:
JMSException

Receiver

public Receiver(java.lang.String jmsUrl,
                java.lang.String jmsUser,
                java.lang.String jmsPassword,
                java.lang.String topicName,
                java.lang.String messageSelector)
         throws JMSException
Create a receiver that will listen only to the messages in the given Topic that will pass the given messageSelector, on the given JMS server.

Parameters:
jmsUrl - the url where to contact the JMS server
jmsUser - the username to use (can be null)
jmsPassword - the password to use (can be null)
topicName - the name of the JMS Topic to listen to.
messageSelector - a message selector expression, see e.g. http://java.sun.com/javaee/5/docs/api/javax/jms/Message.html for the detailed description.
Throws:
JMSException
Method Detail

getMessageSelector

public java.lang.String getMessageSelector()
                                    throws JMSException
Get the message selector pattern active in this receiver to filter messages.

Returns:
a string representation of the selector pattern.
Throws:
JMSException

createSEMAINEMessage

protected SEMAINEMessage createSEMAINEMessage(Message message)
                                       throws MessageFormatException
Create a SEMAINE message from the given JMS message. Subclasses may want to override this in order to provide subclasses of SEMAINEMessage for their data.

Parameters:
message - the JMS method to convert into a SEMAINE message.
Throws:
MessageFormatException - if the message format is problematic
java.lang.NullPointerException - if message is null.

receive

public SEMAINEMessage receive()
                       throws JMSException
Receives the next message produced for this message consumer. This call blocks indefinitely until a message is produced or until this message consumer is closed.

Returns:
the next message produced for this message consumer, or null if this message consumer is concurrently closed
Throws:
JMSException - if the JMS provider fails to receive the next message due to some internal error.

receive

public SEMAINEMessage receive(long timeout)
                       throws JMSException
Receives the next message that arrives within the specified timeout interval. This call blocks until a message arrives, the timeout expires, or this message consumer is closed. A timeout of zero never expires, and the call blocks indefinitely.

Parameters:
timeout - the timeout value (in milliseconds)
Returns:
the next message produced for this message consumer, or null if the timeout expires or this message consumer is concurrently closed
Throws:
JMSException - if the JMS provider fails to receive the next message due to some internal error.

receiveNoWait

public SEMAINEMessage receiveNoWait()
                             throws JMSException
Receives the next message if one is immediately available.

Returns:
the next message produced for this message consumer, or null if one is not available
Throws:
JMSException - if the JMS provider fails to receive the next message due to some internal error.

setMessageListener

public void setMessageListener(SEMAINEMessageAvailableListener aListener)
                        throws JMSException
Throws:
JMSException

getMessageListener

public SEMAINEMessageAvailableListener getMessageListener()

onMessage

public void onMessage(Message m)

getMessage

public SEMAINEMessage getMessage()

notPickedUp

public boolean notPickedUp()

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception