org.apache.activemq
Class ActiveMQConnection

java.lang.Object
  extended by org.apache.activemq.ActiveMQConnection
All Implemented Interfaces:
javax.jms.Connection, javax.jms.QueueConnection, javax.jms.TopicConnection, Closeable, StatsCapable, StreamConnection, TransportListener
Direct Known Subclasses:
ActiveMQXAConnection

public class ActiveMQConnection
extends Object
implements javax.jms.Connection, javax.jms.TopicConnection, javax.jms.QueueConnection, StatsCapable, Closeable, StreamConnection, TransportListener


Field Summary
protected  boolean alwaysSessionAsync
           
static String DEFAULT_BROKER_URL
           
static String DEFAULT_PASSWORD
           
static String DEFAULT_USER
           
protected  boolean dispatchAsync
           
 
Constructor Summary
protected ActiveMQConnection(Transport transport, IdGenerator clientIdGenerator, JMSStatsImpl factoryStats)
          Construct an ActiveMQConnection
 
Method Summary
protected  void addConnectionConsumer(ActiveMQConnectionConsumer connectionConsumer)
          Add a ConnectionConsumer
 void addDispatcher(ConsumerId consumerId, ActiveMQDispatcher dispatcher)
           
 void addInputStream(ActiveMQInputStream stream)
           
 void addOutputStream(ActiveMQOutputStream stream)
           
protected  void addSession(ActiveMQSession session)
          Used internally for adding Sessions to the Connection
 void addTransportListener(TransportListener transportListener)
          Adds a transport listener so that a client can be notified of events in the underlying transport
 void asyncSendPacket(Command command)
          send a Packet through the Connection - for internal use only
 void changeUserInfo(String userName, String password)
          Changes the associated username/password that is associated with this connection.
 void checkClientIDWasManuallySpecified()
          Ensures that the clientID was manually specified and not auto-generated.
protected  void checkClosed()
          simply throws an exception if the Connection is already closed
