org.apache.activemq
Class ActiveMQConnectionFactory

java.lang.Object
  extended by org.apache.activemq.jndi.JNDIBaseStorable
      extended by org.apache.activemq.ActiveMQConnectionFactory
All Implemented Interfaces:
Externalizable, Serializable, Cloneable, javax.jms.ConnectionFactory, javax.jms.QueueConnectionFactory, javax.jms.TopicConnectionFactory, Referenceable, JNDIStorableInterface, StatsCapable
Direct Known Subclasses:
ActiveMQConnectionFactory, ActiveMQSslConnectionFactory, ActiveMQXAConnectionFactory

public class ActiveMQConnectionFactory
extends JNDIBaseStorable
implements javax.jms.ConnectionFactory, javax.jms.QueueConnectionFactory, javax.jms.TopicConnectionFactory, StatsCapable, Cloneable

A ConnectionFactory is an an Administered object, and is used for creating Connections.

This class also implements QueueConnectionFactory and TopicConnectionFactory. You can use this connection to create both QueueConnections and TopicConnections.

Version:
$Revision: 1.9 $
See Also:
ConnectionFactory, Serialized Form

Field Summary
protected  boolean alwaysSessionAsync
           
protected  URI brokerURL
           
protected  String clientID
           
static String DEFAULT_BROKER_URL
           
protected static edu.emory.mathcs.backport.java.util.concurrent.Executor DEFAULT_CONNECTION_EXECUTOR
           
static String DEFAULT_PASSWORD
           
static String DEFAULT_USER
           
protected  boolean dispatchAsync
           
protected  String password
           
protected  String userName
           
 
Constructor Summary
ActiveMQConnectionFactory()
           
ActiveMQConnectionFactory(String brokerURL)
           
ActiveMQConnectionFactory(String userName, String password, String brokerURL)
           
ActiveMQConnectionFactory(String userName, String password, URI brokerURL)
           
ActiveMQConnectionFactory(URI brokerURL)
           
 
Method Summary
 boolean buildFromMap(Map properties)
           
 void buildFromProperties(Properties properties)
          Set the properties that will represent the instance in JNDI
 ActiveMQConnectionFactory copy()
          Returns a copy of the given connection factory
protected  ActiveMQConnection createActiveMQConnection()
           
protected  ActiveMQConnection createActiveMQConnection(String userName, String password)
           
protected  ActiveMQConnection createActiveMQConnection(Transport transport, JMSStatsImpl stats)
           
 javax.jms.Connection createConnection()
           
 javax.jms.Connection createConnection(String userName, String password)
           
 javax.jms.QueueConnection createQueueConnection()
           
 javax.jms.QueueConnection createQueueConnection(String userName, String password)
           
 javax.jms.TopicConnection createTopicConnection()
           
 javax.jms.TopicConnection createTopicConnection(String userName, String password)
           
protected  Transport createTransport()
          Creates a Transport based on this object's connection settings.
 String getBrokerURL()
           
 String getClientID()
           
protected  IdGenerator getClientIdGenerator()
           
 String getClientIDPrefix()
           
 int getCloseTimeout()
           
 String getPassword()
           
 ActiveMQPrefetchPolicy getPrefetchPolicy()
           
 RedeliveryPolicy getRedeliveryPolicy()
           
 StatsImpl getStats()
           
 String getUserName()
           
 boolean isAlwaysSessionAsync()
           
 boolean isCopyMessageOnSend()
           
 boolean isDisableTimeStampsByDefault()
           
 boolean isDispatchAsync()
           
 boolean isNestedMapAndListEnabled()
           
 boolean isObjectMessageSerializationDefered()
           
 boolean isOptimizeAcknowledge()
           
 boolean isOptimizedMessageDispatch()
           
 boolean isStatsEnabled()
           
 boolean isUseAsyncSend()
           
 boolean isUseCompression()
           
 boolean isUseRetroactiveConsumer()
           
 boolean isUseSyncSend()
           
 boolean isWatchTopicAdvisories()
           
 void populateProperties(Properties props)
          Initialize the instance from properties stored in JNDI
 void setAlwaysSessionAsync(boolean alwaysSessionAsync)
          If this flag is set then a separate thread is not used for dispatching messages for each Session in the Connection.
 void setBrokerURL(String brokerURL)
          Sets the connection URL used to connect to the ActiveMQ broker.
 void setClientID(String clientID)
          Sets the JMS clientID to use for the created connection.
