org.codehaus.activemq
Class ActiveMQConnectionFactory

java.lang.Object
  extended byorg.codehaus.activemq.jndi.JNDIBaseStorable
      extended byorg.codehaus.activemq.ActiveMQConnectionFactory
All Implemented Interfaces:
ConnectionFactory, JNDIStorableInterface, QueueConnectionFactory, Referenceable, Service, StatsCapable, TopicConnectionFactory
Direct Known Subclasses:
ActiveMQXAConnectionFactory

public class ActiveMQConnectionFactory
extends JNDIBaseStorable
implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, Service, StatsCapable

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

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

Version:
$Revision: 1.37 $
See Also:
ConnectionFactory

Field Summary
protected  BrokerContainer brokerContainer
           
protected  String brokerName
           
protected  String brokerURL
           
protected  String clientID
           
protected  String password
           
protected  boolean useAsyncSend
          Should we use an async send for persistent non transacted messages ?
protected  String userName
           
 
Constructor Summary
ActiveMQConnectionFactory()
          Default Constructor for ActiveMQConnectionFactory
ActiveMQConnectionFactory(BrokerContainer container)
          Constructs a ConnectionFactory with an already configured and started BrokerContainer ready for use in embedded mode.
ActiveMQConnectionFactory(BrokerContainer container, String brokerURL)
          Constructs a ConnectionFactory with an already configured and started BrokerContainer ready for use in embedded mode and the brokerURL connection.
ActiveMQConnectionFactory(String brokerURL)
           
ActiveMQConnectionFactory(String userName, String password, String brokerURL)
           
 
Method Summary
protected  void buildFromProperties(Properties props)
          Set the properties that will represent the instance in JNDI
protected  BrokerConnector createBrokerConnector(String url)
           
protected  BrokerContainerFactory createBrokerContainerFactory()
           
 Connection createConnection()
          Create a JMS Connection
 Connection createConnection(String userName, String password)
           
protected  String createMulticastClientID()
          Creates the clientID for the multicast client (used to dispatch local messages over a multicast bus)
 QueueConnection createQueueConnection()
          Create a JMS QueueConnection
 QueueConnection createQueueConnection(String userName, String password)
           
 TopicConnection createTopicConnection()
          Create a JMS TopicConnection
 TopicConnection createTopicConnection(String userName, String password)
           
protected  TransportChannel createTransportChannel(String theURLString)
          Factory method to create a TransportChannel from a URL
protected  URI createURI(String uri)
           
protected  URI createURI(String protocol, URI uri)
           
protected  TransportChannel ensureMulticastChannelIsAvailable(URI remoteLocation, TransportChannel channel, BrokerConnector brokerConnector, boolean created)
           
protected  TransportChannel ensureServerIsAvailable(URI remoteLocation, TransportChannel channel, BrokerConnector brokerConnector, boolean created)
           
protected  boolean getBoolean(Properties props, String key)
          Helper method to return the property value as a boolean flag
protected  boolean getBoolean(Properties props, String key, boolean defaultValue)
          Helper method to return the property value as a boolean flag
 BrokerContainer getBrokerContainer()
           
 BrokerContainerFactory getBrokerContainerFactory()
           
 BrokerContext getBrokerContext()
          Returns the context used to store broker containers and connectors which defaults to using the singleton
 String getBrokerName()
          The name of the broker to use if creating an embedded broker
 String getBrokerURL()
           
 String getBrokerXmlConfig()
           
 String getClientID()
           
protected  BrokerContainer getContainer(String brokerName)
           
 Broker getEmbeddedBroker()
           
 JMSStatsImpl getFactoryStats()
           
 String getPassword()
           
 Stats getStats()
           
 String getUserName()
           
 WireFormat getWireFormat()
           
 boolean isUseAsyncSend()
           
 boolean isUseEmbeddedBroker()
          Is an embedded broker used by this connection factory
(package private)  void onConnectionClose(ActiveMQConnection connection)
          Called when a connection is closed so that we can shut down any embedded brokers cleanly
(package private)  void onConnectionCreate(ActiveMQConnection connection)
           
protected  void populateProperties(Properties props)
          Initialize the instance from properties stored in JNDI
static void registerBroker(String theURLString, BrokerConnector brokerConnector)
           
 void setBrokerContainerFactory(BrokerContainerFactory brokerContainerFactory)
           
 void setBrokerContext(BrokerContext brokerContext)
           
 void setBrokerName(String brokerName)
           
 void setBrokerURL(String brokerURL)
           
 void setBrokerXmlConfig(String brokerXmlConfig)
          Sets the XML configuration file used to configure the ActiveMQ broker via Spring if using embedded mode.
 void setClientID(String clientID)
           
 void setPassword(String password)
           
 void setUseAsyncSend(boolean useAsyncSend)
           
 void setUseEmbeddedBroker(boolean useEmbeddedBroker)
          Allows embedded brokers to be associated with a connection factory
 void setUserName(String userName)
           
 void setWireFormat(WireFormat wireFormat)
          Allows a custom wire format to be used; otherwise the default Java wire format is used which is designed for minimum size and maximum speed on the Java platform
 void start()
          Called to start the service
 void stop()
          A hook to allow any embedded JMS Broker's to be closed down