protected  void checkClosedOrFailed()
          simply throws an exception if the Connection is already closed or the Transport has failed
 void cleanup()
          Cleans up this connection so that it's state is as if the connection was just created.
 void close()
          Closes the connection.
 javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination, String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
          Creates a connection consumer for this connection (optional operation).
 javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination, String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages, boolean noLocal)
           
 javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Queue queue, String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
          Creates a connection consumer for this connection (optional operation).
 javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Topic topic, String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
          Creates a connection consumer for this connection (optional operation).
 javax.jms.ConnectionConsumer createDurableConnectionConsumer(javax.jms.Topic topic, String subscriptionName, String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
          Create a durable connection consumer for this connection (optional operation).
 javax.jms.ConnectionConsumer createDurableConnectionConsumer(javax.jms.Topic topic, String subscriptionName, String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages, boolean noLocal)
          Create a durable connection consumer for this connection (optional operation).
 InputStream createDurableInputStream(javax.jms.Topic dest, String name)
           
 InputStream createDurableInputStream(javax.jms.Topic dest, String name, String messageSelector)
           
 InputStream createDurableInputStream(javax.jms.Topic dest, String name, String messageSelector, boolean noLocal)
           
 InputStream createInputStream(javax.jms.Destination dest)
           
 InputStream createInputStream(javax.jms.Destination dest, String messageSelector)
           
 InputStream createInputStream(javax.jms.Destination dest, String messageSelector, boolean noLocal)
           
 OutputStream createNonPersistentOutputStream(javax.jms.Destination dest)
          Creates a non persistent output stream; messages will not be written to disk
 OutputStream createOutputStream(javax.jms.Destination dest)
          Creates a persistent output stream; individual messages will be written to disk/database by the broker
 OutputStream createOutputStream(javax.jms.Destination dest, Map streamProperties, int deliveryMode, int priority, long timeToLive)
          Creates an output stream allowing full control over the delivery mode, the priority and time to live of the messages and the properties added to messages on the stream.
 javax.jms.QueueSession createQueueSession(boolean transacted, int acknowledgeMode)
          Creates a QueueSession object.
 javax.jms.Session createSession(boolean transacted, int acknowledgeMode)
          Creates a Session object.
protected  ActiveMQTempDestination createTempDestination(boolean topic)
          Create the DestinationInfo object for the temporary destination.
 javax.jms.TopicSession createTopicSession(boolean transacted, int acknowledgeMode)
          Creates a TopicSession object.
 void deleteTempDestination(ActiveMQTempDestination destination)
           
 void destroyDestination(ActiveMQDestination destination)
           
protected  void ensureConnectionInfoSent()
          Send the ConnectionInfo to the Broker
 BrokerInfo getBrokerInfo()
          Returns the broker information if it is available or null if it is not available yet.
 String getBrokerName()
          Returns the broker name if one is available or null if one is not available yet.
 String getClientID()
          Gets the client identifier for this connection.
 int getCloseTimeout()
           
 ConnectionInfo getConnectionInfo()
           
 JMSConnectionStatsImpl getConnectionStats()
           
 javax.jms.ExceptionListener getExceptionListener()
          Gets the ExceptionListener object for this connection.
 String getInitializedClientID()
           
 LongSequenceGenerator getLocalTransactionIdGenerator()
           
 javax.jms.ConnectionMetaData getMetaData()
          Gets the metadata for this connection.
protected  SessionId getNextSessionId()
           
 ActiveMQPrefetchPolicy getPrefetchPolicy()
           
 RedeliveryPolicy getRedeliveryPolicy()
           
 String getResourceManagerId()
           
 TaskRunnerFactory getSessionTaskRunner()
           
 StatsImpl getStats()
           
 Transport getTransportChannel()
           
 boolean isAlwaysSessionAsync()
           
 boolean isClosed()
          Returns true if the connection is closed
 boolean isClosing()
          Returns true if the connection is in the process of being closed
 boolean isCopyMessageOnSend()
           
 boolean isDeleted(ActiveMQDestination dest)
           
 boolean isDisableTimeStampsByDefault()
           
 boolean isDispatchAsync()
           
 boolean isNestedMapAndListEnabled()
           
 boolean isObjectMessageSerializationDefered()
           
 boolean isOptimizeAcknowledge()
           
 boolean isOptimizedMessageDispatch()
           
 boolean isStarted()
          Returns true if this connection has been started
 boolean isStatsEnabled()
           
 boolean isTransportFailed()
          Returns true if the underlying transport has failed
 boolean isUseAsyncSend()
           
 boolean isUseCompression()
           
 boolean isUseRetroactiveConsumer()
           
 boolean isUseSyncSend()
           
 boolean isWatchTopicAdvisories()
           
static ActiveMQConnection makeConnection()
          A static helper method to create a new connection
static ActiveMQConnection makeConnection(String uri)
          A static helper method to create a new connection
static ActiveMQConnection makeConnection(String user, String password, String uri)
          A static helper method to create a new connection
 void onAsyncException(Throwable error)
          Used for handling async exceptions
 void onCommand(Object o)
          called to process a command
protected  void onConnectionControl(ConnectionControl command)
           
protected  void onConsumerControl(ConsumerControl command)
           
protected  void onControlCommand(ControlCommand command)
           
 void onException(IOException error)
          An unrecoverable exception has occured on the transport
protected  void removeConnectionConsumer(ActiveMQConnectionConsumer connectionConsumer)
          Remove a ConnectionConsumer
 void removeDispatcher(ConsumerId consumerId)
           
 void removeInputStream(ActiveMQInputStream stream)
           
 void removeOutputStream(ActiveMQOutputStream stream)
           
protected  void removeSession(ActiveMQSession session)
          Used interanlly for removing Sessions from a Connection
 void removeTransportListener(TransportListener transportListener)
           
 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 setClientID(String newClientID)
          Sets the client identifier for this connection.
 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 setDefaultClientID(String clientID)
          Sets the default client id that the connection will use if explicitly not set with the setClientId() call.
 void setDisableTimeStampsByDefault(boolean timeStampsDisableByDefault)
          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 setExceptionListener(javax.jms.ExceptionListener listener)
          Sets an exception listener for this connection.
 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)
          Enables an optimised acknowledgement mode where messages are acknowledged in batches rather than individually
 void setOptimizedMessageDispatch(boolean dispatchOptimizedMessage)
          If this flag is set then an larger prefetch limit is used - only applicable for durable topic subscribers.
protected  void setPassword(String password)
           
 void setPrefetchPolicy(ActiveMQPrefetchPolicy prefetchPolicy)
          Sets the prefetch policy for consumers created by this connection.
 void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy)
          Sets the redelivery policy to be used when messages are rolled back
 void setSessionTaskRunner(TaskRunnerFactory sessionTaskRunner)
           
 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.
protected  void setUserName(String userName)
           
 void setUseSyncSend(boolean forceSyncSend)
           
 void setWatchTopicAdvisories(boolean watchTopicAdvisories)
           
 void start()
          Starts (or restarts) a connection's delivery of incoming messages.
 void stop()
          Temporarily stops a connection's delivery of incoming messages.
 Response syncSendPacket(Command command)
          Send a packet through a Connection - for internal use only
 Response syncSendPacket(Command command, int timeout)
          Send a packet through a Connection - for internal use only
 String toString()
           
protected  void transportFailed(IOException error)
           
 void transportInterupted()
          The transport has suffered an interuption from which it hopes to recover
 void transportResumed()
          The transport has resumed after an interuption
 void unsubscribe(String name)
          Unsubscribes a durable subscription that has been created by a client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_USER