protected  void setClientIdGenerator(IdGenerator clientIdGenerator)
           
 void setClientIDPrefix(String clientIDPrefix)
          Sets the prefix used by autogenerated JMS Client ID values which are used if the JMS client does not explicitly specify on.
 void setCloseTimeout(int closeTimeout)
          Sets the timeout before a close is considered complete.
 void setCopyMessageOnSend(boolean copyMessageOnSend)
          Should a JMS message be copied to a new JMS Message object as part of the send() method in JMS.
 void setDisableTimeStampsByDefault(boolean disableTimeStampsByDefault)
          Sets whether or not timestamps on messages should be disabled or not.
 void setDispatchAsync(boolean asyncDispatch)
          Enables or disables the default setting of whether or not consumers have their messages dispatched synchronously or asynchronously by the broker.
 void setNestedMapAndListEnabled(boolean structuredMapsEnabled)
          Enables/disables whether or not Message properties and MapMessage entries support Nested Structures of Map and List objects
 void setObjectMessageSerializationDefered(boolean objectMessageSerializationDefered)
          When an object is set on an ObjectMessage, the JMS spec requires the object to be serialized by that set method.
 void setOptimizeAcknowledge(boolean optimizeAcknowledge)
           
 void setOptimizedMessageDispatch(boolean optimizedMessageDispatch)
          If this flag is set then an larger prefetch limit is used - only applicable for durable topic subscribers.
 void setPassword(String password)
          Sets the JMS password used for connections created from this factory
 void setPrefetchPolicy(ActiveMQPrefetchPolicy prefetchPolicy)
          Sets the prefetch policy for consumers created by this connection.
 void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy)
          Sets the global redelivery policy to be used when a message is delivered but the session is rolled back
 void setStatsEnabled(boolean statsEnabled)
           
 void setUseAsyncSend(boolean useAsyncSend)
          Forces the use of Async Sends which adds a massive performance boost; but means that the send() method will return immediately whether the message has been sent or not which could lead to message loss.
 void setUseCompression(boolean useCompression)
          Enables the use of compression of the message bodies
 void setUseRetroactiveConsumer(boolean useRetroactiveConsumer)
          Sets whether or not retroactive consumers are enabled.
 void setUserName(String userName)
          Sets the JMS userName used by connections created by this factory
 void setUseSyncSend(boolean forceSyncSend)
           
 void setWatchTopicAdvisories(boolean watchTopicAdvisories)
           
 
Methods inherited from class org.apache.activemq.jndi.JNDIBaseStorable
getProperties, getReference, readExternal, setProperties, writeExternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BROKER_URL

public static final String DEFAULT_BROKER_URL
See Also:
Constant Field Values

DEFAULT_USER

public static final String DEFAULT_USER

DEFAULT_PASSWORD

public static final String DEFAULT_PASSWORD

brokerURL

protected URI brokerURL

userName

protected String userName

password

protected String password

clientID

protected String clientID

dispatchAsync

protected boolean dispatchAsync

alwaysSessionAsync

protected boolean alwaysSessionAsync

DEFAULT_CONNECTION_EXECUTOR

protected static final edu.emory.mathcs.backport.java.util.concurrent.Executor DEFAULT_CONNECTION_EXECUTOR
Constructor Detail

ActiveMQConnectionFactory

public ActiveMQConnectionFactory()

ActiveMQConnectionFactory

public ActiveMQConnectionFactory(String brokerURL)

ActiveMQConnectionFactory

public ActiveMQConnectionFactory(URI brokerURL)

ActiveMQConnectionFactory

public ActiveMQConnectionFactory(String userName,
                                 String password,
                                 URI brokerURL)

ActiveMQConnectionFactory

public ActiveMQConnectionFactory(String userName,
                                 String password,
                                 String brokerURL)
Method Detail

copy

public ActiveMQConnectionFactory copy()
Returns a copy of the given connection factory


createConnection

public javax.jms.Connection createConnection()
                                      throws javax.jms.JMSException
Specified by:
createConnection in interface javax.jms.ConnectionFactory
Returns:
Returns the Connection.
Throws:
javax.jms.JMSException

createConnection

public javax.jms.Connection createConnection(String userName,
                                             String password)
                                      throws javax.jms.JMSException
Specified by:
createConnection in interface javax.jms.ConnectionFactory
Returns:
Returns the Connection.
Throws:
javax.jms.JMSException

createQueueConnection

