org.apache.commons.messenger
Class SessionFactory

java.lang.Object
  extended byorg.apache.commons.messenger.SessionFactory
Direct Known Subclasses:
JNDISessionFactory

public class SessionFactory
extends java.lang.Object

SessionFactory is a Factory of JMS Session objects. It can be configured with a JMS Connection object to use or can use a JMS ConnectionFactory instance to create the JMS Connection lazily

Version:
$Revision: 1.17 $
Author:
James Strachan

Field Summary
private  int acknowlegeMode
          JMS acknowlege mode used on each session
private  java.lang.String clientID
          The client ID for the connection
private  javax.jms.Connection connection
          The JMS connection used to create JMS sessions
private  javax.jms.ConnectionFactory connectionFactory
          The JMS ConnectionFactory used to create JMS Connection instances
private static org.apache.commons.logging.Log log
          Logger
private  java.lang.String password
          the optional password used when creating a new JMS connection via a JMS ConnectionFactory
protected  java.util.Properties properties
          the properties used to create the connection
private  boolean topic
          Whether to use a Topic or Queue connection/session
private  boolean transacted
          whether JMS sessions should be transacted
private  java.lang.String username
          the optional username used when creating a new JMS connection via a JMS ConnectionFactory
 
Constructor Summary
SessionFactory()
           
 
Method Summary
 void addProperty(java.lang.String name, java.lang.String value)
           
 void close()
          Closes the JMS Connection that this object is using, if any
 javax.jms.Connection createConnection()
          Factory method used to create a connection
protected  javax.jms.ConnectionFactory createConnectionFactory()
          Factory method used to create a connection factory.
protected  java.util.Properties createProperties()
          Factory method used to create the initial JNDI context properties.
protected  javax.jms.QueueConnection createQueueConnection(javax.jms.QueueConnectionFactory queueConnectionFactory)
           
 javax.jms.ServerSessionPool createServerSessionPool(javax.jms.MessageListener messageListener, int maxThreads)
           
 javax.jms.Session createSession()
          Creates a new Session instance
 javax.jms.Session createSession(javax.jms.Connection connection)
          Creates a new Session instance
protected  javax.jms.TopicConnection createTopicConnection(javax.jms.TopicConnectionFactory topicConnectionFactory)
           
 int getAcknowledgeMode()
          Returns the JMS acknowledge mode used by the JMS sessions created by this session
 java.lang.String getClientID()
          Returns the clientID used on the current connection.
 javax.jms.Connection getConnection()
          Returns the JMS connection used to create new sessions
 javax.jms.ConnectionFactory getConnectionFactory()
          Returns the JMS ConnectionFactory used to create a new connection
 java.lang.String getPassword()
          Returns the optional password used when creating a new JMS connection via a JMS ConnectionFactory
 java.util.Properties getProperties()
          Returns the Properties that can be used to configure the connection creation
 java.lang.String getUsername()
          Returns the optional username used when creating a new JMS connection via a JMS ConnectionFactory
 boolean isTopic()
           
 boolean isTransacted()
          Returns true if sessions created by this factory should be transacted
 void setAcknowledge(java.lang.String value)
          A String based setter method to allow this property to be defined easily from within the digester XML file.
 void setAcknowledgeMode(int acknowlegeMode)
           
 void setClientID(java.lang.String clientID)
          Sets the clientID used on the current connection.
 void setConnection(javax.jms.Connection connection)
           
 void setConnectionFactory(javax.jms.ConnectionFactory connectionFactory)
           
 void setPassword(java.lang.String password)
           
 void setProperties(java.util.Properties properties)
           
 void setTopic(boolean topic)
          Sets whether to use a Topic or Queue connection/session
 void setTransacted(boolean transacted)
           
 void setUsername(java.lang.String username)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log
Logger


connection

private javax.jms.Connection connection
The JMS connection used to create JMS sessions


connectionFactory

private javax.jms.ConnectionFactory connectionFactory
The JMS ConnectionFactory used to create JMS Connection instances


acknowlegeMode

private int acknowlegeMode
JMS acknowlege mode used on each session


transacted

private boolean transacted
whether JMS sessions should be transacted


username

private java.lang.String username
the optional username used when creating a new JMS connection via a JMS ConnectionFactory


password

private java.lang.String password
the optional password used when creating a new JMS connection via a JMS ConnectionFactory