public static final String DEFAULT_USER

DEFAULT_PASSWORD

public static final String DEFAULT_PASSWORD

DEFAULT_BROKER_URL

public static final String DEFAULT_BROKER_URL
See Also:
Constant Field Values

dispatchAsync

protected boolean dispatchAsync

alwaysSessionAsync

protected boolean alwaysSessionAsync
Constructor Detail

ActiveMQConnection

protected ActiveMQConnection(Transport transport,
                             IdGenerator clientIdGenerator,
                             JMSStatsImpl factoryStats)
                      throws Exception
Construct an ActiveMQConnection

Parameters:
transport -
factoryStats -
Throws:
Exception
Method Detail

setUserName

protected void setUserName(String userName)

setPassword

protected void setPassword(String password)

makeConnection

public static ActiveMQConnection makeConnection()
                                         throws javax.jms.JMSException
A static helper method to create a new connection

Returns:
an ActiveMQConnection
Throws:
javax.jms.JMSException

makeConnection

public static ActiveMQConnection makeConnection(String uri)
                                         throws javax.jms.JMSException,
                                                URISyntaxException
A static helper method to create a new connection

Parameters:
uri -
Returns:
and ActiveMQConnection
Throws:
javax.jms.JMSException
URISyntaxException

makeConnection

public static ActiveMQConnection makeConnection(String user,
                                                String password,
                                                String uri)
                                         throws javax.jms.JMSException,
                                                URISyntaxException
A static helper method to create a new connection

Parameters:
user -
password -
uri -
Returns:
an ActiveMQConnection
Throws:
javax.jms.JMSException
URISyntaxException

getConnectionStats

public JMSConnectionStatsImpl getConnectionStats()
Returns:
a number unique for this connection

createSession

public javax.jms.Session createSession(boolean transacted,
                                       int acknowledgeMode)
                                throws javax.jms.JMSException
Creates a Session object.

Specified by:
createSession in interface javax.jms.Connection
Parameters:
transacted - indicates whether the session is transacted
acknowledgeMode - indicates whether the consumer or the client will acknowledge any messages it receives; ignored if the session is transacted. Legal values are Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, and Session.DUPS_OK_ACKNOWLEDGE.
Returns:
a newly created session
Throws:
javax.jms.JMSException - if the Connection object fails to create a session due to some internal error or lack of support for the specific transaction and acknowledgement mode.
Since:
1.1
See Also:
Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, Session.DUPS_OK_ACKNOWLEDGE

getNextSessionId

protected SessionId getNextSessionId()
Returns:
sessionId

getClientID

public String getClientID()
                   throws javax.jms.JMSException
Gets the client identifier for this connection.

This value is specific to the JMS provider. It is either preconfigured by an administrator in a ConnectionFactory object or assigned dynamically by the application by calling the setClientID method.

Specified by:
getClientID in interface javax.jms.Connection
Returns:
the unique client identifier
Throws:
javax.jms.JMSException - if the JMS provider fails to return the client ID for this connection due to some internal error.

setClientID

public void setClientID(String newClientID)
                 throws javax.jms.JMSException
Sets the client identifier for this connection.

The preferred way to assign a JMS client's client identifier is for it to be configured in a client-specific ConnectionFactory object and transparently assigned to the Connection object it creates.

Alternatively, a client can set a connection's client identifier using a provider-specific value. The facility to set a connection's client identifier explicitly is not a mechanism for overriding the identifier that has been administratively configured. It is provided for the case where no administratively specified identifier exists. If one does exist, an attempt to change it by setting it must throw an IllegalStateException. If a client sets the client identifier explicitly, it must do so immediately after it creates the connection and before any other action on the connection is taken. After this point, setting the client identifier is a programming error that should throw an IllegalStateException.

The purpose of the client identifier is to associate a connection and its objects with a state maintained on behalf of the client by a provider. The only such state identified by the JMS API is that required to support durable subscriptions.

If another connection with the same clientID is already running when this method is called, the JMS provider should detect the duplicate ID and throw an InvalidClientIDException.

Specified by:
setClientID in interface javax.jms.Connection
Parameters:
newClientID - the unique client identifier
Throws:
javax.jms.JMSException - if the JMS provider fails to set the client ID for this connection due to some internal error.
javax.jms.InvalidClientIDException - if the JMS client specifies an invalid or duplicate client ID.
javax.jms.IllegalStateException - if the JMS client attempts to set a connection's client ID at the wrong time or when it has been administratively configured.

setDefaultClientID

public void setDefaultClientID(String clientID)
                        throws javax.jms.JMSException
Sets the default client id that the connection will use if explicitly not set with the setClientId() call.

Throws:
javax.jms.JMSException

getMetaData

public javax.jms.ConnectionMetaData getMetaData()
                                         throws javax.jms.JMSException
