Class Session

  • All Implemented Interfaces:
    jakarta.jms.Session, AutoCloseable, Runnable, SessionMBean
    Direct Known Subclasses:
    QueueSession, TopicSession

    public class Session
    extends Object
    implements jakarta.jms.Session, SessionMBean
    Implements the jakarta.jms.Session interface.

    A Session object is a single-threaded context for producing and consuming messages. A session serves several purposes:

    • It is a factory for message producers and consumers.
    • It is a factory for Joram specific message.
    • It defines a serial order for the messages it consumes and the messages it produces.
    • It retains messages it consumes until they have been acknowledged.
    • It serializes execution of message listeners registered with its message consumers.
    • It is a factory for TemporaryTopics and TemporaryQueues.
    • It supports a single series of transactions that combine work spanning its producers and consumers into atomic units.
    A session can create and service multiple message producers and consumers. The Session class defines the different acknowledge modes:
    • AUTO_ACKNOWLEDGE – With this acknowledgment mode, the session automatically acknowledges a client's receipt of a message either when the session has successfully returned from a call to receive or when the message listener the session has called to process the message successfully returns.
    • CLIENT_ACKNOWLEDGE – With this acknowledgment mode, the client acknowledges a consumed message by calling the message's acknowledge method.
    • DUPS_OK_ACKNOWLEDGE – This acknowledgment mode instructs the session to lazily acknowledge the delivery of messages.
    • SESSION_TRANSACTED – This value is returned from the method getAcknowledgeMode if the session is transacted.
    • Field Detail

      • logger

        private static final Logger logger
      • DEBUG

        private static final boolean DEBUG
      • trace

        private static final Logger trace
      • tracker

        private static final Logger tracker
      • INDIVIDUAL_ACKNOWLEDGE

        public static final int INDIVIDUAL_ACKNOWLEDGE
        With this acknowledgment mode, the client acknowledges a consumed message by calling the message's acknowledge method. Contrary to CLIENT_ACKNOWLEDGE mode this mode allows to acknowledge only the specified message.
        See Also:
        Constant Field Values
      • scheduled

        private boolean scheduled
        true if the session's transaction is scheduled.
      • messageListener

        protected jakarta.jms.MessageListener messageListener
        The message listener of the session, if any.
      • ident

        private final String ident
        The identifier of the session.
      • cnx

        private Connection cnx
        The connection the session belongs to.
      • transacted

        boolean transacted
        true if the session is transacted.
      • acknowledgeMode

        private int acknowledgeMode
        The acknowledgement mode of the session.
      • autoAck

        private boolean autoAck
        true if the session's acknowledgements are automatic.
      • repliesIn

        private Queue repliesIn
        FIFO queue holding the asynchronous server deliveries.
      • listenerCount

        private int listenerCount
        Counter of message listeners.
      • sendings

        Hashtable<String,​ProducerMessages> sendings
        Table holding the ProducerMessages holding producers' messages and destinated to be sent at commit.

        Key: destination name
        Object: ProducerMessages

      • deliveries

        Hashtable<String,​MessageAcks> deliveries
        Table holding the identifiers of the messages delivered per destination or subscription, and not acknowledged.

        Key: destination or subscription name
        Object: MessageAcks instance

      • mtpx

        private RequestMultiplexer mtpx
        The request multiplexer used to communicate with the user proxy.
      • requestor

        private Requestor requestor
        The requestor used by the session to communicate with the user proxy.
      • receiveRequestor

        private Requestor receiveRequestor
        The requestor used by the session to make 'receive' with the user proxy. This second requestor is necessary because it must be closed during the session close (see method close).
      • recover

        private boolean recover
        Indicates that the session has been recovered by a message listener. Doesn't need to be volatile because it is only used by the SessionDaemon thread.
      • toClose

        private boolean toClose
        Indicates that the session has been close by a message listener. Doesn't need to be volatile because it is only used by the SessionDaemon thread.
      • status

        private int status
        Status of the session: STOP, START, CLOSE
      • sessionMode

        private int sessionMode
        Mode of the session: NONE, RECEIVE, LISTENER, APP_SERVER
      • requestStatus

        private int requestStatus
        Status of the request: NONE, RUN, DONE.
      • pendingMessageConsumer

        private MessageConsumer pendingMessageConsumer
        The message consumer currently making a request (null if none).
      • singleThreadOfControl

        private Thread singleThreadOfControl
        The current active control thread.
      • closer

        private Session.Closer closer
        Used to synchronize the method close()
      • implicitAck

        private boolean implicitAck
        Indicates whether the messages consumed are implicitly acknowledged or not. When true messages are immediately removed from queue when delivered. Contrary to Session's AUTO_ACKNOWLEDGE mode there is none acknowledge message from client to server.
        See Also:
        FactoryParameters.implicitAck
      • asyncSend

        private boolean asyncSend
        Indicates whether the messages produced are asynchronously sent or not (without or with acknowledgment).
        See Also:
        FactoryParameters.asyncSend
      • queueMessageReadMax

        private int queueMessageReadMax
        Maximum number of messages that can be read at once from a queue.

        This attribute is inherited from Connection at initialization.

        See Also:
        FactoryParameters.queueMessageReadMax
      • topicAckBufferMax

        private int topicAckBufferMax
        Maximum number of acknowledgements that can be buffered when using Session.DUPS_OK_ACKNOWLEDGE mode.

        This attribute is inherited from Connection at initialization.

        See Also:
        FactoryParameters.topicAckBufferMax
      • topicPassivationThreshold

        private int topicPassivationThreshold
        This threshold is the maximum messages number over which the subscription is passivated.

        This attribute is inherited from Connection at initialization, default value is Integer.MAX_VALUE.

        See Also:
        FactoryParameters.topicPassivationThreshold
      • topicActivationThreshold

        private int topicActivationThreshold
        This threshold is the minimum messages number below which the subscription is activated.

        This attribute is inherited from Connection at initialization, default value is 0.

        See Also:
        FactoryParameters.topicActivationThreshold
      • compressedMinSize

        private int compressedMinSize
        If a message body is upper than the compressedMinSize, this message body is compressed.

        This attribute is inherited from Connection at initialization default value is 0 no compression

        See Also:
        FactoryParameters.compressedMinSize
      • compressionLevel

        private int compressionLevel
        the compression level (0-9)

        This attribute is inherited from Connection at initialization default value is Deflater.BEST_SPEED (1)

        See Also:
        FactoryParameters.compressionLevel
      • asyncSub

        private boolean asyncSub
        Indicates whether the subscription requests are asynchronously handled or not.

        Default value is false, the subscription is handled synchronously so the topic must be accessible.

        Since:
        JORAM 5.0.7
      • stringImage

        private String stringImage
    • Constructor Detail

      • Session

        Session​(Connection cnx,
                boolean transacted,
                int acknowledgeMode,
                RequestMultiplexer mtpx)
         throws jakarta.jms.JMSException
        Opens a session.
        Parameters:
        cnx - The connection the session belongs to.
        transacted - true for a transacted session.
        acknowledgeMode - 1 (auto), 2 (client), 3 (dups ok), 4 (individual).
        Throws:
        jakarta.jms.JMSException - In case of an invalid acknowledge mode.
    • Method Detail

      • checkThread

        boolean checkThread()
      • isImplicitAck

        public boolean isImplicitAck()
        Indicates whether the messages consumed are implicitly acknowledged or not. If true messages are immediately removed from queue when delivered.

        This attribute is inherited from Connection at initialization, by default false.

        Specified by:
        isImplicitAck in interface SessionMBean
        Returns:
        true if messages produced are implicitly acknowledged.
        See Also:
        #implicitAck
      • setImplicitAck

        public void setImplicitAck​(boolean implicitAck)
        Sets implicit acknowledge for this session.

        Determines whether the messages produced are implicitly acknowledged or not. If set to true the messages are immediately removed from queue when delivered.

        This attribute is inherited from Connection at initialization, by default false.

        Parameters:
        implicitAck - if true sets implicit acknowledge for this session.
      • isAsyncSend

        public boolean isAsyncSend()
        Indicates whether the messages produced are asynchronously sent or not (without or with acknowledgment).

        This attribute is inherited from Connection at initialization, by default false.

        Specified by:
        isAsyncSend in interface SessionMBean
        Returns:
        true if messages produced are asynchronously sent.
        See Also:
        #asyncSend
      • setAsyncSend

        public void setAsyncSend​(boolean asyncSend)
        Sets asynchronously sending for this session.

        Determines whether the messages produced are asynchronously sent or not (without or with acknowledgement).

        This attribute is inherited from Connection at initialization, by default false.

        Parameters:
        asyncSend - if true sets asynchronous sending for this session.
        See Also:
        FactoryParameters.asyncSend
      • getQueueMessageReadMax

        public final int getQueueMessageReadMax()
        Get the maximum number of messages that can be read at once from a queue for this Session.

        This attribute is inherited from Connection at initialization, default value is 1.

        Specified by:
        getQueueMessageReadMax in interface SessionMBean
        Returns:
        The maximum number of messages that can be read at once from a queue.
        See Also:
        FactoryParameters.queueMessageReadMax
      • setQueueMessageReadMax

        public void setQueueMessageReadMax​(int queueMessageReadMax)
        Set the maximum number of messages that can be read at once from a queue for this Session.

        This attribute is inherited from Connection at initialization, default value is 1.

        Parameters:
        queueMessageReadMax - The maximum number of messages that can be read at once from a queue.
        See Also:
        FactoryParameters.queueMessageReadMax
      • getTopicAckBufferMax

        public final int getTopicAckBufferMax()
        Get the maximum number of acknowledgements that can be buffered when using Session.DUPS_OK_ACKNOWLEDGE mode for this session.

        This attribute is inherited from Connection at initialization.

        Specified by:
        getTopicAckBufferMax in interface SessionMBean
        Returns:
        The Maximum number of acknowledgements that can be buffered when using Session.DUPS_OK_ACKNOWLEDGE mode.
        See Also:
        FactoryParameters.topicAckBufferMax
      • setTopicAckBufferMax

        public void setTopicAckBufferMax​(int topicAckBufferMax)
        Set the maximum number of acknowledgements that can be buffered when using Session.DUPS_OK_ACKNOWLEDGE mode for this session.

        This attribute is inherited from Connection at initialization.

        Parameters:
        topicAckBufferMax - The Maximum number of acknowledgements that can be buffered in Session.DUPS_OK_ACKNOWLEDGE mode.
        See Also:
        FactoryParameters.topicAckBufferMax
      • getTopicPassivationThreshold

        public final int getTopicPassivationThreshold()
        Get the threshold of passivation for this session.

        This threshold is the maximum messages number over which the subscription is passivated.

        This attribute is inherited from Connection at initialization, default value is Integer.MAX_VALUE.

        Specified by:
        getTopicPassivationThreshold in interface SessionMBean
        Returns:
        The maximum messages number over which the subscription is passivated.
        See Also:
        FactoryParameters.topicPassivationThreshold
      • setTopicPassivationThreshold

        public void setTopicPassivationThreshold​(int topicPassivationThreshold)
        Set the threshold of passivation for this session.

        This threshold is the maximum messages number over which the subscription is passivated.

        This attribute is inherited from Connection at initialization, default value is Integer.MAX_VALUE.

        Parameters:
        topicPassivationThreshold - The maximum messages number over which the subscription is passivated.
        See Also:
        FactoryParameters.topicPassivationThreshold
      • getTopicActivationThreshold

        public final int getTopicActivationThreshold()
        Get the threshold of activation for this session.

        This threshold is the minimum messages number below which the subscription is activated.

        This attribute is inherited from Connection at initialization, default value is 0.

        Specified by:
        getTopicActivationThreshold in interface SessionMBean
        Returns:
        The minimum messages number below which the subscription is activated.
        See Also:
        FactoryParameters.topicActivationThreshold
      • setTopicActivationThreshold

        public void setTopicActivationThreshold​(int topicActivationThreshold)
        Set the threshold of activation for this session.

        This threshold is the minimum messages number below which the subscription is activated.

        This attribute is inherited from Connection at initialization, default value is 0.

        Parameters:
        topicActivationThreshold - The minimum messages number below which the subscription is activated.
        See Also:
        FactoryParameters.topicActivationThreshold
      • getCompressedMinSize

        public final int getCompressedMinSize()
        Get the compressedMinSize for this session.

        The minimum message body size before a message body compression.

        This attribute is inherited from Connection at initialization, default value is 0 no compression

        Specified by:
        getCompressedMinSize in interface SessionMBean
        Returns:
        The minimum size before a message body compression
        See Also:
        FactoryParameters.compressedMinSize
      • setCompressedMinSize

        public final void setCompressedMinSize​(int compressedMinSize)
        Sets the minimum size beyond which the message body is compressed in this session. This attribute is inherited from Connection at initialization, the default value is 0 (no compression).
        Parameters:
        compressedMinSize - The minimum size before a message body compression.
        See Also:
        FactoryParameters.compressedMinSize
      • getCompressionLevel

        public final int getCompressionLevel()
        Get the compression level for this session.

        This attribute is inherited from FactoryParameters, default value is Deflater.BEST_SPEED (1).

        Specified by:
        getCompressionLevel in interface SessionMBean
        Returns:
        The compression level
        See Also:
        FactoryParameters.compressionLevel
      • setCompressionLevel

        public final void setCompressionLevel​(int compressionLevel)
        Set the compression level for this session.

        This attribute is inherited from FactoryParameters, default value is Deflater.BEST_SPEED (1). This method can overload this attribute.

        Parameters:
        The - compression level
        See Also:
        FactoryParameters.compressionLevel
      • isAsyncSub

        public boolean isAsyncSub()
        Indicates whether the subscription request is asynchronously handled or not.

        Default value is false, the subscription is handled synchronously so the topic must be accessible.

        Specified by:
        isAsyncSub in interface SessionMBean
        Returns:
        true if the subscription requests are asynchronously handled.
        Since:
        JORAM 5.0.7
      • setAsyncSub

        public void setAsyncSub​(boolean asyncSub)
        Sets asynchronous subscription for this session.

        Determines whether the subscription request is asynchronously handled or not.

        Default value is false, the subscription is handled synchronously so the topic must be accessible.

        Parameters:
        asyncSub - if true sets asynchronous subscription for this session.
        Since:
        JORAM 5.0.7
      • getJMXBeanName

        public String getJMXBeanName()
        Returns the MBean name.
        Returns:
        the MBean name.
      • registerMBean

        public String registerMBean()
      • unregisterMBean

        public void unregisterMBean()
      • setStatus

        private void setStatus​(int status)
        Sets the status of the session.
      • setSessionMode

        private void setSessionMode​(int sessionMode)
        Sets the session mode.
      • setRequestStatus

        private void setRequestStatus​(int requestStatus)
        Sets the request status.
      • getRequestStatus

        public String getRequestStatus()
        Description copied from interface: SessionMBean
        The status of the current request. Only valid in when the session is used to synchronously receive messages (RECEIVE mode).
        Specified by:
        getRequestStatus in interface SessionMBean
      • checkClosed

        protected void checkClosed()
                            throws jakarta.jms.IllegalStateException
        Checks if the session is closed. If true, an IllegalStateException is raised.
        Throws:
        jakarta.jms.IllegalStateException
      • checkThreadOfControl

        private void checkThreadOfControl()
                                   throws jakarta.jms.IllegalStateException
        Checks if the calling thread is the thread of control. If not, an IllegalStateException is raised.
        Throws:
        jakarta.jms.IllegalStateException
      • checkSessionMode

        private void checkSessionMode​(int expectedSessionMode)
                               throws jakarta.jms.IllegalStateException
        Checks the session mode. If it is not the expected session mode, raises an IllegalStateException.
        Parameters:
        expectedSessionMode - the expected session mode.
        Throws:
        jakarta.jms.IllegalStateException
      • checkClientID

        private void checkClientID()
                            throws jakarta.jms.JMSException
        Throws:
        jakarta.jms.JMSException
      • toString

        public final String toString()
        Returns a String image of this session.
        Overrides:
        toString in class Object
      • getAcknowledgeMode

        public final int getAcknowledgeMode()
                                     throws jakarta.jms.JMSException
        API method. Returns the acknowledgement mode of the session. The acknowledgement mode is set at the time that the session is created. If the session is transacted, the acknowledgement mode is ignored.
        Specified by:
        getAcknowledgeMode in interface jakarta.jms.Session
        Specified by:
        getAcknowledgeMode in interface SessionMBean
        Returns:
        If the session is not transacted, returns the current acknowledgement mode for the session. If the session is transacted, returns Session.SESSION_TRANSACTED.
        Throws:
        jakarta.jms.JMSException - Actually never thrown.
      • getTransacted

        public final boolean getTransacted()
                                    throws jakarta.jms.JMSException
        API method. Indicates whether the session is in transacted mode.
        Specified by:
        getTransacted in interface jakarta.jms.Session
        Specified by:
        getTransacted in interface SessionMBean
        Returns:
        true if the session is in transacted mode.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        IllegalStateException - If the session is closed.
        jakarta.jms.JMSException
      • setTransacted

        public void setTransacted​(boolean t)
        set transacted. see connector ManagedConnectionImpl (Connector).
      • setMessageListener

        public void setMessageListener​(jakarta.jms.MessageListener listener)
                                throws jakarta.jms.JMSException
        API method. Sets the session's distinguished message listener, this is an expert facility not used by regular JMS clients.

        When the distinguished message listener is set, no other form of message receipt in the session can be used; however, all forms of sending messages are still supported.

        Specified by:
        setMessageListener in interface jakarta.jms.Session
        Parameters:
        listener - the message listener to associate with this session.
        Throws:
        jakarta.jms.JMSException - Actually never thrown.
      • getMessageListener

        public jakarta.jms.MessageListener getMessageListener()
                                                       throws jakarta.jms.JMSException
        API method. Returns the session's distinguished message listener, this is an expert facility not used by regular JMS clients.
        Specified by:
        getMessageListener in interface jakarta.jms.Session
        Returns:
        the message listener associated with this session
        Throws:
        jakarta.jms.JMSException - Actually never thrown.
      • createMessage

        public jakarta.jms.Message createMessage()
                                          throws jakarta.jms.JMSException
        API method. Creates a Message object.
        Specified by:
        createMessage in interface jakarta.jms.Session
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException
        See Also:
        Message
      • createTextMessage

        public jakarta.jms.TextMessage createTextMessage()
                                                  throws jakarta.jms.JMSException
        API method. Creates a TextMessage object, a TextMessage object is used to send a message containing a String object.
        Specified by:
        createTextMessage in interface jakarta.jms.Session
        Returns:
        a newly created TextMessage object.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException
        See Also:
        TextMessage
      • createTextMessage

        public jakarta.jms.TextMessage createTextMessage​(String text)
                                                  throws jakarta.jms.JMSException
        API method. Creates a TextMessage object, a TextMessage object is used to send a message containing a String object.
        Specified by:
        createTextMessage in interface jakarta.jms.Session
        Parameters:
        text - the string to use to initialize this message.
        Returns:
        a newly created TextMessage object.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException
        See Also:
        TextMessage
      • createBytesMessage

        public jakarta.jms.BytesMessage createBytesMessage()
                                                    throws jakarta.jms.JMSException
        API method. Creates a BytesMessage object, a BytesMessage object could be used to send a message containing a stream of uninterpreted bytes.
        Specified by:
        createBytesMessage in interface jakarta.jms.Session
        Returns:
        a newly created ByteMessage object.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException
        See Also:
        BytesMessage
      • createMapMessage

        public jakarta.jms.MapMessage createMapMessage()
                                                throws jakarta.jms.JMSException
        API method. Creates a MapMessage object, a MapMessage object is used to send a set of name-value pairs, where names are String objects and values are primitive values.
        Specified by:
        createMapMessage in interface jakarta.jms.Session
        Returns:
        a newly created MapMessage object.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException
        See Also:
        MapMessage
      • createObjectMessage

        public jakarta.jms.ObjectMessage createObjectMessage()
                                                      throws jakarta.jms.JMSException
        API method. Creates an ObjectMessage object, an ObjectMessage object is used to send a message that contains a serializable Java object.
        Specified by:
        createObjectMessage in interface jakarta.jms.Session
        Returns:
        a newly created ObjectMessage object.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException
        See Also:
        ObjectMessage
      • createObjectMessage

        public jakarta.jms.ObjectMessage createObjectMessage​(Serializable object)
                                                      throws jakarta.jms.JMSException
        API method. Creates an ObjectMessage object, an ObjectMessage object is used to send a message that contains a serializable Java object.
        Specified by:
        createObjectMessage in interface jakarta.jms.Session
        Parameters:
        object - the object to use to initialize this message.
        Returns:
        a newly created ObjectMessage object.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException
        See Also:
        ObjectMessage
      • createStreamMessage

        public jakarta.jms.StreamMessage createStreamMessage()
                                                      throws jakarta.jms.JMSException
        API method. Creates a StreamMessage object, a StreamMessage object is used to send a self-defining stream of primitive values.
        Specified by:
        createStreamMessage in interface jakarta.jms.Session
        Returns:
        a newly created StreamMessage object.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException
        See Also:
        StreamMessage
      • createBrowser

        public jakarta.jms.QueueBrowser createBrowser​(jakarta.jms.Queue queue,
                                                      String selector)
                                               throws jakarta.jms.JMSException
        API method. Creates a QueueBrowser object to peek at the messages on the specified queue using a message selector.
        Specified by:
        createBrowser in interface jakarta.jms.Session
        Parameters:
        queue - the queue to browse
        selector - the expression allowing to filter messages
        Returns:
        a newly created QueueBrowser object.
        Throws:
        jakarta.jms.IllegalStateException - if the session is closed.
        jakarta.jms.InvalidDestinationException - if an invalid destination is specified.
        jakarta.jms.InvalidSelectorException - if the message selector is invalid.
        jakarta.jms.JMSException
      • createBrowser

        public jakarta.jms.QueueBrowser createBrowser​(jakarta.jms.Queue queue)
                                               throws jakarta.jms.JMSException
        API method. Creates a QueueBrowser object to peek at the messages on the specified queue.
        Specified by:
        createBrowser in interface jakarta.jms.Session
        Parameters:
        queue - the queue to browse
        Returns:
        a newly created QueueBrowser object.
        Throws:
        jakarta.jms.IllegalStateException - if the session is closed.
        jakarta.jms.InvalidDestinationException - if an invalid destination is specified.
        jakarta.jms.JMSException
      • createProducer

        public jakarta.jms.MessageProducer createProducer​(jakarta.jms.Destination dest)
                                                   throws jakarta.jms.JMSException
        API method. Creates a MessageProducer to send messages to the specified destination. A client uses a MessageProducer object to send messages to a destination.
        Specified by:
        createProducer in interface jakarta.jms.Session
        Parameters:
        dest - the Destination to send to, or null if this is a producer which does not have a specified destination.
        Returns:
        Throws:
        jakarta.jms.InvalidDestinationException - if an invalid destination is specified.
        jakarta.jms.IllegalStateException - If the session is closed or if the connection is broken.
        jakarta.jms.JMSException - If the creation fails for any other reason.
      • createConsumer

        public jakarta.jms.MessageConsumer createConsumer​(jakarta.jms.Destination dest,
                                                          String selector,
                                                          boolean noLocal)
                                                   throws jakarta.jms.JMSException
        API method. Creates a MessageConsumer for the specified destination using a message selector. A client uses a MessageConsumer object to receive messages that have been sent to a destination.

        In some cases, a connection may both publish and subscribe to a topic. The consumer NoLocal attribute allows a consumer to inhibit the delivery of messages published by its own connection. The default value for this attribute is False. The noLocal value is only supported by destinations that are topics.

        Specified by:
        createConsumer in interface jakarta.jms.Session
        Parameters:
        dest - the Destination to access.
        selector - The selector allowing to filter messages.
        noLocal - if true, and the destination is a topic, inhibits the delivery of messages published by its own connection.
        Returns:
        the created MessageConsumer object.
        Throws:
        jakarta.jms.InvalidDestinationException - if an invalid destination is specified.
        jakarta.jms.IllegalStateException - If the session is closed or if the connection is broken.
        jakarta.jms.JMSException - If the creation fails for any other reason.
      • createConsumer

        public jakarta.jms.MessageConsumer createConsumer​(jakarta.jms.Destination dest,
                                                          String selector)
                                                   throws jakarta.jms.JMSException
        API method. Creates a MessageConsumer for the specified destination using a message selector. A client uses a MessageConsumer object to receive messages that have been sent to a destination.
        Specified by:
        createConsumer in interface jakarta.jms.Session
        Parameters:
        dest - the Destination to access.
        selector - The selector allowing to filter messages.
        Returns:
        the created MessageConsumer object.
        Throws:
        jakarta.jms.InvalidDestinationException - if an invalid destination is specified.
        jakarta.jms.IllegalStateException - If the session is closed or if the connection is broken.
        jakarta.jms.JMSException - If the creation fails for any other reason.
      • createConsumer

        public jakarta.jms.MessageConsumer createConsumer​(jakarta.jms.Destination dest)
                                                   throws jakarta.jms.JMSException
        API method. Creates a MessageConsumer for the specified destination. A client uses a MessageConsumer object to receive messages that have been sent to a destination.
        Specified by:
        createConsumer in interface jakarta.jms.Session
        Parameters:
        dest - the Destination to access.
        Returns:
        the created MessageConsumer object.
        Throws:
        jakarta.jms.InvalidDestinationException - if an invalid destination is specified.
        jakarta.jms.IllegalStateException - If the session is closed or if the connection is broken.
        jakarta.jms.JMSException - If the creation fails for any other reason.
      • createDurableSubscriber

        public jakarta.jms.TopicSubscriber createDurableSubscriber​(jakarta.jms.Topic topic,
                                                                   String name,
                                                                   String selector,
                                                                   boolean noLocal)
                                                            throws jakarta.jms.JMSException
        API method. Creates a durable subscriber to the specified topic, using a message selector and specifying whether messages published by its own connection should be delivered to it.

        If a client needs to receive all the messages published on a topic, including the ones published while the subscriber is inactive, it needs to use a durable TopicSubscriber. Joram retains a record of durable subscriptions and insures that all messages from the topic's publishers are retained until they are acknowledged by this durable subscriber or they have expired.

        A client can change an existing durable subscription by creating a durable TopicSubscriber with the same name and a new topic and/or message selector. Changing a durable subscriber is equivalent to unsubscribing (deleting) the old one and creating a new one.

        Specified by:
        createDurableSubscriber in interface jakarta.jms.Session
        Parameters:
        topic - the non-temporary Topic to subscribe to.
        name - the name used to identify this subscription.
        selector - The selector allowing to filter messages. A value of null or an empty string indicates that there is no message selector for the message consumer.
        noLocal - if true, inhibits the delivery of messages published by its own connection.
        Returns:
        the created TopicSubscriber object.
        Throws:
        jakarta.jms.InvalidDestinationException - if an invalid destination is specified.
        jakarta.jms.IllegalStateException - If the session is closed or if the connection is broken or if the client identifier is unset.
        jakarta.jms.JMSException - If the creation fails for any other reason.
      • createDurableSubscriber

        public jakarta.jms.TopicSubscriber createDurableSubscriber​(jakarta.jms.Topic topic,
                                                                   String name)
                                                            throws jakarta.jms.JMSException
        API method. Creates a durable subscriber to the specified topic.

        If a client needs to receive all the messages published on a topic, including the ones published while the subscriber is inactive, it needs to use a durable TopicSubscriber. Joram retains a record of durable subscriptions and insures that all messages from the topic's publishers are retained until they are acknowledged by this durable subscriber or they have expired.

        A client can change an existing durable subscription by creating a durable TopicSubscriber with the same name and a new topic and/or message selector. Changing a durable subscriber is equivalent to unsubscribing (deleting) the old one and creating a new one.

        Specified by:
        createDurableSubscriber in interface jakarta.jms.Session
        Parameters:
        topic - the non-temporary Topic to subscribe to.
        name - the name used to identify this subscription.
        Returns:
        the created TopicSubscriber object.
        Throws:
        jakarta.jms.InvalidDestinationException - if an invalid destination is specified.
        jakarta.jms.IllegalStateException - If the session is closed or if the connection is broken or if the client identifier is unset.
        jakarta.jms.JMSException - If the creation fails for any other reason.
      • createQueue

        public jakarta.jms.Queue createQueue​(String name)
                                      throws jakarta.jms.JMSException
        This method allows to create or retrieve a Queue with the given name on the local server. First a destination with the specified name is searched on the server, if it does not exist it is created. In any case a queue identity with its Joram specific address is returned.

        If the given name is a provider-specific name ("#x.y.z" unique identifier) a queue identity is returned with the specified identifier.

        API method.

        Clients that depend on this ability are not portable. Normally the physical creation of destination is an administrative task and is not to be initiated by the JMS API.

        Specified by:
        createQueue in interface jakarta.jms.Session
        Parameters:
        name - the name of this queue.
        Returns:
        a queue with the given name.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException - If the topic creation failed.
        See Also:
        Queue
      • createTopic

        public jakarta.jms.Topic createTopic​(String name)
                                      throws jakarta.jms.JMSException
        This method allows to create or retrieve a Topic with the given name on the local server. First a destination with the specified name is searched on the server, if it does not exist it is created. In any case a topic identity with its provider-specific address is returned.

        If the given name is a Joram specific name ("#x.y.z" unique identifier) a topic identity is returned with the specified identifier.

        API method.

        Clients that depend on this ability are not portable. Normally the physical creation of destination is an administrative task and is not to be initiated by the JMS API.

        Specified by:
        createTopic in interface jakarta.jms.Session
        Parameters:
        name - the name of this topic.
        Returns:
        a topic with the given name.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException - If the topic creation failed.
        See Also:
        Topic
      • createDestination

        private String createDestination​(byte type,
                                         String name)
                                  throws jakarta.jms.JMSException
        Create a destination with the given name and type. If a destination of a corresponding name and type exists it is returned.
        Parameters:
        type - the type of the destination to create.
        name - the name of the destination to create.
        Returns:
        the unique identifier of the created destination.
        Throws:
        jakarta.jms.JMSException
      • createTemporaryQueue

        public jakarta.jms.TemporaryQueue createTemporaryQueue()
                                                        throws jakarta.jms.JMSException
        API method. Creates a TemporaryQueue object. Its lifetime will be that of the Connection unless it is deleted earlier.
        Specified by:
        createTemporaryQueue in interface jakarta.jms.Session
        Returns:
        a temporary queue identity.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed or if the connection is broken.
        jakarta.jms.JMSException - If the request fails for any other reason.
        See Also:
        TemporaryQueue
      • createTemporaryTopic

        public jakarta.jms.TemporaryTopic createTemporaryTopic()
                                                        throws jakarta.jms.JMSException
        API method. Creates a TemporaryTopic object. Its lifetime will be that of the Connection unless it is deleted earlier.
        Specified by:
        createTemporaryTopic in interface jakarta.jms.Session
        Returns:
        a temporary topic identity.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed or if the connection is broken.
        jakarta.jms.JMSException - If the request fails for any other reason.
        See Also:
        TemporaryTopic
      • run

        public void run()
        API method.
        Specified by:
        run in interface Runnable
        Specified by:
        run in interface jakarta.jms.Session
      • setMessageConsumerListener

        void setMessageConsumerListener​(MessageConsumerListener mcl)
        Called by MultiSessionConsumer ASF mode
      • commit

        public void commit()
                    throws jakarta.jms.JMSException
        API method. Commits all messages done in this transaction and releases any locks currently held.
        Specified by:
        commit in interface jakarta.jms.Session
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed, or not transacted, or if the connection is broken.
        jakarta.jms.JMSException
      • doCommit

        public void doCommit()
                      throws jakarta.jms.JMSException
        Throws:
        jakarta.jms.JMSException
      • rollback

        public void rollback()
                      throws jakarta.jms.JMSException
        API method. Rolls back any messages done in this transaction and releases any locks currently held.
        Specified by:
        rollback in interface jakarta.jms.Session
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed, or not transacted.
        jakarta.jms.JMSException
      • doRollback

        public void doRollback()
                        throws jakarta.jms.JMSException
        Throws:
        jakarta.jms.JMSException
      • recover

        public void recover()
                     throws jakarta.jms.JMSException
        API method. Stops message delivery in this session, and restarts message delivery with the oldest unacknowledged message.
        Specified by:
        recover in interface jakarta.jms.Session
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed, or transacted.
        jakarta.jms.JMSException
      • doRecover

        private void doRecover()
                        throws jakarta.jms.JMSException
        Throws:
        jakarta.jms.JMSException
      • unsubscribe

        public void unsubscribe​(String name)
                         throws jakarta.jms.JMSException
        API method. Unsubscribes a durable subscription that has been created by a client, this method deletes the state being maintained on behalf of the subscriber by the Joram server.

        It is erroneous for a client to delete a durable subscription while there is an active MessageConsumer 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 jakarta.jms.Session
        Specified by:
        unsubscribe in interface SessionMBean
        Parameters:
        name - the name used to identify this subscription.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed or if the connection is broken.
        jakarta.jms.InvalidDestinationException - If the subscription does not exist.
        jakarta.jms.JMSException - If the request fails for any other reason.
      • close

        public void close()
                   throws jakarta.jms.JMSException
        API method. Closes the session.

        In order to free significant resources allocated on behalf of a session, clients should close sessions when they are not needed. Closing a session automatically close all related producers, and consumers and causes all temporary destinations to be deleted.

        This call will block until a receive call or message listener in progress has completed. A blocked message consumer receive call returns null when this session is closed. Closing a transacted session must roll back the transaction in progress.

        This method is the only Session method that can be called concurrently.

        Invoking any other Session method on a closed session must throw a JMSException.IllegalStateException. Closing a closed session must not throw an exception.

        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface jakarta.jms.Session
        Specified by:
        close in interface SessionMBean
        Throws:
        jakarta.jms.JMSException - if the JMS provider fails to close the session due to some internal error.
      • doClose

        void doClose()
              throws jakarta.jms.JMSException
        Throws:
        jakarta.jms.JMSException
      • start

        void start()
        Starts the asynchronous deliveries in the session.

        This method is called by a started connection.

      • doStart

        private void doStart()
      • stop

        void stop()
        Stops the asynchronous deliveries processing in the session.

        This method must be carefully used. When the session is stopped, the connection might very well going on pushing deliveries in the session's queue. If the session is never re-started, these deliveries will never be popped out, and this may lead to a situation of consumed but never acknowledged messages.

        This fatal situation never occurs as the stop() method is either called by he Session.close() and Connection.stop() methods, which first empties the session's deliveries and forbid any further push.

      • doStop

        private void doStop()
      • prepareSend

        private void prepareSend​(Destination dest,
                                 Message msg)
                          throws jakarta.jms.JMSException
        Method called by message producers when producing a message for preparing the session to later commit it.
        Parameters:
        dest - The destination the message is destinated to.
        msg - The message.
        Throws:
        jakarta.jms.JMSException
      • prepareAck

        private void prepareAck​(String name,
                                String id,
                                boolean queueMode)
        Method called by message consumers when receiving a message for preparing the session to later acknowledge or deny it.
        Parameters:
        name - Name of the destination or of the proxy subscription the message comes from.
        id - Identifier of the consumed message.
        queueMode - true if the message consumed comes from a queue.
      • acknowledge

        void acknowledge()
                  throws jakarta.jms.JMSException
        Method acknowledging the received messages. Called by Message.
        Throws:
        jakarta.jms.JMSException
      • doAcknowledge

        private void doAcknowledge()
                            throws jakarta.jms.JMSException
        Method acknowledging the received messages.
        Throws:
        jakarta.jms.JMSException
      • acknowledge

        void acknowledge​(Destination dest,
                         String msgId)
                  throws jakarta.jms.JMSException
        Method acknowledging one received message. Called by Message.
        Throws:
        jakarta.jms.JMSException
      • deny

        private void deny()
                   throws jakarta.jms.JMSException
        Method denying the received messages. Called from: - rollback -> synchronized client thread - recover -> synchronized client thread - close -> synchronized client thread - onMessage -> not synchronized session daemon. It is the only thread that can run into the session (session mode = LISTENER) except for the method close that can be called concurrently. But close() first stops the session daemon and then calls deny(). The hashtable deliveries is also accessed from: - acknowledge -> synchronized client thread - commit -> synchronized client thread - receive -> synchronized client thread. - onMessage -> not synchronized session daemon (see above).
        Throws:
        jakarta.jms.JMSException
      • receive

        jakarta.jms.Message receive​(long requestTimeToLive,
                                    long waitTimeOut,
                                    MessageConsumer mc,
                                    String targetName,
                                    String selector,
                                    boolean queueMode)
                             throws jakarta.jms.JMSException
        Called by MessageConsumer. This method is not synchronized because it can be concurrently called by close() and Connection.stop().
        Throws:
        jakarta.jms.JMSException
      • preReceive

        private void preReceive​(MessageConsumer mc)
                         throws jakarta.jms.JMSException
        First stage before calling the proxy and waiting for the reply. It is synchronized because it locks the session in order to prevent any other thread to make another operation.
        Throws:
        jakarta.jms.JMSException
      • postReceive

        private void postReceive()
        Final stage after calling the reply has been returned by the proxy. It releases the session and enables another thread to call it.
      • addConsumer

        protected void addConsumer​(MessageConsumer mc)
        Called here and by sub-classes.
      • closeConsumer

        void closeConsumer​(MessageConsumer mc)
        Called by MessageConsumer.
      • checkConsumers

        void checkConsumers​(String agentId)
                     throws jakarta.jms.JMSException
        Called by Connection (i.e. temporary destinations deletion)
        Throws:
        jakarta.jms.JMSException
      • checkCLMessageProducer

        private void checkCLMessageProducer​(MessageProducer mp)
                                     throws jakarta.jms.IllegalStateException
        Throws:
        jakarta.jms.IllegalStateException
      • addProducer

        protected void addProducer​(MessageProducer mp)
        Called here and by sub-classes.
      • closeProducer

        void closeProducer​(MessageProducer mp)
                    throws jakarta.jms.IllegalStateException
        Called by MessageProducer.
        Throws:
        jakarta.jms.IllegalStateException
      • closeBrowser

        void closeBrowser​(QueueBrowser qb)
        Called by Queue browser.
      • removeMessageListener

        void removeMessageListener​(MessageConsumerListener mcl,
                                   boolean check)
                            throws jakarta.jms.JMSException
        Called by MessageConsumer. The thread of control and the status must be checked if the call results from a setMessageListener but not from a close.
        Throws:
        jakarta.jms.JMSException
      • pushMessages

        void pushMessages​(SingleSessionConsumer consumerListener,
                          ConsumerMessages messages)
        Called by MessageConsumerListener (demultiplexer thread from RequestMultiplexer) in order to distribute messages to a message consumer. Not synchronized because a concurrent close can be done.
      • onMessage

        void onMessage​(Message msg)
        Called by ConnectionConsumer in order to distribute a message through the method run(). Session mode is APP_SERVER.
      • denyMessage

        private void denyMessage​(String targetName,
                                 String msgId,
                                 boolean queueMode,
                                 boolean redelivered)
                          throws jakarta.jms.JMSException
        Called by: - method run (application server thread) synchronized - method onMessage (SessionDaemon thread) not synchronized but no concurrent call except a close which first stops SessionDaemon.
        Throws:
        jakarta.jms.JMSException
      • onMessages

        private void onMessages​(Session.MessageListenerContext ctx)
                         throws jakarta.jms.JMSException
        Called by SessionDaemon. Not synchronized but no concurrent call except a close which first stops SessionDaemon.
        Throws:
        jakarta.jms.JMSException
      • onMessage

        void onMessage​(Message momMsg,
                       MessageConsumerListener mcl)
                throws jakarta.jms.JMSException
        Called by onMessages()
        Throws:
        jakarta.jms.JMSException
      • send

        void send​(Destination dest,
                  jakarta.jms.Message msg,
                  int deliveryMode,
                  int priority,
                  long timeToLive,
                  boolean timestampDisabled,
                  long deliveryDelay,
                  jakarta.jms.CompletionListener completionListener,
                  MessageProducer messageProducer)
           throws jakarta.jms.JMSException
        Called by MessageProducer.
        Throws:
        jakarta.jms.JMSException
      • syncRequest

        AbstractJmsReply syncRequest​(AbstractJmsRequest request)
                              throws jakarta.jms.JMSException
        Called by MessageConsumer. The requestor raises an exception if it is called during another request. This cannot happen as a session is monothreaded. A concurrent close first aborts the current request so it releases the requestor for a subsequent use.
        Throws:
        jakarta.jms.JMSException
      • getConnection

        final Connection getConnection()
      • getId

        final String getId()
      • isAutoAck

        public final boolean isAutoAck()
        Description copied from interface: SessionMBean
        true if the session's acknowledgements are automatic.
        Specified by:
        isAutoAck in interface SessionMBean
      • checkShared

        private void checkShared​(Topic topic,
                                 String sharedSubscriptionName,
                                 String selector)
                          throws jakarta.jms.JMSException
        Throws:
        jakarta.jms.JMSException
      • createSharedConsumer

        public jakarta.jms.MessageConsumer createSharedConsumer​(jakarta.jms.Topic topic,
                                                                String sharedSubscriptionName)
                                                         throws jakarta.jms.JMSException
        API 2.0 method.
        Specified by:
        createSharedConsumer in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createSharedConsumer

        public jakarta.jms.MessageConsumer createSharedConsumer​(jakarta.jms.Topic topic,
                                                                String sharedSubscriptionName,
                                                                String selector)
                                                         throws jakarta.jms.JMSException
        API 2.0 method.
        Specified by:
        createSharedConsumer in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createDurableConsumer

        public jakarta.jms.MessageConsumer createDurableConsumer​(jakarta.jms.Topic topic,
                                                                 String name)
                                                          throws jakarta.jms.JMSException
        API 2.0 method. Creates a durable consumer to the specified topic.

        If a client needs to receive all the messages published on a topic, including the ones published while the subscriber is inactive, it needs to use a durable TopicSubscriber. Joram retains a record of durable subscribers and insures that all messages from the topic's publishers are retained until they are acknowledged by this durable consumer or they have expired.

        A client can change an existing durable consumer by creating a durable MessageConsumer with the same name and a new topic and/or message selector. Changing a durable consumer is equivalent to unsubscribing (deleting) the old one and creating a new one.

        Specified by:
        createDurableConsumer in interface jakarta.jms.Session
        Parameters:
        topic - the non-temporary Topic to subscribe to.
        name - the name used to identify this subscription.
        Returns:
        the created MessageConsumer object.
        Throws:
        jakarta.jms.InvalidDestinationException - if an invalid destination is specified.
        jakarta.jms.IllegalStateException - If the session is closed or if the connection is broken or if the client identifier is unset.
        jakarta.jms.JMSException - If the creation fails for any other reason.
      • createDurableConsumer

        public jakarta.jms.MessageConsumer createDurableConsumer​(jakarta.jms.Topic topic,
                                                                 String name,
                                                                 String selector,
                                                                 boolean noLocal)
                                                          throws jakarta.jms.JMSException
        API 2.0 method. Creates a durable consumer to the specified topic.

        If a client needs to receive all the messages published on a topic, including the ones published while the subscriber is inactive, it needs to use a durable TopicSubscriber. Joram retains a record of durable subscribers and insures that all messages from the topic's publishers are retained until they are acknowledged by this durable consumer or they have expired.

        A client can change an existing durable consumer by creating a durable MessageConsumer with the same name and a new topic and/or message selector. Changing a durable consumer is equivalent to unsubscribing (deleting) the old one and creating a new one.

        Specified by:
        createDurableConsumer in interface jakarta.jms.Session
        Parameters:
        topic - the non-temporary Topic to subscribe to.
        name - the name used to identify this subscription.
        selector - the selector used to filter incoming messages.
        noLocal - if true, inhibits the delivery of messages published by its own connection.
        Returns:
        the created MessageConsumer object.
        Throws:
        jakarta.jms.InvalidDestinationException - if an invalid destination is specified.
        jakarta.jms.IllegalStateException - If the session is closed or if the connection is broken or if the client identifier is unset.
        jakarta.jms.JMSException - If the creation fails for any other reason.
      • createSharedDurableConsumer

        public jakarta.jms.MessageConsumer createSharedDurableConsumer​(jakarta.jms.Topic topic,
                                                                       String name)
                                                                throws jakarta.jms.JMSException
        API 2.0 method.
        Specified by:
        createSharedDurableConsumer in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createSharedDurableConsumer

        public jakarta.jms.MessageConsumer createSharedDurableConsumer​(jakarta.jms.Topic topic,
                                                                       String name,
                                                                       String selector)
                                                                throws jakarta.jms.JMSException
        API 2.0 method.
        Specified by:
        createSharedDurableConsumer in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException