eu.semaine.jms
Class IOBase

java.lang.Object
  extended by eu.semaine.jms.IOBase
Direct Known Subclasses:
MetaMessenger, Receiver, Sender

public class IOBase
extends java.lang.Object

This class handles the low-level interaction with the JMS provider for the components of the SEMAINE system.

Author:
marc

Nested Class Summary
static class IOBase.ConnectionStatus
           
static class IOBase.Event
           
 
Field Summary
protected  Connection connection
           
protected  JMSException exception
           
protected  boolean isConnectionStarted
           
protected  java.lang.String jmsPassword
           
protected  java.lang.String jmsUrl
           
protected  java.lang.String jmsUser
           
protected  Session session
           
protected  Topic topic
           
protected  java.lang.String topicName
           
 
Constructor Summary
IOBase(java.lang.String topicName)
          Create a new JMS IOBase connection with the given topic on the default JMS server.
IOBase(java.lang.String jmsUrl, java.lang.String jmsUser, java.lang.String jmsPassword, java.lang.String topicName)
          Create a new JMS IOBase connection with the given topic on the given JMS server.
 
Method Summary
protected static Connection createConnection(java.lang.String serverUrl, java.lang.String serverUser, java.lang.String serverPassword)
          Create a new Connection to a JMS server.
 Connection getConnection()
           
static Connection getConnection(java.lang.String serverUrl, java.lang.String serverUser, java.lang.String serverPassword, IOBase iobase)
          Get a Connection to a JMS server.
static IOBase.ConnectionStatus getConnectionStatus(Connection c)
          Try to determine the status of the connection.
 java.lang.String getJMSPassword()
          Get the password used when connecting to the JMS server.
 java.lang.String getJMSUrl()
          Get the URL of the JMS server connected to.
 java.lang.String getJMSUser()
          Get the user name used when connecting to the JMS server.
 Session getSession()
           
 Topic getTopic()
           
 java.lang.String getTopicName()
          Get the name of the topic.
static boolean isEmbeddedBroker()
           
 void startConnection()
           
static void useEmbeddedBroker()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jmsUrl

protected java.lang.String jmsUrl

jmsUser

protected java.lang.String jmsUser

jmsPassword

protected java.lang.String jmsPassword

connection

protected Connection connection

session

protected Session session

topic

protected Topic topic

topicName

protected java.lang.String topicName

isConnectionStarted

protected boolean isConnectionStarted

exception

protected JMSException exception
Constructor Detail

IOBase

public IOBase(java.lang.String topicName)
       throws JMSException
Create a new JMS IOBase connection with the given topic on the default JMS server. The default JMS server is determined as follows:

Parameters:
topicName - the name of the topic to send to.
Throws:
JMSException
java.lang.NullPointerException - if any of the parameters jmsUrl or topicName are null.

IOBase

public IOBase(java.lang.String jmsUrl,
              java.lang.String jmsUser,
              java.lang.String jmsPassword,
              java.lang.String topicName)
       throws JMSException
Create a new JMS IOBase connection with 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)
topicName - the name of the topic to send to.
Throws:
JMSException
java.lang.NullPointerException - if any of the parameters jmsUrl or topicName are null.
Method Detail

useEmbeddedBroker

public static void useEmbeddedBroker()
                              throws java.lang.Exception
Throws:
java.lang.Exception

isEmbeddedBroker

public static boolean isEmbeddedBroker()

getConnection

public static Connection getConnection(java.lang.String serverUrl,
                                       java.lang.String serverUser,
                                       java.lang.String serverPassword,
                                       IOBase iobase)
                                throws JMSException
Get a Connection to a JMS server. This will reuse an existing connection if possible, and only create a new Connection if no connection to the given server coordinates exists yet. If this process is using an embedded broker, this will use a local VM connection, ignoring the connection info given as parameters.

Parameters:
serverUrl - the server url, e.g. "tcp://localhost:61616"
serverUser - the user name, or null
serverPassword - the password, or null
iobase - an iobase object that wants to be notified if an exception occurs, or null.
Returns:
a valid connection object. It is undetermined whether the connection is already started.
Throws:
JMSException - if the connection cannot be created for some reason.

createConnection

protected static Connection createConnection(java.lang.String serverUrl,
                                             java.lang.String serverUser,
                                             java.lang.String serverPassword)
                                      throws JMSException
Create a new Connection to a JMS server. This should not normally be called from user code, since a Connection is a resource-intensive / heavyweight object. If this process is using an embedded broker, this will create a local VM connection, ignoring the connection info given as parameters. Use #getConnection(String, String, String) instead to re-use an existing connection if possible.

Parameters:
serverUrl - the server url, e.g. "tcp://localhost:61616"
serverUser - the user name, or null
serverPassword - the password, or null
Returns:
a valid connection object which is not yet started.
Throws:
JMSException - if the connection cannot be created for some reason.

getConnectionStatus

public static IOBase.ConnectionStatus getConnectionStatus(Connection c)
Try to determine the status of the connection.

Parameters:
c - a connection.
Returns:
one of the following ConnectionStatus values:
  • unknown if we cannot determine the status;
  • started if the connection has been started and not stopped or closed;
  • closed if the connection is closing or has been closed;
  • stopped if the connection has not yet been started or has been stopped.

getTopicName

public java.lang.String getTopicName()
Get the name of the topic.

Returns:
a string containing the topic name.
Throws:
JMSException

getJMSUrl

public java.lang.String getJMSUrl()
Get the URL of the JMS server connected to.

Returns:
a string containing the url

getJMSUser

public java.lang.String getJMSUser()
Get the user name used when connecting to the JMS server.

Returns:
the user name as a string, or null if no user name was given.

getJMSPassword

public java.lang.String getJMSPassword()
Get the password used when connecting to the JMS server.

Returns:
the password as a string, or null if no password was given.

getConnection

public Connection getConnection()

getSession

public Session getSession()

getTopic

public Topic getTopic()

startConnection

public void startConnection()
                     throws JMSException
Throws:
JMSException