public javax.jms.QueueConnection createQueueConnection()
                                                throws javax.jms.JMSException
Specified by:
createQueueConnection in interface javax.jms.QueueConnectionFactory
Returns:
Returns the QueueConnection.
Throws:
javax.jms.JMSException

createQueueConnection

public javax.jms.QueueConnection createQueueConnection(String userName,
                                                       String password)
                                                throws javax.jms.JMSException
Specified by:
createQueueConnection in interface javax.jms.QueueConnectionFactory
Returns:
Returns the QueueConnection.
Throws:
javax.jms.JMSException

createTopicConnection

public javax.jms.TopicConnection createTopicConnection()
                                                throws javax.jms.JMSException
Specified by:
createTopicConnection in interface javax.jms.TopicConnectionFactory
Returns:
Returns the TopicConnection.
Throws:
javax.jms.JMSException

createTopicConnection

public javax.jms.TopicConnection createTopicConnection(String userName,
                                                       String password)
                                                throws javax.jms.JMSException
Specified by:
createTopicConnection in interface javax.jms.TopicConnectionFactory
Returns:
Returns the TopicConnection.
Throws:
javax.jms.JMSException

getStats

public StatsImpl getStats()
Specified by:
getStats in interface StatsCapable
Returns:
the Stats for this object

createActiveMQConnection

protected ActiveMQConnection createActiveMQConnection()
                                               throws javax.jms.JMSException
Throws:
javax.jms.JMSException

createTransport

protected Transport createTransport()
                             throws javax.jms.JMSException
Creates a Transport based on this object's connection settings. Separated from createActiveMQConnection to allow for subclasses to override.

Returns:
The newly created Transport.
Throws:
javax.jms.JMSException - If unable to create trasnport.

createActiveMQConnection

protected ActiveMQConnection createActiveMQConnection(String userName,
                                                      String password)
                                               throws javax.jms.JMSException
Returns:
Returns the Connection.
Throws:
javax.jms.JMSException

createActiveMQConnection

protected ActiveMQConnection createActiveMQConnection(Transport transport,
                                                      JMSStatsImpl stats)
                                               throws Exception
Throws:
Exception

getBrokerURL

public String getBrokerURL()

setBrokerURL

public void setBrokerURL(String brokerURL)
Sets the connection URL used to connect to the ActiveMQ broker.


getClientID

public String getClientID()

setClientID

public void setClientID(String clientID)
Sets the JMS clientID to use for the created connection. Note that this can only be used by one connection at once so generally its a better idea to set the clientID on a Connection


isCopyMessageOnSend

public boolean isCopyMessageOnSend()

setCopyMessageOnSend

public void setCopyMessageOnSend(boolean copyMessageOnSend)
Should a JMS message be copied to a new JMS Message object as part of the send() method in JMS. This is enabled by default to be compliant with the JMS specification. You can disable it if you do not mutate JMS messages after they are sent for a performance boost


isDisableTimeStampsByDefault

public boolean isDisableTimeStampsByDefault()

setDisableTimeStampsByDefault

public void setDisableTimeStampsByDefault(boolean disableTimeStampsByDefault)
Sets whether or not timestamps on messages should be disabled or not. If you disable them it adds a small performance boost.


isOptimizedMessageDispatch

public boolean isOptimizedMessageDispatch()

setOptimizedMessageDispatch

public void setOptimizedMessageDispatch(boolean optimizedMessageDispatch)
If this flag is set then an larger prefetch limit is used - only applicable for durable topic subscribers.


getPassword

public String getPassword()

setPassword

public void setPassword(String password)
Sets the JMS password used for connections created from this factory


getPrefetchPolicy

public ActiveMQPrefetchPolicy getPrefetchPolicy()

setPrefetchPolicy

public void setPrefetchPolicy(ActiveMQPrefetchPolicy prefetchPolicy)
Sets the prefetch policy for consumers created by this connection.


isUseAsyncSend

public boolean isUseAsyncSend()

setUseAsyncSend

public void setUseAsyncSend(boolean useAsyncSend)
Forces the use of Async Sends which adds a massive performance boost; but means that the send() method will return immediately whether the message has been sent or not which could lead to message loss.


getUserName

public String getUserName()

setUserName

public void setUserName(String userName)
Sets the JMS userName used by connections created by this factory


isUseRetroactiveConsumer

public boolean isUseRetroactiveConsumer()

setUseRetroactiveConsumer

public void setUseRetroactiveConsumer(boolean useRetroactiveConsumer)
Sets whether or not retroactive consumers are enabled. Retroactive consumers allow non-durable topic subscribers to receive old messages that were published before the non-durable subscriber started.


getRedeliveryPolicy

public RedeliveryPolicy getRedeliveryPolicy()

setRedeliveryPolicy

public void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy)
Sets the global redelivery policy to be used when a message is delivered but the session is rolled back


buildFromProperties

public void buildFromProperties(Properties properties)
Description copied from class: JNDIBaseStorable
Set the properties that will represent the instance in JNDI

Specified by:
buildFromProperties in class JNDIBaseStorable

buildFromMap

public boolean buildFromMap(Map properties)

populateProperties

public void populateProperties(Properties props)
Description copied from class: JNDIBaseStorable
Initialize the instance from properties stored in JNDI

Specified by:
populateProperties in class JNDIBaseStorable

isUseCompression

public boolean isUseCompression()

setUseCompression

public void setUseCompression(boolean useCompression)
Enables the use of compression of the message bodies


isObjectMessageSerializationDefered

public boolean isObjectMessageSerializationDefered()

setObjectMessageSerializationDefered

public void setObjectMessageSerializationDefered(boolean objectMessageSerializationDefered)
When an object is set on an ObjectMessage, the JMS spec requires the object to be serialized by that set method. Enabling this flag causes the object to not get serialized. The object may subsequently get serialized if the message needs to be sent over a socket or stored to disk.


isDispatchAsync

public boolean isDispatchAsync()

setDispatchAsync

public void setDispatchAsync(boolean asyncDispatch)
Enables or disables the default setting of whether or not consumers have their messages dispatched synchronously or asynchronously by the broker. For non-durable topics for example we typically dispatch synchronously by default to minimize context switches which boost performance. However sometimes its better to go slower to ensure that a single blocked consumer socket does not block delivery to other consumers.

Parameters:
asyncDispatch - If true then consumers created on this connection will default to having their messages dispatched asynchronously. The default value is false.

getCloseTimeout

public int getCloseTimeout()
Returns:
Returns the closeTimeout.

setCloseTimeout

public void setCloseTimeout(int closeTimeout)
Sets the timeout before a close is considered complete. Normally a close() on a connection waits for confirmation from the broker; this allows that operation to timeout to save the client hanging if there is no broker


isAlwaysSessionAsync

public boolean isAlwaysSessionAsync()
Returns:
Returns the alwaysSessionAsync.

setAlwaysSessionAsync

public void setAlwaysSessionAsync(boolean alwaysSessionAsync)
If this flag is set then a separate thread is not used for dispatching messages for each Session in the Connection. However, a separate thread is always used if there is more than one session, or the session isn't in auto acknowledge or duplicates ok mode


isOptimizeAcknowledge

public boolean isOptimizeAcknowledge()
Returns:
Returns the optimizeAcknowledge.

setOptimizeAcknowledge

public void setOptimizeAcknowledge(boolean optimizeAcknowledge)
Parameters:
optimizeAcknowledge - The optimizeAcknowledge to set.

isNestedMapAndListEnabled

public boolean isNestedMapAndListEnabled()

setNestedMapAndListEnabled

public void setNestedMapAndListEnabled(boolean structuredMapsEnabled)
Enables/disables whether or not Message properties and MapMessage entries support Nested Structures of Map and List objects


getClientIDPrefix

public String getClientIDPrefix()

setClientIDPrefix

public void setClientIDPrefix(String clientIDPrefix)
Sets the prefix used by autogenerated JMS Client ID values which are used if the JMS client does not explicitly specify on.

Parameters:
clientIDPrefix -

getClientIdGenerator

protected IdGenerator getClientIdGenerator()

setClientIdGenerator

protected void setClientIdGenerator(IdGenerator clientIdGenerator)

isStatsEnabled

public boolean isStatsEnabled()
Returns:
the statsEnabled

setStatsEnabled

public void setStatsEnabled(boolean statsEnabled)
Parameters:
statsEnabled - the statsEnabled to set

isUseSyncSend

public boolean isUseSyncSend()

setUseSyncSend

public void setUseSyncSend(boolean forceSyncSend)

isWatchTopicAdvisories

public boolean isWatchTopicAdvisories()

setWatchTopicAdvisories

public void setWatchTopicAdvisories(boolean watchTopicAdvisories)


Copyright © 2011 Apache Software Foundation. All Rights Reserved.