static void unregisterBroker(String theURLString)
           
 
Methods inherited from class org.codehaus.activemq.jndi.JNDIBaseStorable
getProperties, getReference, setProperties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

brokerContainer

protected BrokerContainer brokerContainer

userName

protected String userName

password

protected String password

brokerURL

protected String brokerURL

clientID

protected String clientID

brokerName

protected String brokerName

useAsyncSend

protected boolean useAsyncSend
Should we use an async send for persistent non transacted messages ?

Constructor Detail

ActiveMQConnectionFactory

public ActiveMQConnectionFactory()
Default Constructor for ActiveMQConnectionFactory


ActiveMQConnectionFactory

public ActiveMQConnectionFactory(String brokerURL)

ActiveMQConnectionFactory

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

ActiveMQConnectionFactory

public ActiveMQConnectionFactory(BrokerContainer container)
Constructs a ConnectionFactory with an already configured and started BrokerContainer ready for use in embedded mode.

Parameters:
container -

ActiveMQConnectionFactory

public ActiveMQConnectionFactory(BrokerContainer container,
                                 String brokerURL)
Constructs a ConnectionFactory with an already configured and started BrokerContainer ready for use in embedded mode and the brokerURL connection.

Parameters:
container -
Method Detail

getStats

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

getFactoryStats

public JMSStatsImpl getFactoryStats()

getBrokerURL

public String getBrokerURL()
Returns:
Returns the brokerURL.

setBrokerURL

public void setBrokerURL(String brokerURL)
Parameters:
brokerURL - The brokerURL to set.

getClientID

public String getClientID()
Returns:
Returns the clientID.

setClientID

public void setClientID(String clientID)
Parameters:
clientID - The clientID to set.

getPassword

public String getPassword()
Returns:
Returns the password.

setPassword

public void setPassword(String password)
Parameters:
password - The password to set.

getUserName

public String getUserName()
Returns:
Returns the userName.

setUserName

public void setUserName(String userName)
Parameters:
userName - The userName to set.

isUseEmbeddedBroker

public boolean isUseEmbeddedBroker()
Is an embedded broker used by this connection factory

Returns:
true if an embedded broker will be used by this connection factory

setUseEmbeddedBroker

public void setUseEmbeddedBroker(boolean useEmbeddedBroker)
Allows embedded brokers to be associated with a connection factory

Parameters:
useEmbeddedBroker -

getBrokerName

public String getBrokerName()
The name of the broker to use if creating an embedded broker

Returns:

setBrokerName

public void setBrokerName(String brokerName)

isUseAsyncSend

public boolean isUseAsyncSend()
Returns:
Returns the useAsyncSend.

setUseAsyncSend

public void setUseAsyncSend(boolean useAsyncSend)
Parameters:
useAsyncSend - The useAsyncSend to set.

getWireFormat

public WireFormat getWireFormat()

setWireFormat

public void setWireFormat(WireFormat wireFormat)
Allows a custom wire format to be used; otherwise the default Java wire format is used which is designed for minimum size and maximum speed on the Java platform

Parameters:
wireFormat -

getBrokerXmlConfig

public String getBrokerXmlConfig()

getBrokerContainer

public BrokerContainer getBrokerContainer()

setBrokerXmlConfig

public void setBrokerXmlConfig(String brokerXmlConfig)
Sets the XML configuration file used to configure the ActiveMQ broker via Spring if using embedded mode.

Parameters:
brokerXmlConfig - is the filename which is assumed to be on the classpath unless a URL is specified. So a value of foo/bar.xml would be assumed to be on the classpath whereas file:dir/file.xml would use the file system. Any valid URL string is supported.
See Also:
setUseEmbeddedBroker(boolean)

getBrokerContainerFactory

public BrokerContainerFactory getBrokerContainerFactory()
                                                 throws JMSException
Throws:
JMSException

setBrokerContainerFactory

public void setBrokerContainerFactory(BrokerContainerFactory brokerContainerFactory)

getBrokerContext

public BrokerContext getBrokerContext()
Returns the context used to store broker containers and connectors which defaults to using the singleton


setBrokerContext

public void setBrokerContext(BrokerContext brokerContext)

createConnection

public Connection createConnection()
                            throws JMSException
Create a JMS Connection

