Class JmsConnectionFactory

java.lang.Object
org.apache.qpid.jms.jndi.JNDIStorable
org.apache.qpid.jms.JmsConnectionFactory
All Implemented Interfaces:
jakarta.jms.ConnectionFactory, jakarta.jms.QueueConnectionFactory, jakarta.jms.TopicConnectionFactory, Externalizable, Serializable, Referenceable

public class JmsConnectionFactory extends JNDIStorable implements jakarta.jms.ConnectionFactory, jakarta.jms.QueueConnectionFactory, jakarta.jms.TopicConnectionFactory
JMS ConnectionFactory Implementation.
See Also:
  • Field Details

  • Constructor Details

    • JmsConnectionFactory

      public JmsConnectionFactory()
    • JmsConnectionFactory

      public JmsConnectionFactory(String username, String password)
    • JmsConnectionFactory

      public JmsConnectionFactory(String remoteURI)
    • JmsConnectionFactory

      public JmsConnectionFactory(String userName, String password, String remoteURI)
    • JmsConnectionFactory

      public JmsConnectionFactory(URI remoteURI)
    • JmsConnectionFactory

      public JmsConnectionFactory(String userName, String password, URI remoteURI)
  • Method Details

    • buildFromProperties

      protected Map<String,String> buildFromProperties(Map<String,String> props)
      Description copied from class: JNDIStorable
      Set the properties that will represent the instance in JNDI
      Specified by:
      buildFromProperties in class JNDIStorable
      Parameters:
      props - The properties to use when building the new isntance.
      Returns:
      a new, unmodifiable, map containing any unused properties, or empty if none were.
    • populateProperties

      protected void populateProperties(Map<String,String> props)
      Description copied from class: JNDIStorable
      Initialize the instance from properties stored in JNDI
      Specified by:
      populateProperties in class JNDIStorable
      Parameters:
      props - The properties to use when initializing the new instance.
    • createTopicConnection

      public jakarta.jms.TopicConnection createTopicConnection() throws jakarta.jms.JMSException
      Specified by:
      createTopicConnection in interface jakarta.jms.TopicConnectionFactory
      Throws:
      jakarta.jms.JMSException
    • createTopicConnection

      public jakarta.jms.TopicConnection createTopicConnection(String username, String password) throws jakarta.jms.JMSException
      Specified by:
      createTopicConnection in interface jakarta.jms.TopicConnectionFactory
      Throws:
      jakarta.jms.JMSException
    • createConnection

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

      public jakarta.jms.Connection createConnection(String username, String password) throws jakarta.jms.JMSException
      Specified by:
      createConnection in interface jakarta.jms.ConnectionFactory
      Throws:
      jakarta.jms.JMSException
    • createQueueConnection

      public jakarta.jms.QueueConnection createQueueConnection() throws jakarta.jms.JMSException
      Specified by:
      createQueueConnection in interface jakarta.jms.QueueConnectionFactory
      Throws:
      jakarta.jms.JMSException
    • createQueueConnection

      public jakarta.jms.QueueConnection createQueueConnection(String username, String password) throws jakarta.jms.JMSException
      Specified by:
      createQueueConnection in interface jakarta.jms.QueueConnectionFactory
      Throws:
      jakarta.jms.JMSException
    • configureConnectionInfo

      protected JmsConnectionInfo configureConnectionInfo(String username, String password) throws jakarta.jms.JMSException
      Throws:
      jakarta.jms.JMSException
    • createContext

      public jakarta.jms.JMSContext createContext()
      Specified by:
      createContext in interface jakarta.jms.ConnectionFactory
    • createContext

      public jakarta.jms.JMSContext createContext(int sessionMode)
      Specified by:
      createContext in interface jakarta.jms.ConnectionFactory
    • createContext

      public jakarta.jms.JMSContext createContext(String username, String password)
      Specified by:
      createContext in interface jakarta.jms.ConnectionFactory
    • createContext

      public jakarta.jms.JMSContext createContext(String username, String password, int sessionMode)
      Specified by:
      createContext in interface jakarta.jms.ConnectionFactory
    • createProvider

      protected Provider createProvider(URI remoteURI) throws Exception
      Throws:
      Exception
    • createURI

      protected static URI createURI(String name)
    • getConnectionIdGenerator

      protected IdGenerator getConnectionIdGenerator()
    • setConnectionIdGenerator

      protected void setConnectionIdGenerator(IdGenerator connectionIdGenerator)
    • getRemoteURI

      public String getRemoteURI()
      Returns:
      the remoteURI
    • setRemoteURI

      public void setRemoteURI(String remoteURI)
      Parameters:
      remoteURI - the remoteURI to set
    • getUsername

      public String getUsername()
      Returns:
      the user name used for connection authentication.
    • setUsername

      public void setUsername(String username)
      Parameters:
      username - the user name to set
    • getPassword

      public String getPassword()
      Returns:
      the password set for connection authentication.
    • setPassword

      public void setPassword(String password)
      Parameters:
      password - the password to set
    • isForceSyncSend

      public boolean isForceSyncSend()
      Returns true if the client should always send messages using a synchronous send operation regardless of persistence mode, or inside a transaction.
      Returns:
      true if sends should always be done synchronously.
    • setForceSyncSend

      public void setForceSyncSend(boolean forceSyncSend)
      Configures whether or not the client will always send messages synchronously or not regardless of other factors that might result in an asynchronous send.
      Parameters:
      forceSyncSend - if true sends are always done synchronously.
    • isForceAsyncSend

      public boolean isForceAsyncSend()
    • setForceAsyncSend

      public void setForceAsyncSend(boolean forceAsyncSend)
    • isLocalMessagePriority

      public boolean isLocalMessagePriority()
      Returns:
      the localMessagePriority configuration option.
    • setLocalMessagePriority

      public void setLocalMessagePriority(boolean localMessagePriority)
      Enables client-side message priority support in MessageConsumer instances. This results in all prefetched messages being dispatched in priority order.
      Parameters:
      localMessagePriority - the messagePrioritySupported to set
    • getQueuePrefix

      public String getQueuePrefix()
      Returns the prefix applied to Queues that are created by the client.
      Returns:
      the currently configured Queue prefix.
    • setQueuePrefix

      public void setQueuePrefix(String queuePrefix)
    • getTopicPrefix

      public String getTopicPrefix()
      Returns the prefix applied to Topics that are created by the client.
      Returns:
      the currently configured Topic prefix.
    • setTopicPrefix

      public void setTopicPrefix(String topicPrefix)
    • isValidatePropertyNames

      public boolean isValidatePropertyNames()
    • setValidatePropertyNames

      public void setValidatePropertyNames(boolean validatePropertyNames)
    • isValidateSelector

      public boolean isValidateSelector()
    • setValidateSelector

      public void setValidateSelector(boolean validateSelector)
      Sets whether local validation is performed of a consumers message selector string conforming to the JMS selector syntax. Default is true.
      Parameters:
      validateSelector - whether to validate consumer message selector strings
    • getCloseTimeout

      public long getCloseTimeout()
      Gets the currently set close timeout.
      Returns:
      the currently set close timeout.
    • setCloseTimeout

      public void setCloseTimeout(long closeTimeout)
      Sets the close timeout used to control how long a Connection close will wait for clean shutdown of the connection before giving up. A negative value means wait forever. Care should be taken in that a very short close timeout can cause the client to not cleanly shutdown the connection and it's resources.
      Parameters:
      closeTimeout - time in milliseconds to wait for a clean connection close.
    • getConnectTimeout

      public long getConnectTimeout()
      Returns the currently configured wire level connect timeout.
      Returns:
      the currently configured wire level connect timeout.
    • setConnectTimeout

      public void setConnectTimeout(long connectTimeout)
      Sets the timeout value used to control how long a client will wait for a successful connection to the remote peer to be established before considering the attempt to have failed. This value does not control socket level connection timeout but rather connection handshake at the wire level, to control the socket level timeouts use the standard socket options configuration values.
      Parameters:
      connectTimeout - the time in milliseconds to wait for the protocol connection handshake to complete.
    • getSendTimeout

      public long getSendTimeout()
    • setSendTimeout

      public void setSendTimeout(long sendTimeout)
    • getRequestTimeout

      public long getRequestTimeout()
    • setRequestTimeout

      public void setRequestTimeout(long requestTimeout)
    • getPrefetchPolicy

      public JmsPrefetchPolicy getPrefetchPolicy()
    • setPrefetchPolicy

      public void setPrefetchPolicy(JmsPrefetchPolicy prefetchPolicy)
    • getRedeliveryPolicy

      public JmsRedeliveryPolicy getRedeliveryPolicy()
      Returns the JmsRedeliveryPolicy that is applied when a new connection is created.
      Returns:
      the redeliveryPolicy that is currently configured for this factory.
    • setRedeliveryPolicy

      public void setRedeliveryPolicy(JmsRedeliveryPolicy redeliveryPolicy)
      Sets the JmsRedeliveryPolicy that is applied when a new connection is created.
      Parameters:
      redeliveryPolicy - The new redeliveryPolicy to set
    • getPresettlePolicy

      public JmsPresettlePolicy getPresettlePolicy()
      Returns:
      the presettlePolicy that is currently configured.
    • setPresettlePolicy

      public void setPresettlePolicy(JmsPresettlePolicy presettlePolicy)
      Sets the JmsPresettlePolicy that is applied to MessageProducers.
      Parameters:
      presettlePolicy - the presettlePolicy to use by connections created from this factory.
    • getMessageIDPolicy

      public JmsMessageIDPolicy getMessageIDPolicy()
      Returns:
      the messageIDPolicy that is currently configured.
    • setMessageIDPolicy

      public void setMessageIDPolicy(JmsMessageIDPolicy messageIDPolicy)
      Sets the JmsMessageIDPolicy that is use to configure the JmsMessageIDBuilder that is assigned to any new MessageProducer created from Connection instances that this factory has created.
      Parameters:
      messageIDPolicy - the messageIDPolicy to use by connections created from this factory.
    • getDeserializationPolicy

      public JmsDeserializationPolicy getDeserializationPolicy()
      Returns:
      the deserializationPolicy that is currently configured.
    • setDeserializationPolicy

      public void setDeserializationPolicy(JmsDeserializationPolicy deserializationPolicy)
      Sets the JmsDeserializationPolicy that is applied when a new connection is created.
      Parameters:
      deserializationPolicy - the deserializationPolicy that will be applied to new connections.
    • getClientIDPrefix

      public String getClientIDPrefix()
      Returns:
      the currently configured client ID prefix for auto-generated client IDs.
    • setClientIDPrefix

      public void setClientIDPrefix(String clientIDPrefix)
      Sets the prefix used by auto-generated JMS Client ID values which are used if the JMS client does not explicitly specify one.
      Parameters:
      clientIDPrefix - the value to use as a prefix on auto-generated client IDs.
    • getClientIdGenerator

      protected IdGenerator getClientIdGenerator()
    • setClientIdGenerator

      protected void setClientIdGenerator(IdGenerator clientIdGenerator)
    • getClientID

      public String getClientID()
    • setClientID

      public void setClientID(String clientID)
      Sets the JMS clientID to use for connections created by this factory. NOTE: A clientID can only be used by one Connection at a time, so setting it here will restrict the ConnectionFactory to creating a single open Connection at a time. It is possible to set the clientID on the Connection itself immediately after creation if no value has been set via the factory that created it, which will allow the factory to create multiple open connections at a time.
      Parameters:
      clientID - The clientID to assign when creating a new connection.
    • setConnectionIDPrefix

      public void setConnectionIDPrefix(String connectionIDPrefix)
      Sets the prefix used by connection id generator.
      Parameters:
      connectionIDPrefix - The string prefix used on all connection Id's created by this factory.
    • getExceptionListener

      public jakarta.jms.ExceptionListener getExceptionListener()
      Gets the currently configured JMS ExceptionListener that will be set on all new Connection objects created from this factory. NOTE: the listener object is not saved when serializing the factory.
      Returns:
      the currently configured JMS ExceptionListener.
    • setExceptionListener

      public void setExceptionListener(jakarta.jms.ExceptionListener exceptionListener)
      Sets the JMS ExceptionListener that will be set on all new Connection objects created from this factory.
      Parameters:
      exceptionListener - the JMS ExceptionListener to apply to new Connection's or null to clear.
    • isForceAsyncAcks

      public boolean isForceAsyncAcks()
      Returns:
      true if consumer acknowledgments are sent asynchronously or not.
    • setForceAsyncAcks

      public void setForceAsyncAcks(boolean forceAsyncAcks)
      Should the message acknowledgments from a consumer be sent synchronously or asynchronously. Sending the acknowledgments asynchronously can increase the performance of a consumer but opens up the possibility of a missed message acknowledge should the connection be unstable.
      Parameters:
      forceAsyncAcks - true to have the client send all message acknowledgments asynchronously.
    • isLocalMessageExpiry

      public boolean isLocalMessageExpiry()
      Returns:
      true if MessageConsumer instance will check for expired messages locally before dispatch.
    • setLocalMessageExpiry

      public void setLocalMessageExpiry(boolean localMessageExpiry)
      Controls whether message expiration checking is done locally (in addition to any broker side checks) in each MessageConsumer prior to dispatching a message. Disabling this check can lead to consumption of expired messages.
      Parameters:
      localMessageExpiry - controls whether expiration checking is done prior to dispatch.
    • isReceiveLocalOnly

      public boolean isReceiveLocalOnly()
    • setReceiveLocalOnly

      public void setReceiveLocalOnly(boolean receiveLocalOnly)
      Controls whether the client only checks its local message buffer when using receive calls with a timeout, or will instead drain remaining credit from the remote peer to ensure there are really no messages available if the timeout expires before a message arrives in the consumers local buffer.
      Parameters:
      receiveLocalOnly - true if receive calls with a timeout should only check the local message buffer.
    • isReceiveNoWaitLocalOnly

      public boolean isReceiveNoWaitLocalOnly()
    • setReceiveNoWaitLocalOnly

      public void setReceiveNoWaitLocalOnly(boolean receiveNoWaitLocalOnly)
      Controls whether the client only checks its local message buffer when using receiveNoWait calls, or will instead drain remaining credit from the remote peer synchronously to ensure there are really no messages available that have yet to arrive in the consumers local buffer.
      Parameters:
      receiveNoWaitLocalOnly - true if receiveNoWait calls should only check the local message buffer.
    • isPopulateJMSXUserID

      public boolean isPopulateJMSXUserID()
    • setPopulateJMSXUserID

      public void setPopulateJMSXUserID(boolean populateJMSXUserID)
      Controls whether message sent from the Connection will have the JMSXUserID message property populated with the authenticated user ID of the Connection. When false all messages sent from the Connection will not carry any value in the JMSXUserID property regardless of it being manually set on the Message to prevent a client spoofing the JMSXUserID value.
      Parameters:
      populateJMSXUserID - true if message sent from this connection should have the JMSXUserID value populated.
    • setSslContext

      public void setSslContext(SSLContext sslContext)
      Sets an SSLContext to use when creating an SSL/TLS secured connection with this factory. The URI must still be configured to indicate a secure connection should be created. Using this method overrides the effect of URI/System property configuration relating to the location/credentials/type of SSL key/trust stores and whether to trust all certificates or use a particular keyAlias.
      Parameters:
      sslContext - the sslContext to use, or null to respect the URI/System property configuration again.
    • isAwaitClientID

      public boolean isAwaitClientID()
    • setAwaitClientID

      public void setAwaitClientID(boolean awaitClientID)
      Controls whether the client will wait for a ClientID value to be set or the Connection to be used before it will attempt to complete the AMQP connection Open process.

      By default a newly created Connection that does not have a ClientID configured in the URI will wait until a call to setClientID or some other interaction with the Connection API occurs before finishing the AMQP connection Open process with the remote peer. In some cases if this takes too long the remote can disconnect as a way of defending against denial of service attacks. If the user does not plan on setting a ClientID then this option allows for immediate AMQP connection Open completion and avoids the case where the remote peer might drop the Connection if it isn't used promptly.

      This value defaults to true.

      Parameters:
      awaitClientID - the whether to wait for the client ID to be set before activating the connection.
    • isUseDaemonThread

      public boolean isUseDaemonThread()
    • setUseDaemonThread

      public void setUseDaemonThread(boolean useDaemonThread)
      Sets whether the Connection created will ensure that there is at least one non-daemon thread running at all times.
      Parameters:
      useDaemonThread - controls whether the Connection maintains a non-daemon thread.
    • isCloseLinksThatFailOnReconnect

      public boolean isCloseLinksThatFailOnReconnect()
      Returns:
      whether links that fail to be created during failover reconnect are closed or not.
    • setCloseLinksThatFailOnReconnect

      public void setCloseLinksThatFailOnReconnect(boolean closeLinksThatFailOnReconnect)
      Controls how the client manages errors on recreation of a link (producer / consumer) during a failover reconnect attempt (defaults to false).

      When false the failure of a link recreation operation while reestablishing a failed connection results in the client failing that reconnect attempt and retrying the entire connection process again. This can be disabled by setting this option to true in which case the client will close the producer or consumer associated with the failed link create attempt and continue rebuilding the client resources for the newly reestablished connection. When failing a consumer link the client will trigger the ExceptionListener assigned to the Connection if the link that failed was a consumer and that consumer had an associated JMS MessageListener.

      Parameters:
      closeLinksThatFailOnReconnect - whether to close links that fail to establish on failover reconnect.
    • setExtension

      public void setExtension(String extensionName, BiFunction<jakarta.jms.Connection,URI,Object> extension)
      Provides an entry point for extensions to be configured on this ConnectionFactory.

      If a previous extension with the same name is present it is replaced with the new value or cleared if the value is null.

      Parameters:
      extensionName - The name of the extension point being added.
      extension - The Function that implements the extension.
      See Also:
    • setTracing

      public void setTracing(String tracing)
      Sets the type name for a tracing provider to use for the connection(s) created using the factory.
      Parameters:
      tracing - The tracing provider type name to set
    • getTracing

      public String getTracing()
    • setTracer

      public void setTracer(JmsTracer tracer)
      Explicitly sets a tracer instance for use by the connection(s) created from the factory. Using this method overrides any implicit creation of a tracer due to use of either URI configuration option or the setTracing(String) method. The provided tracer will have its close method called when a created connection/context is closed, so if a tracer is to be used across multiple such connections created by this factory then the close method should handle that appropriately, e.g no-op and have the application and/or underlying tracing implementation cleanup at shutdown. If no Connection/JMSContext object is returned from a creation attempt due to an exception being thrown, the tracer provided will not have its close method called and the application or underlying tracing implementation is responsible for any cleanup required.
      Parameters:
      tracer - The tracer to set
    • getTracer

      public JmsTracer getTracer()
      Gets any tracer previously set explicitly on the connection factory using setTracer(JmsTracer). Does not return any tracer created implicitly due to use of either URI configuration option or the setTracing(String) method.
      Returns:
      the tracer previously set, or null if none was set.
    • getDefaultRemoteAddress

      public static String getDefaultRemoteAddress()
      Returns:
      the default remote address to connect to in the event that none was set.