Gets the metadata for this connection.

Specified by:
getMetaData in interface javax.jms.Connection
Returns:
the connection metadata
Throws:
javax.jms.JMSException - if the JMS provider fails to get the connection metadata for this connection.
See Also:
ConnectionMetaData

getExceptionListener

public javax.jms.ExceptionListener getExceptionListener()
                                                 throws javax.jms.JMSException
Gets the ExceptionListener object for this connection. Not every Connection has an ExceptionListener associated with it.

Specified by:
getExceptionListener in interface javax.jms.Connection
Returns:
the ExceptionListener for this connection, or null. if no ExceptionListener is associated with this connection.
Throws:
javax.jms.JMSException - if the JMS provider fails to get the ExceptionListener for this connection.
See Also:
Connection.setExceptionListener(ExceptionListener)

setExceptionListener

public void setExceptionListener(javax.jms.ExceptionListener listener)
                          throws javax.jms.JMSException
Sets an exception listener for this connection.

If a JMS provider detects a serious problem with a connection, it informs the connection's ExceptionListener, if one has been registered. It does this by calling the listener's onException method, passing it a JMSException object describing the problem.

An exception listener allows a client to be notified of a problem asynchronously. Some connections only consume messages, so they would have no other way to learn their connection has failed.

A connection serializes execution of its ExceptionListener.

A JMS provider should attempt to resolve connection problems itself before it notifies the client of them.

Specified by:
setExceptionListener in interface javax.jms.Connection
Parameters:
listener - the exception listener
Throws:
javax.jms.JMSException - if the JMS provider fails to set the exception listener for this connection.

start

public void start()
           throws javax.jms.JMSException
Starts (or restarts) a connection's delivery of incoming messages. A call to start on a connection that has already been started is ignored.

Specified by:
start in interface javax.jms.Connection
Throws:
javax.jms.JMSException - if the JMS provider fails to start message delivery due to some internal error.
See Also:
Connection.stop()

stop

public void stop()
          throws javax.jms.JMSException
Temporarily stops a connection's delivery of incoming messages. Delivery can be restarted using the connection's start method. When the connection is stopped, delivery to all the connection's message consumers is inhibited: synchronous receives block, and messages are not delivered to message listeners.

This call blocks until receives and/or message listeners in progress have completed.

Stopping a connection has no effect on its ability to send messages. A call to stop on a connection that has already been stopped is ignored.

A call to stop must not return until delivery of messages has paused. This means that a client can rely on the fact that none of its message listeners will be called and that all threads of control waiting for receive calls to return will not return with a message until the connection is restarted. The receive timers for a stopped connection continue to advance, so receives may time out while the connection is stopped.

If message listeners are running when stop is invoked, the stop call must wait until all of them have returned before it may return. While these message listeners are completing, they must have the full services of the connection available to them.

Specified by:
stop in interface javax.jms.Connection
Throws:
javax.jms.JMSException - if the JMS provider fails to stop message delivery due to some internal error.
See Also:
Connection.start()

close

public void close()
           throws javax.jms.JMSException
Closes the connection.

Since a provider typically allocates significant resources outside the JVM on behalf of a connection, clients should close these resources when they are not needed. Relying on garbage collection to eventually reclaim these resources may not be timely enough.

There is no need to close the sessions, producers, and consumers of a closed connection.

Closing a connection causes all temporary destinations to be deleted.

When this method is invoked, it should not return until message processing has been shut down in an orderly fashion. This means that all message listeners that may have been running have returned, and that all pending receives have returned. A close terminates all pending message receives on the connection's sessions' consumers. The receives may return with a message or with null, depending on whether there was a message available at the time of the close. If one or more of the connection's sessions' message listeners is processing a message at the time when connection close is invoked, all the facilities of the connection and its sessions must remain available to those listeners until they return control to the JMS provider.

Closing a connection causes any of its sessions' transactions in progress to be rolled back. In the case where a session's work is coordinated by an external transaction manager, a session's commit and rollback methods are not used and the result of a closed session's work is determined later by the transaction manager. Closing a connection does NOT force an acknowledgment of client-acknowledged sessions.

Invoking the acknowledge method of a received message from a closed connection's session must throw an IllegalStateException. Closing a closed connection must NOT throw an exception.

Specified by:
close in interface javax.jms.Connection
Specified by:
close in interface Closeable
Throws:
javax.jms.JMSException - if the JMS provider fails to close the connection due to some internal error. For example, a failure to release resources or to close a socket connection can cause this exception to be thrown.

createDurableConnectionConsumer

public javax.jms.ConnectionConsumer createDurableConnectionConsumer(javax.jms.Topic topic,
                                                                    String subscriptionName,
                                                                    String messageSelector,
                                                                    javax.jms.ServerSessionPool sessionPool,
                                                                    int maxMessages)
                                                             throws javax.jms.JMSException
