eu.semaine.jms.receiver
Class Receiver

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

public class Receiver
extends IOBase
implements javax.jms.MessageListener

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.Event
 
Field Summary
protected  javax.jms.MessageConsumer consumer
           
protected  SEMAINEMessageAvailableListener listener
           
protected  JMSLogger log
           
protected  SEMAINEMessage message
           
 
Fields inherited from class eu.semaine.jms.IOBase
connection, isConnectionStarted, jmsPassword, jmsUrl, jmsUser, session, topic
 
Constructor Summary
Receiver(java.lang.String topicName)
          Create a receiver that will listen for all messages in the given Topic.
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.
 
Method Summary
protected  SEMAINEMessage createSEMAINEMessage(javax.jms.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(javax.jms.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
getConnection, getJMSUrl, getSession, getTopic, getTopicName, startConnection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

consumer

protected javax.jms.MessageConsumer consumer

listener

protected SEMAINEMessageAvailableListener listener

log

protected JMSLogger log

message

protected SEMAINEMessage message
Constructor Detail

Receiver

public Receiver(java.lang.String topicName)
         throws javax.jms.JMSException
Create a receiver that will listen for all messages in the given Topic.

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

Receiver

public Receiver(java.lang.String topicName,
                java.lang.String messageSelector)
         throws javax.jms.JMSException
Create a receiver that will listen only to the messages in the given Topic that will pass the given messageSelector.

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:
javax.jms.JMSException
Method Detail

getMessageSelector

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

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

createSEMAINEMessage

protected SEMAINEMessage createSEMAINEMessage(javax.jms.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 javax.jms.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:
javax.jms.JMSException - if the JMS provider fails to receive the next message due to some internal error.

receive

public SEMAINEMessage receive(long timeout)
                       throws javax.jms.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:
javax.jms.JMSException - if the JMS provider fails to receive the next message due to some internal error.

receiveNoWait

public SEMAINEMessage receiveNoWait()
                             throws javax.jms.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:
javax.jms.JMSException - if the JMS provider fails to receive the next message due to some internal error.

setMessageListener

public void setMessageListener(SEMAINEMessageAvailableListener aListener)
                        throws javax.jms.JMSException
Throws:
javax.jms.JMSException

getMessageListener

public SEMAINEMessageAvailableListener getMessageListener()

onMessage

public void onMessage(javax.jms.Message m)
Specified by:
onMessage in interface javax.jms.MessageListener

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