Save This Page
Home » apache-activemq-5.1.0-src » org.apache » activemq » [javadoc | source]
org.apache.activemq
public class: ActiveMQConnection [javadoc | source]
java.lang.Object
   org.apache.activemq.ActiveMQConnection

All Implemented Interfaces:
    TransportListener, StatsCapable, EnhancedConnection, javax.jms.TopicConnection, Closeable, javax.jms.QueueConnection, StreamConnection, javax.jms.Connection

Direct Known Subclasses:
    CamelConnection, ActiveMQXAConnection

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Field Summary
public static final  String DEFAULT_USER     
public static final  String DEFAULT_PASSWORD     
public static final  String DEFAULT_BROKER_URL     
public final  ConcurrentHashMap activeTempDestinations     
protected  boolean dispatchAsync     
protected  boolean alwaysSessionAsync     
Constructor:
 protected ActiveMQConnection(Transport transport,
    IdGenerator clientIdGenerator,
    JMSStatsImpl factoryStats) throws Exception 
    Construct an ActiveMQConnection
    Parameters:
    transport -
    factoryStats -
    Throws:
    Exception -
Method from org.apache.activemq.ActiveMQConnection Summary:
addConnectionConsumer,   addDispatcher,   addInputStream,   addOutputStream,   addProducer,   addSession,   addTransportListener,   asyncSendPacket,   changeUserInfo,   checkClientIDWasManuallySpecified,   checkClosed,   checkClosedOrFailed,   cleanup,   close,   createBlobTransferPolicy,   createConnectionConsumer,   createConnectionConsumer,   createConnectionConsumer,   createConnectionConsumer,   createDurableConnectionConsumer,   createDurableConnectionConsumer,   createDurableInputStream,   createDurableInputStream,   createDurableInputStream,   createInputStream,   createInputStream,   createInputStream,   createNonPersistentOutputStream,   createOutputStream,   createOutputStream,   createQueueSession,   createSession,   createTempDestination,   createTopicSession,   deleteTempDestination,   destroyDestination,   ensureConnectionInfoSent,   getBlobTransferPolicy,   getBrokerInfo,   getBrokerName,   getClientID,   getCloseTimeout,   getConnectionInfo,   getConnectionStats,   getDestinationSource,   getExceptionListener,   getInitializedClientID,   getLocalTransactionIdGenerator,   getMetaData,   getNextSessionId,   getPrefetchPolicy,   getProducerWindowSize,   getProtocolVersion,   getRedeliveryPolicy,   getResourceManagerId,   getSendTimeout,   getSessionTaskRunner,   getStats,   getTimeCreated,   getTransformer,   getTransport,   getTransportChannel,   getWarnAboutUnstartedConnectionTimeout,   isAlwaysSessionAsync,   isAlwaysSyncSend,   isClosed,   isClosing,   isCopyMessageOnSend,   isDeleted,   isDisableTimeStampsByDefault,   isDispatchAsync,   isDuplicate,   isExclusiveConsumer,   isNestedMapAndListEnabled,   isObjectMessageSerializationDefered,   isOptimizeAcknowledge,   isOptimizedMessageDispatch,   isStarted,   isStatsEnabled,   isTransportFailed,   isUseAsyncSend,   isUseCompression,   isUseRetroactiveConsumer,   isWatchTopicAdvisories,   makeConnection,   makeConnection,   makeConnection,   onAsyncException,   onCommand,   onConnectionControl,   onConsumerControl,   onControlCommand,   onException,   onWireFormatInfo,   removeConnectionConsumer,   removeDispatcher,   removeDispatcher,   removeInputStream,   removeOutputStream,   removeProducer,   removeSession,   removeTransportListener,   rollbackDuplicate,   send,   setAlwaysSessionAsync,   setAlwaysSyncSend,   setBlobTransferPolicy,   setClientID,   setCloseTimeout,   setCopyMessageOnSend,   setDefaultClientID,   setDisableTimeStampsByDefault,   setDispatchAsync,   setExceptionListener,   setExclusiveConsumer,   setNestedMapAndListEnabled,   setObjectMessageSerializationDefered,   setOptimizeAcknowledge,   setOptimizedMessageDispatch,   setPassword,   setPrefetchPolicy,   setProducerWindowSize,   setRedeliveryPolicy,   setSendTimeout,   setSessionTaskRunner,   setStatsEnabled,   setTransformer,   setUseAsyncSend,   setUseCompression,   setUseRetroactiveConsumer,   setUserName,   setWarnAboutUnstartedConnectionTimeout,   setWatchTopicAdvisories,   start,   stop,   syncSendPacket,   syncSendPacket,   toString,   transportFailed,   transportInterupted,   transportResumed,   unsubscribe
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.activemq.ActiveMQConnection Detail:
 protected  void addConnectionConsumer(ActiveMQConnectionConsumer connectionConsumer) throws JMSException 
    Add a ConnectionConsumer
 public  void addDispatcher(ConsumerId consumerId,
    ActiveMQDispatcher dispatcher) 
 public  void addInputStream(ActiveMQInputStream stream) 
 public  void addOutputStream(ActiveMQOutputStream stream) 
 public  void addProducer(ProducerId producerId,
    ActiveMQMessageProducer producer) 
 protected  void addSession(ActiveMQSession session) throws JMSException 
    Used internally for adding Sessions to the Connection
 public  void addTransportListener(TransportListener transportListener) 
    Adds a transport listener so that a client can be notified of events in the underlying transport
 public  void asyncSendPacket(Command command) throws JMSException 
    send a Packet through the Connection - for internal use only
 public  void changeUserInfo(String userName,
    String password) throws 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.
 public  void checkClientIDWasManuallySpecified() throws 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.
 protected synchronized  void checkClosed() throws JMSException 
    simply throws an exception if the Connection is already closed
 protected synchronized  void checkClosedOrFailed() throws JMSException 
    simply throws an exception if the Connection is already closed or the Transport has failed
 public  void cleanup() throws 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.
 public  void close() throws 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.

 protected BlobTransferPolicy createBlobTransferPolicy() 
 public ConnectionConsumer createConnectionConsumer(Topic topic,
    String messageSelector,
    ServerSessionPool sessionPool,
    int maxMessages) throws JMSException 
    Creates a connection consumer for this connection (optional operation). This is an expert facility not used by regular JMS clients.
 public ConnectionConsumer createConnectionConsumer(Queue queue,
    String messageSelector,
    ServerSessionPool sessionPool,
    int maxMessages) throws JMSException 
    Creates a connection consumer for this connection (optional operation). This is an expert facility not used by regular JMS clients.
 public ConnectionConsumer createConnectionConsumer(Destination destination,
    String messageSelector,
    ServerSessionPool sessionPool,
    int maxMessages) throws JMSException 
    Creates a connection consumer for this connection (optional operation). This is an expert facility not used by regular JMS clients.
 public ConnectionConsumer createConnectionConsumer(Destination destination,
    String messageSelector,
    ServerSessionPool sessionPool,
    int maxMessages,
    boolean noLocal) throws JMSException 
 public ConnectionConsumer createDurableConnectionConsumer(Topic topic,
    String subscriptionName,
    String messageSelector,
    ServerSessionPool sessionPool,
    int maxMessages) throws JMSException 
    Create a durable connection consumer for this connection (optional operation). This is an expert facility not used by regular JMS clients.
 public ConnectionConsumer createDurableConnectionConsumer(Topic topic,
    String subscriptionName,
    String messageSelector,
    ServerSessionPool sessionPool,
    int maxMessages,
    boolean noLocal) throws JMSException 
    Create a durable connection consumer for this connection (optional operation). This is an expert facility not used by regular JMS clients.
 public InputStream createDurableInputStream(Topic dest,
    String name) throws JMSException 
 public InputStream createDurableInputStream(Topic dest,
    String name,
    String messageSelector) throws JMSException 
 public InputStream createDurableInputStream(Topic dest,
    String name,
    String messageSelector,
    boolean noLocal) throws JMSException 
 public InputStream createInputStream(Destination dest) throws JMSException 
 public InputStream createInputStream(Destination dest,
    String messageSelector) throws JMSException 
 public InputStream createInputStream(Destination dest,
    String messageSelector,
    boolean noLocal) throws JMSException 
 public OutputStream createNonPersistentOutputStream(Destination dest) throws JMSException 
    Creates a non persistent output stream; messages will not be written to disk
 public OutputStream createOutputStream(Destination dest) throws JMSException 
    Creates a persistent output stream; individual messages will be written to disk/database by the broker
 public OutputStream createOutputStream(Destination dest,
    Map streamProperties,
    int deliveryMode,
    int priority,
    long timeToLive) throws 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.
 public QueueSession createQueueSession(boolean transacted,
    int acknowledgeMode) throws JMSException 
    Creates a QueueSession object.
 public Session createSession(boolean transacted,
    int acknowledgeMode) throws JMSException 
    Creates a Session object.
 protected ActiveMQTempDestination createTempDestination(boolean topic) throws JMSException 
    Create the DestinationInfo object for the temporary destination.
 public TopicSession createTopicSession(boolean transacted,
    int acknowledgeMode) throws JMSException 
    Creates a TopicSession object.
 public  void deleteTempDestination(ActiveMQTempDestination destination) throws JMSException 
 public  void destroyDestination(ActiveMQDestination destination) throws JMSException 
 protected synchronized  void ensureConnectionInfoSent() throws JMSException 
    Send the ConnectionInfo to the Broker
 public BlobTransferPolicy getBlobTransferPolicy() 
 public BrokerInfo getBrokerInfo() 
    Returns the broker information if it is available or null if it is not available yet.
 public String getBrokerName() 
    Returns the broker name if one is available or null if one is not available yet.
 public String getClientID() throws 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.

 public int getCloseTimeout() 
 public ConnectionInfo getConnectionInfo() 
 public JMSConnectionStatsImpl getConnectionStats() 
 public DestinationSource getDestinationSource() throws JMSException 
    Returns the DestinationSource object which can be used to listen to destinations being created or destroyed or to enquire about the current destinations available on the broker
 public ExceptionListener getExceptionListener() throws JMSException 
    Gets the ExceptionListener object for this connection. Not every Connection has an ExceptionListener associated with it.
 public String getInitializedClientID() throws JMSException 
 public LongSequenceGenerator getLocalTransactionIdGenerator() 
 public ConnectionMetaData getMetaData() throws JMSException 
    Gets the metadata for this connection.
 protected SessionId getNextSessionId() 
 public ActiveMQPrefetchPolicy getPrefetchPolicy() 
 public int getProducerWindowSize() 
 public int getProtocolVersion() 
 public RedeliveryPolicy getRedeliveryPolicy() throws JMSException 
 public String getResourceManagerId() throws JMSException 
 public int getSendTimeout() 
 public TaskRunnerFactory getSessionTaskRunner() 
 public StatsImpl getStats() 
 public long getTimeCreated() 
    Returns the time this connection was created
 public MessageTransformer getTransformer() 
 public Transport getTransport() 
 public Transport getTransportChannel() 
 public long getWarnAboutUnstartedConnectionTimeout() 
 public boolean isAlwaysSessionAsync() 
 public boolean isAlwaysSyncSend() 
 public boolean isClosed() 
    Returns true if the connection is closed
 public boolean isClosing() 
    Returns true if the connection is in the process of being closed
 public boolean isCopyMessageOnSend() 
 public boolean isDeleted(ActiveMQDestination dest) 
 public boolean isDisableTimeStampsByDefault() 
 public boolean isDispatchAsync() 
 protected boolean isDuplicate(ActiveMQDispatcher dispatcher,
    Message message) 
 public boolean isExclusiveConsumer() 
 public boolean isNestedMapAndListEnabled() 
 public boolean isObjectMessageSerializationDefered() 
 public boolean isOptimizeAcknowledge() 
 public boolean isOptimizedMessageDispatch() 
 public boolean isStarted() 
    Returns true if this connection has been started
 public boolean isStatsEnabled() 
 public boolean isTransportFailed() 
    Returns true if the underlying transport has failed
 public boolean isUseAsyncSend() 
 public boolean isUseCompression() 
 public boolean isUseRetroactiveConsumer() 
 public synchronized boolean isWatchTopicAdvisories() 
 public static ActiveMQConnection makeConnection() throws JMSException 
    A static helper method to create a new connection
 public static ActiveMQConnection makeConnection(String uri) throws JMSException, URISyntaxException 
    A static helper method to create a new connection
 public static ActiveMQConnection makeConnection(String user,
    String password,
    String uri) throws JMSException, URISyntaxException 
    A static helper method to create a new connection
 public  void onAsyncException(Throwable error) 
    Used for handling async exceptions
 public  void onCommand(Object o) 
 protected  void onConnectionControl(ConnectionControl command) 
 protected  void onConsumerControl(ConsumerControl command) 
 protected  void onControlCommand(ControlCommand command) 
 public  void onException(IOException error) 
 protected  void onWireFormatInfo(WireFormatInfo info) 
 protected  void removeConnectionConsumer(ActiveMQConnectionConsumer connectionConsumer) 
    Remove a ConnectionConsumer
 public  void removeDispatcher(ConsumerId consumerId) 
 protected  void removeDispatcher(ActiveMQDispatcher dispatcher) 
 public  void removeInputStream(ActiveMQInputStream stream) 
 public  void removeOutputStream(ActiveMQOutputStream stream) 
 public  void removeProducer(ProducerId producerId) 
 protected  void removeSession(ActiveMQSession session) 
    Used interanlly for removing Sessions from a Connection
 public  void removeTransportListener(TransportListener transportListener) 
 protected  void rollbackDuplicate(ActiveMQDispatcher dispatcher,
    Message message) 
  void send(ActiveMQDestination destination,
    ActiveMQMessage msg,
    MessageId messageId,
    int deliveryMode,
    int priority,
    long timeToLive,
    boolean async) throws JMSException 
    Internal send method optimized: - It does not copy the message - It can only handle ActiveMQ messages. - You can specify if the send is async or sync - Does not allow you to send /w a transaction.
 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
 public  void setAlwaysSyncSend(boolean alwaysSyncSend) 
    Set true if always require messages to be sync sent
 public  void setBlobTransferPolicy(BlobTransferPolicy blobTransferPolicy) 
    Sets the policy used to describe how out-of-band BLOBs (Binary Large OBjects) are transferred from producers to brokers to consumers
 public  void setClientID(String newClientID) throws 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.

 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
 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
 public  void setDefaultClientID(String clientID) throws JMSException 
    Sets the default client id that the connection will use if explicitly not set with the setClientId() call.
 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.
 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.
 public  void setExceptionListener(ExceptionListener listener) throws 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.

 public  void setExclusiveConsumer(boolean exclusiveConsumer) 
    Enables or disables whether or not queue consumers should be exclusive or not for example to preserve ordering when not using Message Groups
 public  void setNestedMapAndListEnabled(boolean structuredMapsEnabled) 
    Enables/disables whether or not Message properties and MapMessage entries support Nested Structures of Map and List objects
 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.
 public  void setOptimizeAcknowledge(boolean optimizeAcknowledge) 
    Enables an optimised acknowledgement mode where messages are acknowledged in batches rather than individually
 public  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) 
 public  void setPrefetchPolicy(ActiveMQPrefetchPolicy prefetchPolicy) 
 public  void setProducerWindowSize(int producerWindowSize) 
 public  void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy) 
    Sets the redelivery policy to be used when messages are rolled back
 public  void setSendTimeout(int sendTimeout) 
 public  void setSessionTaskRunner(TaskRunnerFactory sessionTaskRunner) 
 public  void setStatsEnabled(boolean statsEnabled) 
 public  void setTransformer(MessageTransformer transformer) 
    Sets the transformer used to transform messages before they are sent on to the JMS bus or when they are received from the bus but before they are delivered to the JMS client
 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.
 public  void setUseCompression(boolean useCompression) 
    Enables the use of compression of the message bodies
 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.
 protected  void setUserName(String userName) 
 public  void setWarnAboutUnstartedConnectionTimeout(long warnAboutUnstartedConnectionTimeout) 
    Enables the timeout from a connection creation to when a warning is generated if the connection is not properly started via #start() and a message is received by a consumer. It is a very common gotcha to forget to start the connection so this option makes the default case to create a warning if the user forgets. To disable the warning just set the value to < 0 (say -1).
 public synchronized  void setWatchTopicAdvisories(boolean watchTopicAdvisories) 
 public  void start() throws 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.
 public  void stop() throws 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.

 public Response syncSendPacket(Command command) throws JMSException 
    Send a packet through a Connection - for internal use only
 public Response syncSendPacket(Command command,
    int timeout) throws JMSException 
    Send a packet through a Connection - for internal use only
 public String toString() 
 protected  void transportFailed(IOException error) 
 public  void transportInterupted() 
 public  void transportResumed() 
 public  void unsubscribe(String name) throws 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.