Specified by:
createConnection in interface ConnectionFactory
Returns:
the JMS Connection
Throws:
JMSException - if an error occurs creating the Connection

createConnection

public Connection createConnection(String userName,
                                   String password)
                            throws JMSException
Specified by:
createConnection in interface ConnectionFactory
Parameters:
userName -
password -
Returns:
the Connection
Throws:
JMSException - if an error occurs creating the Connection

createQueueConnection

public QueueConnection createQueueConnection()
                                      throws JMSException
Create a JMS QueueConnection

Specified by:
createQueueConnection in interface QueueConnectionFactory
Returns:
the JMS QueueConnection
Throws:
JMSException - if an error occurs creating the Connection

createQueueConnection

public QueueConnection createQueueConnection(String userName,
                                             String password)
                                      throws JMSException
Specified by:
createQueueConnection in interface QueueConnectionFactory
Parameters:
userName -
password -
Returns:
the QueueConnection
Throws:
JMSException - if an error occurs creating the Connection

createTopicConnection

public TopicConnection createTopicConnection()
                                      throws JMSException
Create a JMS TopicConnection

Specified by:
createTopicConnection in interface TopicConnectionFactory
Returns:
the JMS TopicConnection
Throws:
JMSException - if an error occurs creating the Connection

createTopicConnection

public TopicConnection createTopicConnection(String userName,
                                             String password)
                                      throws JMSException
Specified by:
createTopicConnection in interface TopicConnectionFactory
Parameters:
userName -
password -
Returns:
the TopicConnection
Throws:
JMSException - if an error occurs creating the Connection

start

public void start()
           throws JMSException
Description copied from interface: Service
Called to start the service

Specified by:
start in interface Service
Throws:
JMSException

stop

public void stop()
          throws JMSException
A hook to allow any embedded JMS Broker's to be closed down

Specified by:
stop in interface Service
Throws:
JMSException

getEmbeddedBroker

public Broker getEmbeddedBroker()
                         throws JMSException
Throws:
JMSException

registerBroker

public static void registerBroker(String theURLString,
                                  BrokerConnector brokerConnector)

unregisterBroker

public static void unregisterBroker(String theURLString)

buildFromProperties

protected void buildFromProperties(Properties props)
Set the properties that will represent the instance in JNDI

Specified by:
buildFromProperties in class JNDIBaseStorable
Parameters:
props -

populateProperties

protected void populateProperties(Properties props)
Initialize the instance from properties stored in JNDI

Specified by:
populateProperties in class JNDIBaseStorable
Parameters:
props -

getBoolean

protected boolean getBoolean(Properties props,
                             String key)
Helper method to return the property value as a boolean flag

Parameters:
props -
key -
Returns:

getBoolean

protected boolean getBoolean(Properties props,
                             String key,
                             boolean defaultValue)
Helper method to return the property value as a boolean flag

Parameters:
props -
key -
defaultValue -
Returns:

createBrokerContainerFactory

protected BrokerContainerFactory createBrokerContainerFactory()
                                                       throws JMSException
Throws:
JMSException

createTransportChannel

protected TransportChannel createTransportChannel(String theURLString)
                                           throws JMSException
Factory method to create a TransportChannel from a URL

Throws:
JMSException

getContainer

protected BrokerContainer getContainer(String brokerName)
                                throws JMSException
Throws:
JMSException

createBrokerConnector

protected BrokerConnector createBrokerConnector(String url)
                                         throws JMSException
Throws:
JMSException

ensureServerIsAvailable

protected TransportChannel ensureServerIsAvailable(URI remoteLocation,
                                                   TransportChannel channel,
                                                   BrokerConnector brokerConnector,
                                                   boolean created)
                                            throws JMSException
Throws:
JMSException

ensureMulticastChannelIsAvailable

protected TransportChannel ensureMulticastChannelIsAvailable(URI remoteLocation,
                                                             TransportChannel channel,
                                                             BrokerConnector brokerConnector,
                                                             boolean created)
                                                      throws JMSException
Throws:
JMSException

createMulticastClientID

protected String createMulticastClientID()
Creates the clientID for the multicast client (used to dispatch local messages over a multicast bus)


createURI

protected URI createURI(String protocol,
                        URI uri)
                 throws JMSException
Throws:
JMSException

createURI

protected URI createURI(String uri)
                 throws JMSException
Throws:
JMSException

onConnectionClose

void onConnectionClose(ActiveMQConnection connection)
                 throws JMSException
Called when a connection is closed so that we can shut down any embedded brokers cleanly

Parameters:
connection -
Throws:
JMSException

onConnectionCreate

void onConnectionCreate(ActiveMQConnection connection)


Copyright © 2004 Protique, Ltd.. All Rights Reserved.