properties

protected java.util.Properties properties
the properties used to create the connection


topic

private boolean topic
Whether to use a Topic or Queue connection/session


clientID

private java.lang.String clientID
The client ID for the connection

Constructor Detail

SessionFactory

public SessionFactory()
Method Detail

createSession

public javax.jms.Session createSession(javax.jms.Connection connection)
                                throws javax.jms.JMSException
Creates a new Session instance

Throws:
javax.jms.JMSException

createSession

public javax.jms.Session createSession()
                                throws javax.jms.JMSException
Creates a new Session instance

Throws:
javax.jms.JMSException

createServerSessionPool

public javax.jms.ServerSessionPool createServerSessionPool(javax.jms.MessageListener messageListener,
                                                           int maxThreads)
                                                    throws javax.jms.JMSException
Throws:
javax.jms.JMSException

createConnection

public javax.jms.Connection createConnection()
                                      throws javax.jms.JMSException
Factory method used to create a connection

Throws:
javax.jms.JMSException

close

public void close()
           throws javax.jms.JMSException
Closes the JMS Connection that this object is using, if any

Throws:
javax.jms.JMSException

getConnection

public javax.jms.Connection getConnection()
                                   throws javax.jms.JMSException
Returns the JMS connection used to create new sessions

Throws:
javax.jms.JMSException

setConnection

public void setConnection(javax.jms.Connection connection)
                   throws javax.jms.JMSException
Throws:
javax.jms.JMSException

getConnectionFactory

public javax.jms.ConnectionFactory getConnectionFactory()
                                                 throws javax.jms.JMSException
Returns the JMS ConnectionFactory used to create a new connection

Throws:
javax.jms.JMSException

setConnectionFactory

public void setConnectionFactory(javax.jms.ConnectionFactory connectionFactory)

isTransacted

public boolean isTransacted()
Returns true if sessions created by this factory should be transacted


setTransacted

public void setTransacted(boolean transacted)

getAcknowledgeMode

public int getAcknowledgeMode()
Returns the JMS acknowledge mode used by the JMS sessions created by this session


setAcknowledgeMode

public void setAcknowledgeMode(int acknowlegeMode)

setAcknowledge

public void setAcknowledge(java.lang.String value)
A String based setter method to allow this property to be defined easily from within the digester XML file. * @param value is either "auto", "client" or "dups_ok"

Throws:
java.lang.IllegalArgumentException - if the value is not one of the correct values

getUsername

public java.lang.String getUsername()
Returns the optional username used when creating a new JMS connection via a JMS ConnectionFactory


setUsername

public void setUsername(java.lang.String username)

getPassword

public java.lang.String getPassword()
Returns the optional password used when creating a new JMS connection via a JMS ConnectionFactory


setPassword

public void setPassword(java.lang.String password)

getProperties

public java.util.Properties getProperties()
Returns the Properties that can be used to configure the connection creation


setProperties

public void setProperties(java.util.Properties properties)

addProperty

public void addProperty(java.lang.String name,
                        java.lang.String value)

isTopic

public boolean isTopic()
Returns:
whether to use a Topic or Queue connection/session

setTopic

public void setTopic(boolean topic)
Sets whether to use a Topic or Queue connection/session


getClientID

public java.lang.String getClientID()
Returns the clientID used on the current connection.

Returns:
String

setClientID

public void setClientID(java.lang.String clientID)
Sets the clientID used on the current connection.

Parameters:
clientID - The clientID to set

createQueueConnection

protected javax.jms.QueueConnection createQueueConnection(javax.jms.QueueConnectionFactory queueConnectionFactory)
                                                   throws javax.jms.JMSException
Throws:
javax.jms.JMSException

createTopicConnection

protected javax.jms.TopicConnection createTopicConnection(javax.jms.TopicConnectionFactory topicConnectionFactory)
                                                   throws javax.jms.JMSException
Throws:
javax.jms.JMSException

createConnectionFactory

protected javax.jms.ConnectionFactory createConnectionFactory()
                                                       throws javax.jms.JMSException
Factory method used to create a connection factory. Derived classes may wish to use JNDI to load the ConnectionFactory

Throws:
javax.jms.JMSException

createProperties

protected java.util.Properties createProperties()
Factory method used to create the initial JNDI context properties. Derived classes may wish to overload this method to provide different properties