eu.semaine.jms.sender
Class Sender

java.lang.Object
  extended by eu.semaine.jms.IOBase
      extended by eu.semaine.jms.sender.Sender
Direct Known Subclasses:
BytesSender, FeatureSender, XMLSender

public class Sender
extends IOBase

This class handles the common part to all message senders in the SEMAINE system.

Author:
marc

Nested Class Summary
 
Nested classes/interfaces inherited from class eu.semaine.jms.IOBase
IOBase.Event
 
Field Summary
protected  java.lang.String datatype
          The name of the data type being sent.
protected  int period
          If data is periodic, the period in which data is sent, in milliseconds.
protected  javax.jms.MessageProducer producer
           
protected  java.lang.String source
          The name of the source component from where the data originated.
 
Fields inherited from class eu.semaine.jms.IOBase
connection, isConnectionStarted, jmsPassword, jmsUrl, jmsUser, session, topic
 
Constructor Summary
Sender(java.lang.String topicName, java.lang.String datatype, java.lang.String source)
          Create a new Sender to the given topic on the default JMS server.
Sender(java.lang.String jmsUrl, java.lang.String jmsUser, java.lang.String jmsPassword, java.lang.String topicName, java.lang.String datatype, java.lang.String source)
          Create a new Sender to the given topic on the given JMS server.
 
Method Summary
protected  void fillMessageProperties(javax.jms.Message message, long usertime)
          Fill in the usual message properties as far as possible.
 java.lang.String getDatatype()
          The name of the data type sent.
 int getPeriod()
          For periodic senders, get the period of sending.
 java.lang.String getSource()
          The name of the source component sending the data.
 long getTimeToLive()
          Get the time to live for all messages sent by this sender, i.e. the number of milliseconds before the message is considered obsolete by the JMS system.
protected  void initialise(java.lang.String datatype, java.lang.String source)
           
 boolean isEventBased()
          Test whether this sender is set to send messages in an event-based way.
 boolean isPeriodic()
          Test whether this sender is set to send messages periodically.
static void main(java.lang.String[] args)
           
 void sendTextMessage(java.lang.String text, long usertime)
          Send a text message via this sender.
 void sendTextMessage(java.lang.String text, long usertime, IOBase.Event eventType)
          Send a text message via this sender, for event-based messages.
 void setEventBased()
          Determine that the data is event-based, not periodic.
 void setPeriodic(int aPeriod)
          Determine that the data is periodic, and set the period in which data is (intended to be) sent, in milliseconds.
 void setTimeToLive(long aTimeToLive)
          Set the time to live for all messages sent by this sender, i.e. the number of milliseconds before the message is considered obsolete by the JMS system.
 
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

producer

protected javax.jms.MessageProducer producer

datatype

protected java.lang.String datatype
The name of the data type being sent.


source

protected java.lang.String source
The name of the source component from where the data originated.


period

protected int period
If data is periodic, the period in which data is sent, in milliseconds. A value of 0 means not periodic. Data can be either periodic or event-based, but not both at the same time.

Constructor Detail

Sender

public Sender(java.lang.String topicName,
              java.lang.String datatype,
              java.lang.String source)
       throws javax.jms.JMSException
Create a new Sender to the given topic on the default JMS server. The default JMS server is determined as follows: Datatype and source will be sent with every message.

Parameters:
topic - the name of the topic to send to.
datatype - the name of the type of data being sent.
source - the name of the component sending the data.
Throws:
javax.jms.JMSException
java.lang.NullPointerException - if any of the parameters topicName, datatype, or source are null.

Sender

public Sender(java.lang.String jmsUrl,
              java.lang.String jmsUser,
              java.lang.String jmsPassword,
              java.lang.String topicName,
              java.lang.String datatype,
              java.lang.String source)
       throws javax.jms.JMSException
Create a new Sender to the given topic on the given JMS server. Datatype and source will be sent with every message.

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 topic to send to.
datatype - the name of the type of data being sent.
source - the name of the component sending the data.
Throws:
javax.jms.JMSException
java.lang.NullPointerException - if any of the parameters jmsUrl, topicName, datatype, or source are null.
Method Detail