Create a durable connection consumer for this connection (optional operation). This is an expert facility not used by regular JMS clients.

Specified by:
createDurableConnectionConsumer in interface javax.jms.Connection
Specified by:
createDurableConnectionConsumer in interface javax.jms.TopicConnection
Parameters:
topic - topic to access
subscriptionName - durable subscription name
messageSelector - only messages with properties matching the message selector expression are delivered. A value of null or an empty string indicates that there is no message selector for the message consumer.
sessionPool - the server session pool to associate with this durable connection consumer
maxMessages - the maximum number of messages that can be assigned to a server session at one time
Returns:
the durable connection consumer
Throws:
javax.jms.JMSException - if the Connection object fails to create a connection consumer due to some internal error or invalid arguments for sessionPool and messageSelector.
javax.jms.InvalidDestinationException - if an invalid destination is specified.
javax.jms.InvalidSelectorException - if the message selector is invalid.
Since:
1.1
See Also:
ConnectionConsumer

createDurableConnectionConsumer

public javax.jms.ConnectionConsumer createDurableConnectionConsumer(javax.jms.Topic topic,
                                                                    String subscriptionName,
                                                                    String messageSelector,
                                                                    javax.jms.ServerSessionPool sessionPool,
                                                                    int maxMessages,
                                                                    boolean noLocal)
                                                             throws javax.jms.JMSException
Create a durable connection consumer for this connection (optional operation). This is an expert facility not used by regular JMS clients.

Parameters:
topic - topic to access
subscriptionName - durable subscription name
messageSelector - only messages with properties matching the message selector expression are delivered. A value of null or an empty string indicates that there is no message selector for the message consumer.
sessionPool - the server session pool to associate with this durable connection consumer
maxMessages - the maximum number of messages that can be assigned to a server session at one time
noLocal - set true if you want to filter out messages published locally
Returns:
the durable connection consumer
Throws:
javax.jms.JMSException - if the Connection object fails to create a connection consumer due to some internal error or invalid arguments for sessionPool and messageSelector.
javax.jms.InvalidDestinationException - if an invalid destination is specified.
javax.jms.InvalidSelectorException - if the message selector is invalid.
Since:
1.1
See Also:
ConnectionConsumer

isStarted

public boolean isStarted()
Returns true if this connection has been started

Returns:
true if this Connection is started

isClosed

public boolean isClosed()
Returns true if the connection is closed


isClosing

public boolean isClosing()
Returns true if the connection is in the process of being closed


isTransportFailed

public boolean isTransportFailed()
Returns true if the underlying transport has failed


getPrefetchPolicy

public ActiveMQPrefetchPolicy getPrefetchPolicy()
Returns:
Returns the prefetchPolicy.

setPrefetchPolicy

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


getTransportChannel

public Transport getTransportChannel()

getInitializedClientID

public String getInitializedClientID()
                              throws javax.jms.JMSException
Returns:
Returns the clientID of the connection, forcing one to be generated if one has not yet been configured.
Throws:
javax.jms.JMSException

isDisableTimeStampsByDefault

public boolean isDisableTimeStampsByDefault()
Returns:
Returns the timeStampsDisableByDefault.

setDisableTimeStampsByDefault

public void setDisableTimeStampsByDefault(boolean timeStampsDisableByDefault)
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()
Returns:
Returns the dispatchOptimizedMessage.

setOptimizedMessageDispatch

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


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


getConnectionInfo

public ConnectionInfo getConnectionInfo()
Returns:
ConnectionInfo

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.


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


addTransportListener

public void addTransportListener(TransportListener transportListener)
Adds a transport listener so that a client can be notified of events in the underlying transport


removeTransportListener

public void removeTransportListener(TransportListener transportListener)

getSessionTaskRunner

public TaskRunnerFactory getSessionTaskRunner()

setSessionTaskRunner

public void setSessionTaskRunner(TaskRunnerFactory sessionTaskRunner)

isStatsEnabled

public boolean isStatsEnabled()
Returns:
the statsEnabled

setStatsEnabled

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

addSession

protected void addSession(ActiveMQSession session)
                   throws javax.jms.JMSException
Used internally for adding Sessions to the Connection

Parameters:
session -
Throws:
javax.jms.JMSException
javax.jms.JMSException

removeSession

protected void removeSession(ActiveMQSession session)
Used interanlly for removing Sessions from a Connection

Parameters:
session -

addConnectionConsumer

protected void addConnectionConsumer(ActiveMQConnectionConsumer connectionConsumer)
                              throws javax.jms.JMSException
Add a ConnectionConsumer

Parameters:
connectionConsumer -
Throws:
javax.jms.JMSException

removeConnectionConsumer

