Class JMSJobFactory

  • All Implemented Interfaces:
    JobFactory, AutoCloseable

    public class JMSJobFactory
    extends Object
    implements JobFactory, AutoCloseable
    JobFactory implementation using the Java Messaging Service API (JMS).

    Instances of this class will automatically establish a JMS connection at construction time. In order to release these resources the close() method shall be called when this instance is not needed anymore. Since it implements AutoCloseable it can be used in conjunction with the try-with-resources statement.

    • Field Detail

      • DEFAULT_QUEUE_NAME

        public static final String DEFAULT_QUEUE_NAME
        The default name of the JMS request queue.
        See Also:
        Constant Field Values
      • PROPERTY_KEY_SUBMISSION_TIMEOUT

        public static final String PROPERTY_KEY_SUBMISSION_TIMEOUT
        Property key for the submission timeout. Associated value must be an Integer.

        If a job has not been accepted by a server by the specified timeout, submission will fail. If the timeout is 0, the default timeout (as defined by the JobFactory) is used, if the timeout is < 0, it will wait indefinitely for acceptance.

        See Also:
        Constant Field Values
      • PROPERTY_KEY_COMMUNICATION_TIMEOUT

        public static final String PROPERTY_KEY_COMMUNICATION_TIMEOUT
        Property key for the communication timeout. Associated value must be an Integer.

        If there has been no JMS communication activity on a channel for the time specified by the timeout, the communication is supposed to be dead. This applies to both sides of the communication. If the timeout is <= 0, the default timeout is used.

        NB: The minimum timeout accepted by the server is 1000ms.

        See Also:
        Constant Field Values
      • PROPERTY_KEY_PRIORITY

        public static final String PROPERTY_KEY_PRIORITY
        Property key for the priority. Associated value must be an Integer.
        See Also:
        Constant Field Values
    • Constructor Detail

      • JMSJobFactory

        public JMSJobFactory​(javax.jms.QueueConnectionFactory connectionFactory,
                             String queueName)
        Create a new JMSJobFactory with the given JMS QueueConnectionFactory, Credentials and the given request queue name.
        Parameters:
        connectionFactory - the JMS connection factory to use. Must not be null.
        queueName - the name of the request queue, default is "JS.REQUEST". Must not be null.
        See Also:
        DEFAULT_QUEUE_NAME
    • Method Detail

      • isSessionAlreadyClosed

        public boolean isSessionAlreadyClosed()
        Indicates whether the JMS QueueSession is already closed. If closed this instance cannot be used for JMS connections anymore.
        Returns:
        true if this instance cannot be used anymore since its session is already closed, false otherwise.
      • getDefaultPriority

        public int getDefaultPriority()
        Returns:
        the default priority.
      • getSubmissionTimeout

        public long getSubmissionTimeout()
        Returns:
        the job submission timeout.
      • getCommunicationTimeout

        public long getCommunicationTimeout()
      • setCommunicationTimeout

        public void setCommunicationTimeout​(long communicationTimeout)
        Set the default communication timeout.

        If there has been no JMS communication activity on a channel for the time specified by the timeout, the communication is supposed to be dead. This applies to both sides of the communication.

        Parameters:
        communicationTimeout - communication timeout in milliseconds (ms)
        See Also:
        DEFAULT_TIMEOUT, PROPERTY_KEY_COMMUNICATION_TIMEOUT
      • close

        public void close()
        Closes the JMS connection to jadice server and releases the JMS resources held by it.

        Afterwards this JMSJobFactory must not be used anymore. Any successive calls will throw an IllegalStateException.

        Caveat: This method shall not be called while Jobs created by this instance are running!

        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface JobFactory
      • connect

        public void connect()
                     throws ConnectionException
        Description copied from interface: JobFactory
        Performs all actions that are required before Jobs can be created
        Specified by:
        connect in interface JobFactory
        Throws:
        ConnectionException - if the connection to the underlying communication infrastructure could not be established
      • getCredentials

        public Credentials getCredentials()
        Returns:
        Credentials that are used for establishing a JMS connection.
        Since:
        jadice server 5.4.0.0
        See Also:
        ConnectionFactory.createConnection(String, String)
      • setCredentials

        public void setCredentials​(Credentials credentials)
        Set credentials that are used for establishing a JMS connection.
        Parameters:
        credentials - username and password
        Throws:
        IllegalStateException - if the connection to JMS has already been established with connect().
        Since:
        jadice server 5.4.0.0
        See Also:
        ConnectionFactory.createConnection(String, String)
      • setKeepAliveMsgPriority

        public void setKeepAliveMsgPriority​(int keepAliveMsgPriority)
      • getKeepAliveMsgPriority

        public int getKeepAliveMsgPriority()