initialise

protected void initialise(java.lang.String datatype,
                          java.lang.String source)
                   throws javax.jms.JMSException
Throws:
javax.jms.JMSException

getDatatype

public java.lang.String getDatatype()
The name of the data type sent.

Returns:
a non-null and non-empty string.

getSource

public java.lang.String getSource()
The name of the source component sending the data.

Returns:
a non-null and non-empty string.

setPeriodic

public void setPeriodic(int aPeriod)
Determine that the data is periodic, and set the period in which data is (intended to be) sent, in milliseconds.

Parameters:
aPeriod - the period in which data is to be sent.
Throws:
java.lang.IllegalArgumentException - if aPeriod is <= 0.

setEventBased

public void setEventBased()
Determine that the data is event-based, not periodic. Individual messages can transport different kinds of events,

See Also:
#sendTextMessage(String, long, eu.semaine.jms.IOBase.Event)}.

isPeriodic

public boolean isPeriodic()
Test whether this sender is set to send messages periodically.

Returns:
true if sender is set to periodic, false otherwise.

isEventBased

public boolean isEventBased()
Test whether this sender is set to send messages in an event-based way.

Returns:
true if sender is set to event-based, false otherwise.

getPeriod

public int getPeriod()
For periodic senders, get the period of sending.

Returns:
An integer representing the period of sending, in milliseconds.

setTimeToLive

public void setTimeToLive(long aTimeToLive)
                   throws javax.jms.JMSException
Set the time to live for all messages sent by this sender, i.e. the number of milliseconds before the message is considered obsolete by the JMS system. Messages that are not delivered by their expiration time are deleted by the JMS system.

Parameters:
aTimeToLive - time to live, in milliseconds. A value of 0 means unlimited time, i.e. the messages will not expire.
Throws:
javax.jms.JMSException

getTimeToLive

public long getTimeToLive()
                   throws javax.jms.JMSException
Get the time to live for all messages sent by this sender, i.e. the number of milliseconds before the message is considered obsolete by the JMS system. Messages that are not delivered by their expiration time are deleted by the JMS system.

Returns:
time to live, in milliseconds. A value of 0 means unlimited time, i.e. the messages will not expire.
Throws:
javax.jms.JMSException

sendTextMessage

public void sendTextMessage(java.lang.String text,
                            long usertime)
                     throws javax.jms.JMSException
Send a text message via this sender. This will send a message to the registered topic with the following message properties: Furthermore, if getTimeToLive() returns a non-zero value, the message will contain a header field JMSExpiration containing the time when the message will expire.

Parameters:
text - the message text.
usertime - the "user" time that this message refers to, in milliseconds since 1970.
Throws:
java.lang.IllegalStateException - if the connection is not started or the sender is in event-based mode.
javax.jms.JMSException

sendTextMessage

public void sendTextMessage(java.lang.String text,
                            long usertime,
                            IOBase.Event eventType)
                     throws javax.jms.JMSException
Send a text message via this sender, for event-based messages. This will send a message to the registered topic with the following message properties: Furthermore, if getTimeToLive() returns a non-zero value, the message will contain a header field JMSExpiration containing the time when the message will expire.

Parameters:
text - the message text.
usertime - the "user" time that this message refers to, in milliseconds since 1970.
event - the type of event represented by this message.
Throws:
java.lang.IllegalStateException - if the connection is not started or the sender is in periodic mode.
javax.jms.JMSException

fillMessageProperties

protected void fillMessageProperties(javax.jms.Message message,
                                     long usertime)
                              throws javax.jms.JMSException
Fill in the usual message properties as far as possible. Subclasses are encouraged to override this method, but should normally call this method as well (as super.fillMessageProperties(message, usertime)).

Parameters:
a - message object in preparation for sending.
usertime - the "user" time that this message refers to, in milliseconds since 1970.
Throws:
javax.jms.JMSException

main

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