protected void removeConnectionConsumer(ActiveMQConnectionConsumer connectionConsumer)
Remove a ConnectionConsumer

Parameters:
connectionConsumer -

createTopicSession

public javax.jms.TopicSession createTopicSession(boolean transacted,
                                                 int acknowledgeMode)
                                          throws javax.jms.JMSException
Creates a TopicSession object.

Specified by:
createTopicSession in interface javax.jms.TopicConnection
Parameters:
transacted - indicates whether the session is transacted
acknowledgeMode - indicates whether the consumer or the client will acknowledge any messages it receives; ignored if the session is transacted. Legal values are Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, and Session.DUPS_OK_ACKNOWLEDGE.
Returns:
a newly created topic session
Throws:
javax.jms.JMSException - if the TopicConnection object fails to create a session due to some internal error or lack of support for the specific transaction and acknowledgement mode.
See Also:
Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, Session.DUPS_OK_ACKNOWLEDGE

createConnectionConsumer

public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Topic topic,
                                                             String messageSelector,
                                                             javax.jms.ServerSessionPool sessionPool,
                                                             int maxMessages)
                                                      throws javax.jms.JMSException
Creates a connection consumer for this connection (optional operation). This is an expert facility not used by regular JMS clients.

Specified by:
createConnectionConsumer in interface javax.jms.TopicConnection
Parameters:
topic - the topic to access
messageSelector - only messages with properties matching the message selector expression are delivered. A value of null or an empty string indicates that there is no message selector for the message consumer.
sessionPool - the server session pool to associate with this connection consumer
maxMessages - the maximum number of messages that can be assigned to a server session at one time
Returns:
the connection consumer
Throws:
javax.jms.JMSException - if the TopicConnection object fails to create a connection consumer due to some internal error or invalid arguments for sessionPool and messageSelector.
javax.jms.InvalidDestinationException - if an invalid topic is specified.
javax.jms.InvalidSelectorException - if the message selector is invalid.
See Also:
ConnectionConsumer

createConnectionConsumer

public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Queue queue,
                                                             String messageSelector,
                                                             javax.jms.ServerSessionPool sessionPool,
                                                             int maxMessages)
                                                      throws javax.jms.JMSException
Creates a connection consumer for this connection (optional operation). This is an expert facility not used by regular JMS clients.

Specified by:
createConnectionConsumer in interface javax.jms.QueueConnection
Parameters:
queue - the queue to access
messageSelector - only messages with properties matching the message selector expression are delivered. A value of null or an empty string indicates that there is no message selector for the message consumer.
sessionPool - the server session pool to associate with this connection consumer
maxMessages - the maximum number of messages that can be assigned to a server session at one time
Returns:
the connection consumer
Throws:
javax.jms.JMSException - if the QueueConnection object fails to create a connection consumer due to some internal error or invalid arguments for sessionPool and messageSelector.
javax.jms.InvalidDestinationException - if an invalid queue is specified.
javax.jms.InvalidSelectorException - if the message selector is invalid.
See Also:
ConnectionConsumer

createConnectionConsumer

public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination,
                                                             String messageSelector,
                                                             javax.jms.ServerSessionPool sessionPool,
                                                             int maxMessages)
                                                      throws javax.jms.JMSException
Creates a connection consumer for this connection (optional operation). This is an expert facility not used by regular JMS clients.

Specified by:
createConnectionConsumer in interface javax.jms.Connection
Parameters:
destination - the destination to access
messageSelector - only messages with properties matching the message selector expression are delivered. A value of null or an empty string indicates that there is no message selector for the message consumer.
sessionPool - the server session pool to associate with this connection consumer
maxMessages - the maximum number of messages that can be assigned to a server session at one time
Returns:
the connection consumer
Throws:
javax.jms.JMSException - if the Connection object fails to create a connection consumer due to some internal error or invalid arguments for sessionPool and messageSelector.
javax.jms.InvalidDestinationException - if an invalid destination is specified.
javax.jms.InvalidSelectorException - if the message selector is invalid.
Since:
1.1
See Also:
ConnectionConsumer

createConnectionConsumer

public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination,
                                                             String messageSelector,
                                                             javax.jms.ServerSessionPool sessionPool,
                                                             int maxMessages,
                                                             boolean noLocal)
                                                      throws javax.jms.JMSException
Throws:
javax.jms.JMSException

createQueueSession

public javax.jms.QueueSession createQueueSession(boolean transacted,
                                                 int acknowledgeMode)
                                          throws javax.jms.JMSException
Creates a QueueSession object.

Specified by:
createQueueSession in interface javax.jms.QueueConnection
Parameters:
transacted - indicates whether the session is transacted
acknowledgeMode - indicates whether the consumer or the client will acknowledge any messages it receives; ignored if the session is transacted. Legal values are Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, and Session.DUPS_OK_ACKNOWLEDGE.
Returns:
a newly created queue session
Throws:
javax.jms.JMSException - if the QueueConnection object fails to create a session due to some internal error or lack of support for the specific transaction and acknowledgement mode.
See Also:
Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, Session.DUPS_OK_ACKNOWLEDGE

checkClientIDWasManuallySpecified

public void checkClientIDWasManuallySpecified()
                                       throws javax.jms.JMSException
Ensures that the clientID was manually specified and not auto-generated. If the clientID was not specified this method will throw an exception. This method is used to ensure that the clientID + durableSubscriber name are used correctly.

Throws:
javax.jms.JMSException

asyncSendPacket

public void asyncSendPacket(Command command)
                     throws javax.jms.JMSException
send a Packet through the Connection - for internal use only

Parameters:
command -
Throws:
javax.jms.JMSException

syncSendPacket

public Response syncSendPacket(Command command)
                        throws javax.jms.JMSException
Send a packet through a Connection - for internal use only

Parameters:
command -
Returns:
Throws:
javax.jms.JMSException

syncSendPacket

public Response syncSendPacket(Command command,
                               int timeout)
                        throws javax.jms.JMSException
Send a packet through a Connection - for internal use only

Parameters:
command -
Returns:
Throws:
javax.jms.JMSException

getStats

public StatsImpl getStats()
Specified by:
getStats in interface StatsCapable
Returns:
statistics for this Connection

checkClosedOrFailed

protected void checkClosedOrFailed()
                            throws javax.jms.JMSException
simply throws an exception if the Connection is already closed or the Transport has failed

Throws:
javax.jms.JMSException

checkClosed

protected void checkClosed()
                    throws javax.jms.JMSException
simply throws an exception if the Connection is already closed

Throws:
javax.jms.JMSException

ensureConnectionInfoSent

protected void ensureConnectionInfoSent()
                                 throws javax.jms.JMSException
Send the ConnectionInfo to the Broker

Throws:
javax.jms.JMSException

isUseAsyncSend

public boolean isUseAsyncSend()
Returns:
Returns the useAsyncSend.

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.


cleanup

public void cleanup()
             throws javax.jms.JMSException
Cleans up this connection so that it's state is as if the connection was just created. This allows the Resource Adapter to clean up a connection so that it can be reused without having to close and recreate the connection.

Throws:
javax.jms.JMSException

changeUserInfo

public void changeUserInfo(String userName,
                           String password)
                    throws javax.jms.JMSException
Changes the associated username/password that is associated with this connection. If the connection has been used, you must called cleanup() before calling this method.

Throws:
javax.jms.IllegalStateException - if the connection is in used.
javax.jms.JMSException

getResourceManagerId

public String getResourceManagerId()
                            throws javax.jms.JMSException
Returns:
Returns the resourceManagerId.
Throws:
javax.jms.JMSException

getBrokerName

public String getBrokerName()
Returns the broker name if one is available or null if one is not available yet.


getBrokerInfo

public BrokerInfo getBrokerInfo()
Returns the broker information if it is available or null if it is not available yet.


getRedeliveryPolicy

public RedeliveryPolicy getRedeliveryPolicy()
                                     throws javax.jms.JMSException
Returns:
Returns the RedeliveryPolicy.
Throws:
javax.jms.JMSException

setRedeliveryPolicy

public void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy)
Sets the redelivery policy to be used when messages are rolled back


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)
Enables an optimised acknowledgement mode where messages are acknowledged in batches rather than individually

Parameters:
optimizeAcknowledge - The optimizeAcknowledge to set.

addDispatcher

public void addDispatcher(ConsumerId consumerId,
                          ActiveMQDispatcher dispatcher)

removeDispatcher

public void removeDispatcher(ConsumerId consumerId)

onCommand

public void onCommand(Object o)
Description copied from interface: TransportListener
called to process a command

Specified by:
onCommand in interface TransportListener
Parameters:
command - - the command to consume

onAsyncException

public void onAsyncException(Throwable error)
Used for handling async exceptions

Parameters:
error -

onException

public void onException(IOException error)
Description copied from interface: TransportListener
An unrecoverable exception has occured on the transport

Specified by:
onException in interface TransportListener

transportInterupted

public void transportInterupted()
Description copied from interface: TransportListener
The transport has suffered an interuption from which it hopes to recover

Specified by:
transportInterupted in interface TransportListener

transportResumed

public void transportResumed()
Description copied from interface: TransportListener
The transport has resumed after an interuption

Specified by:
transportResumed in interface TransportListener

createTempDestination

protected ActiveMQTempDestination createTempDestination(boolean topic)
                                                 throws javax.jms.JMSException
Create the DestinationInfo object for the temporary destination.

