Class JmsConnection

java.lang.Object
org.apache.qpid.jms.JmsConnection
All Implemented Interfaces:
jakarta.jms.Connection, jakarta.jms.QueueConnection, jakarta.jms.TopicConnection, AutoCloseable, ProviderListener
Direct Known Subclasses:
JmsQueueConnection, JmsTopicConnection

public class JmsConnection extends Object implements AutoCloseable, jakarta.jms.Connection, jakarta.jms.TopicConnection, jakarta.jms.QueueConnection, ProviderListener
Implementation of a JMS Connection
  • Constructor Details

    • JmsConnection

      protected JmsConnection(JmsConnectionInfo connectionInfo, Provider provider) throws jakarta.jms.JMSException
      Throws:
      jakarta.jms.JMSException
  • Method Details

    • close

      public void close() throws jakarta.jms.JMSException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • shutdown

      protected void shutdown() throws jakarta.jms.JMSException
      Called to free all Connection resources.
      Throws:
      jakarta.jms.JMSException
    • shutdown

      protected void shutdown(Exception cause) throws jakarta.jms.JMSException
      Called to free all Connection resources.
      Throws:
      jakarta.jms.JMSException
    • createSession

      public jakarta.jms.Session createSession() throws jakarta.jms.JMSException
      Specified by:
      createSession in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • createSession

      public jakarta.jms.Session createSession(int acknowledgeMode) throws jakarta.jms.JMSException
      Specified by:
      createSession in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • createSession

      public jakarta.jms.Session createSession(boolean transacted, int acknowledgeMode) throws jakarta.jms.JMSException
      Specified by:
      createSession in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • getClientID

      public String getClientID() throws jakarta.jms.JMSException
      Specified by:
      getClientID in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • getMetaData

      public jakarta.jms.ConnectionMetaData getMetaData() throws jakarta.jms.JMSException
      Specified by:
      getMetaData in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • setClientID

      public void setClientID(String clientID) throws jakarta.jms.JMSException
      Specified by:
      setClientID in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • start

      public void start() throws jakarta.jms.JMSException
      Specified by:
      start in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • stop

      public void stop() throws jakarta.jms.JMSException
      Specified by:
      stop in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • createSharedConnectionConsumer

      public jakarta.jms.ConnectionConsumer createSharedConnectionConsumer(jakarta.jms.Topic topic, String subscriptionName, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) throws jakarta.jms.JMSException
      Specified by:
      createSharedConnectionConsumer in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • createSharedDurableConnectionConsumer

      public jakarta.jms.ConnectionConsumer createSharedDurableConnectionConsumer(jakarta.jms.Topic topic, String subscriptionName, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) throws jakarta.jms.JMSException
      Specified by:
      createSharedDurableConnectionConsumer in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • createDurableConnectionConsumer

      public jakarta.jms.ConnectionConsumer createDurableConnectionConsumer(jakarta.jms.Topic topic, String subscriptionName, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) throws jakarta.jms.JMSException
      Specified by:
      createDurableConnectionConsumer in interface jakarta.jms.Connection
      Specified by:
      createDurableConnectionConsumer in interface jakarta.jms.TopicConnection
      Throws:
      jakarta.jms.JMSException
    • createConnectionConsumer

      public jakarta.jms.ConnectionConsumer createConnectionConsumer(jakarta.jms.Destination destination, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) throws jakarta.jms.JMSException
      Specified by:
      createConnectionConsumer in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • createConnectionConsumer

      public jakarta.jms.ConnectionConsumer createConnectionConsumer(jakarta.jms.Topic topic, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) throws jakarta.jms.JMSException
      Specified by:
      createConnectionConsumer in interface jakarta.jms.TopicConnection
      Throws:
      jakarta.jms.JMSException
    • createConnectionConsumer

      public jakarta.jms.ConnectionConsumer createConnectionConsumer(jakarta.jms.Queue queue, String messageSelector, jakarta.jms.ServerSessionPool sessionPool, int maxMessages) throws jakarta.jms.JMSException
      Specified by:
      createConnectionConsumer in interface jakarta.jms.QueueConnection
      Throws:
      jakarta.jms.JMSException
    • createTopicSession

      public jakarta.jms.TopicSession createTopicSession(boolean transacted, int acknowledgeMode) throws jakarta.jms.JMSException
      Specified by:
      createTopicSession in interface jakarta.jms.TopicConnection
      Throws:
      jakarta.jms.JMSException
    • createQueueSession

      public jakarta.jms.QueueSession createQueueSession(boolean transacted, int acknowledgeMode) throws jakarta.jms.JMSException
      Specified by:
      createQueueSession in interface jakarta.jms.QueueConnection
      Throws:
      jakarta.jms.JMSException
    • onException

      public void onException(Exception ex)
    • onException

      public void onException(jakarta.jms.JMSException ex)
    • getSessionAcknowledgeMode

      protected int getSessionAcknowledgeMode(boolean transacted, int acknowledgeMode) throws jakarta.jms.JMSException
      Throws:
      jakarta.jms.JMSException
    • removeSession

      protected void removeSession(JmsSessionInfo sessionInfo)
    • addSession

      protected void addSession(JmsSessionInfo sessionInfo, JmsSession session)
    • removeConnectionConsumer

      protected void removeConnectionConsumer(JmsConsumerInfo consumerInfo)
    • addConnectionConsumer

      protected void addConnectionConsumer(JmsConsumerInfo consumerInfo, JmsConnectionConsumer consumer)
    • createTemporaryQueue

      protected jakarta.jms.TemporaryQueue createTemporaryQueue() throws jakarta.jms.JMSException
      Returns:
      a newly initialized TemporaryQueue instance.
      Throws:
      jakarta.jms.JMSException
    • createTemporaryTopic

      protected jakarta.jms.TemporaryTopic createTemporaryTopic() throws jakarta.jms.JMSException
      Returns:
      a newly initialized TemporaryTopic instance.
      Throws:
      jakarta.jms.JMSException
    • deleteTemporaryDestination

      protected void deleteTemporaryDestination(JmsTemporaryDestination destination) throws jakarta.jms.JMSException
      Throws:
      jakarta.jms.JMSException
    • checkClosedOrFailed

      protected void checkClosedOrFailed() throws jakarta.jms.JMSException
      Throws:
      jakarta.jms.JMSException
    • checkConsumeFromTemporaryDestination

      protected void checkConsumeFromTemporaryDestination(JmsTemporaryDestination destination) throws jakarta.jms.JMSException
      Throws:
      jakarta.jms.JMSException
    • isTemporaryDestinationDeleted

      protected boolean isTemporaryDestinationDeleted(JmsDestination destination)
    • checkClosed

      protected void checkClosed() throws jakarta.jms.IllegalStateException
      Throws:
      jakarta.jms.IllegalStateException
    • getNextSessionId

      protected JmsSessionId getNextSessionId()
    • getNextTransactionId

      protected JmsTransactionId getNextTransactionId()
    • getNextConnectionConsumerId

      protected JmsConsumerId getNextConnectionConsumerId()
    • isExplicitClientID

      protected boolean isExplicitClientID()
    • getExceptionListener

      public jakarta.jms.ExceptionListener getExceptionListener() throws jakarta.jms.JMSException
      Specified by:
      getExceptionListener in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • setExceptionListener

      public void setExceptionListener(jakarta.jms.ExceptionListener listener) throws jakarta.jms.JMSException
      Specified by:
      setExceptionListener in interface jakarta.jms.Connection
      Throws:
      jakarta.jms.JMSException
    • addConnectionListener

      public void addConnectionListener(JmsConnectionListener listener)
      Adds a JmsConnectionListener so that a client can be notified of events in the underlying connection and its state.
      Parameters:
      listener - the new listener to add to the collection.
    • removeConnectionListener

      public boolean removeConnectionListener(JmsConnectionListener listener)
      Removes a JmsConnectionListener that was previously registered.
      Parameters:
      listener - the listener to remove from the collection.
      Returns:
      true if the given listener was removed from the current set.
    • isForceAsyncSend

      public boolean isForceAsyncSend()
    • setForceAsyncSend

      public void setForceAsyncSend(boolean forceAsyncSend)
    • isForceSyncSend

      public boolean isForceSyncSend()
    • setForceSyncSend

      public void setForceSyncSend(boolean alwaysSyncSend)
    • getTopicPrefix

      public String getTopicPrefix()
    • setTopicPrefix

      public void setTopicPrefix(String topicPrefix)
    • getQueuePrefix

      public String getQueuePrefix()
    • setQueuePrefix

      public void setQueuePrefix(String queuePrefix)
    • isValidatePropertyNames

      public boolean isValidatePropertyNames()
    • setValidatePropertyNames

      public void setValidatePropertyNames(boolean validatePropertyNames)
    • isValidateSelector

      public boolean isValidateSelector()
    • setValidateSelector

      public void setValidateSelector(boolean validateSelector)
    • getPrefetchPolicy

      public JmsPrefetchPolicy getPrefetchPolicy()
    • setPrefetchPolicy

      public void setPrefetchPolicy(JmsPrefetchPolicy prefetchPolicy)
    • getRedeliveryPolicy

      public JmsRedeliveryPolicy getRedeliveryPolicy()
    • setRedeliveryPolicy

      public void setRedeliveryPolicy(JmsRedeliveryPolicy redeliveryPolicy)
    • getPresettlePolicy

      public JmsPresettlePolicy getPresettlePolicy()
    • setPresettlePolicy

      public void setPresettlePolicy(JmsPresettlePolicy presettlePolicy)
    • getDeserializationPolicy

      public JmsDeserializationPolicy getDeserializationPolicy()
    • setDeserializationPolicy

      public void setDeserializationPolicy(JmsDeserializationPolicy deserializationPolicy)
    • isReceiveLocalOnly

      public boolean isReceiveLocalOnly()
    • setReceiveLocalOnly

      public void setReceiveLocalOnly(boolean receiveLocalOnly)
    • isReceiveNoWaitLocalOnly

      public boolean isReceiveNoWaitLocalOnly()
    • setReceiveNoWaitLocalOnly

      public void setReceiveNoWaitLocalOnly(boolean receiveNoWaitLocalOnly)
    • isLocalMessagePriority

      public boolean isLocalMessagePriority()
    • setLocalMessagePriority

      public void setLocalMessagePriority(boolean localMessagePriority)
    • getCloseTimeout

      public long getCloseTimeout()
    • setCloseTimeout

      public void setCloseTimeout(long closeTimeout)
    • getConnectTimeout

      public long getConnectTimeout()
    • setConnectTimeout

      public void setConnectTimeout(long connectTimeout)
    • getSendTimeout

      public long getSendTimeout()
    • setSendTimeout

      public void setSendTimeout(long sendTimeout)
    • getRequestTimeout

      public long getRequestTimeout()
    • setRequestTimeout

      public void setRequestTimeout(long requestTimeout)
    • getConfiguredURI

      public URI getConfiguredURI()
    • getConnectedURI

      public URI getConnectedURI()
    • getUsername

      public String getUsername()
    • getPassword

      public String getPassword()
    • isConnected

      public boolean isConnected()
    • isStarted

      public boolean isStarted()
    • isClosed

      public boolean isClosed()
    • isFailed

      public boolean isFailed()
    • getId

      public JmsConnectionId getId()
    • getMessageFactory

      public JmsMessageFactory getMessageFactory()
    • isForceAsyncAcks

      public boolean isForceAsyncAcks()
    • setForceAsyncAcks

      public void setForceAsyncAcks(boolean forceAsyncAcks)
    • isLocalMessageExpiry

      public boolean isLocalMessageExpiry()
    • setLocalMessageExpiry

      public void setLocalMessageExpiry(boolean localMessageExpiry)
    • getMessageIDPolicy

      public JmsMessageIDPolicy getMessageIDPolicy()
    • setMessageIDPolicy

      public void setMessageIDPolicy(JmsMessageIDPolicy messageIDPolicy)
    • isPopulateJMSXUserID

      public boolean isPopulateJMSXUserID()
    • setPopulateJMSXUserID

      public void setPopulateJMSXUserID(boolean populateJMSXUserID)
    • isUseDaemonThread

      public boolean isUseDaemonThread()
    • isCloseLinksThatFailOnReconnect

      public boolean isCloseLinksThatFailOnReconnect()
    • setCloseLinksThatFailOnReconnect

      public void setCloseLinksThatFailOnReconnect(boolean closeLinksThatFailOnReconnect)
    • onInboundMessage

      public void onInboundMessage(JmsInboundMessageDispatch envelope)
      Description copied from interface: ProviderListener
      Called when a new Message has arrived for a registered consumer.
      Specified by:
      onInboundMessage in interface ProviderListener
      Parameters:
      envelope - The dispatch object containing the message and delivery information.
    • onCompletedMessageSend

      public void onCompletedMessageSend(JmsOutboundMessageDispatch envelope)
      Description copied from interface: ProviderListener
      Called when an outbound message dispatch that requested a completion callback has reached a state where the send can be considered successful based on the QoS level associated of the outbound message.
      Specified by:
      onCompletedMessageSend in interface ProviderListener
      Parameters:
      envelope - the original outbound message dispatch that is now complete.
    • onFailedMessageSend

      public void onFailedMessageSend(JmsOutboundMessageDispatch envelope, ProviderException cause)
      Description copied from interface: ProviderListener
      Called when an outbound message dispatch that requested a completion callback has reached a state where the send can be considered failed.
      Specified by:
      onFailedMessageSend in interface ProviderListener
      Parameters:
      envelope - the original outbound message dispatch that should be treated as a failed send.
      cause - the exception that describes the cause of the failed send.
    • onConnectionInterrupted

      public void onConnectionInterrupted(URI remoteURI)
      Description copied from interface: ProviderListener
      Called from a fault tolerant Provider instance to signal that the underlying connection to the Broker has been lost. The Provider will attempt to reconnect following this event unless closed. It is considered a programming error to allow any exceptions to be thrown from this notification method.
      Specified by:
      onConnectionInterrupted in interface ProviderListener
      Parameters:
      remoteURI - The URI of the Broker whose connection was lost.
    • onConnectionRecovery

      public void onConnectionRecovery(Provider provider) throws Exception
      Description copied from interface: ProviderListener
      Called to indicate that a connection to the Broker has been reestablished and that notified listener should start to recover it's state. The provider will not transition to the recovered state until the listener notifies the provider that recovery is complete.
      Specified by:
      onConnectionRecovery in interface ProviderListener
      Parameters:
      provider - The new Provider instance that will become active after the state has been recovered.
      Throws:
      Exception - if an error occurs during recovery attempt, this will fail the Provider that's being used for recovery.
    • onConnectionRecovered

      public void onConnectionRecovered(Provider provider) throws Exception
      Description copied from interface: ProviderListener
      Called to indicate that a connection to the Broker has been reestablished and that all recovery operations have succeeded and the connection will now be transitioned to a recovered state. This method gives the listener a chance so send any necessary post recovery commands such as consumer start or message pull for a zero prefetch consumer etc.
      Specified by:
      onConnectionRecovered in interface ProviderListener
      Parameters:
      provider - The new Provider instance that will become active after the state has been recovered.
      Throws:
      Exception - if an error occurs during recovery attempt, this will fail the Provider that's being used for recovery.
    • onConnectionRestored

      public void onConnectionRestored(URI remoteURI)
      Description copied from interface: ProviderListener
      Called to signal that all recovery operations are now complete and the Provider is again in a normal connected state. It is considered a programming error to allow any exceptions to be thrown from this notification method.
      Specified by:
      onConnectionRestored in interface ProviderListener
      Parameters:
      remoteURI - The URI of the Broker that the client has now connected to.
    • onConnectionEstablished

      public void onConnectionEstablished(URI remoteURI)
      Description copied from interface: ProviderListener
      Called to indicate that the underlying connection to the Broker has been established for the first time. For a fault tolerant provider this event should only ever be triggered once with the interruption and recovery events following on for future
      Specified by:
      onConnectionEstablished in interface ProviderListener
      Parameters:
      remoteURI - The URI of the Broker that the client has now connected to.
    • onConnectionFailure

      public void onConnectionFailure(ProviderException ex)
      Description copied from interface: ProviderListener
      Called to indicate that the underlying connection to the Broker has been lost and the Provider will not perform any reconnect. Following this call the provider is in a failed state and further calls to it will throw an Exception.
      Specified by:
      onConnectionFailure in interface ProviderListener
      Parameters:
      ex - The exception that indicates the cause of this Provider failure.
    • onResourceClosed

      public void onResourceClosed(JmsResource resource, ProviderException cause)
      Description copied from interface: ProviderListener
      Called to indicate that a currently active resource has been closed due to some error condition, management request or some other action. This can either be initiated remotely or locally depending on the condition that triggers the close.
      Specified by:
      onResourceClosed in interface ProviderListener
      Parameters:
      resource - the JmsResource instance that has been closed.
      cause - optional exception object that indicates the cause of the close.
    • onProviderException

      public void onProviderException(ProviderException cause)
      Description copied from interface: ProviderListener
      Called to indicate that a some client operation caused or received an error that is not considered fatal at the provider level.
      Specified by:
      onProviderException in interface ProviderListener
      Parameters:
      cause - the exception object that is being reported to the listener.
    • onAsyncException

      public void onAsyncException(Throwable error)
      Handles any asynchronous errors that occur from the JMS framework classes. If any listeners are registered they will be notified of the error from a thread in the Connection's Executor service.
      Parameters:
      error - The exception that triggered this error.
    • providerFailed

      protected void providerFailed(ProviderException cause)