Parameters:
topic - - if its true topic, else queue.
Returns:
DestinationInfo
Throws:
javax.jms.JMSException

deleteTempDestination

public void deleteTempDestination(ActiveMQTempDestination destination)
                           throws javax.jms.JMSException
Parameters:
destination -
Throws:
javax.jms.JMSException

isDeleted

public boolean isDeleted(ActiveMQDestination dest)

isCopyMessageOnSend

public boolean isCopyMessageOnSend()

getLocalTransactionIdGenerator

public LongSequenceGenerator getLocalTransactionIdGenerator()

isUseCompression

public boolean isUseCompression()

setUseCompression

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


destroyDestination

public void destroyDestination(ActiveMQDestination destination)
                        throws javax.jms.JMSException
Throws:
javax.jms.JMSException

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.

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.


createInputStream

public InputStream createInputStream(javax.jms.Destination dest)
                              throws javax.jms.JMSException
Specified by:
createInputStream in interface StreamConnection
Throws:
javax.jms.JMSException

createInputStream

public InputStream createInputStream(javax.jms.Destination dest,
                                     String messageSelector)
                              throws javax.jms.JMSException
Specified by:
createInputStream in interface StreamConnection
Throws:
javax.jms.JMSException

createInputStream

public InputStream createInputStream(javax.jms.Destination dest,
                                     String messageSelector,
                                     boolean noLocal)
                              throws javax.jms.JMSException
Specified by:
createInputStream in interface StreamConnection
Throws:
javax.jms.JMSException

createDurableInputStream

public InputStream createDurableInputStream(javax.jms.Topic dest,
                                            String name)
                                     throws javax.jms.JMSException
Specified by:
createDurableInputStream in interface StreamConnection
Throws:
javax.jms.JMSException

createDurableInputStream

public InputStream createDurableInputStream(javax.jms.Topic dest,
                                            String name,
                                            String messageSelector)
                                     throws javax.jms.JMSException
Specified by:
createDurableInputStream in interface StreamConnection
Throws:
javax.jms.JMSException

createDurableInputStream

public InputStream createDurableInputStream(javax.jms.Topic dest,
                                            String name,
                                            String messageSelector,
                                            boolean noLocal)
                                     throws javax.jms.JMSException
Specified by:
createDurableInputStream in interface StreamConnection
Throws:
javax.jms.JMSException

createOutputStream

public OutputStream createOutputStream(javax.jms.Destination dest)
                                throws javax.jms.JMSException
Creates a persistent output stream; individual messages will be written to disk/database by the broker

Specified by:
createOutputStream in interface StreamConnection
Throws:
javax.jms.JMSException

createNonPersistentOutputStream

public OutputStream createNonPersistentOutputStream(javax.jms.Destination dest)
                                             throws javax.jms.JMSException
Creates a non persistent output stream; messages will not be written to disk

Throws:
javax.jms.JMSException

createOutputStream

public OutputStream createOutputStream(javax.jms.Destination dest,
                                       Map streamProperties,
                                       int deliveryMode,
                                       int priority,
                                       long timeToLive)
                                throws javax.jms.JMSException
Creates an output stream allowing full control over the delivery mode, the priority and time to live of the messages and the properties added to messages on the stream.

Specified by:
createOutputStream in interface StreamConnection
Parameters:
streamProperties - defines a map of key-value pairs where the keys are strings and the values are primitive values (numbers and strings) which are appended to the messages similarly to using the Message.setObjectProperty(String, Object) method
Throws:
javax.jms.JMSException

unsubscribe

public void unsubscribe(String name)
                 throws javax.jms.JMSException
Unsubscribes a durable subscription that has been created by a client.

This method deletes the state being maintained on behalf of the subscriber by its provider.

It is erroneous for a client to delete a durable subscription while there is an active MessageConsumer or TopicSubscriber for the subscription, or while a consumed message is part of a pending transaction or has not been acknowledged in the session.

Specified by:
unsubscribe in interface StreamConnection
Parameters:
name - the name used to identify this subscription
Throws:
javax.jms.JMSException - if the session fails to unsubscribe to the durable subscription due to some internal error.
javax.jms.InvalidDestinationException - if an invalid subscription name is specified.
Since:
1.1

addOutputStream

public void addOutputStream(ActiveMQOutputStream stream)

removeOutputStream

public void removeOutputStream(ActiveMQOutputStream stream)

addInputStream

public void addInputStream(ActiveMQInputStream stream)

removeInputStream

public void removeInputStream(ActiveMQInputStream stream)

onControlCommand

protected void onControlCommand(ControlCommand command)

onConnectionControl

protected void onConnectionControl(ConnectionControl command)

onConsumerControl

protected void onConsumerControl(ConsumerControl command)

transportFailed

protected void transportFailed(IOException error)

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


toString

public String toString()
Overrides:
toString in class Object

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.