Class Session

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

    public class Session
    extends Object
    implements Session, SessionMBean
    Implements the javax.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

        public static org.objectweb.util.monolog.api.Logger logger
      • trace

        public static org.objectweb.util.monolog.api.Logger trace
      • tracker

        public static org.objectweb.util.monolog.api.Logger tracker
      • INDIVIDUAL_ACKNOWLEDGE

        public static 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.
      • scheduled

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

        protected 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 fr.dyade.aaa.common.Queue repliesIn
        FIFO queue holding the asynchronous server deliveries.
      • listenerCount

        private int listenerCount
        Counter of message listeners.
      • sendings

        Hashtable<String,​org.objectweb.joram.shared.client.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 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:
        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
      • checkThreadOfControl

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

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

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

        public final int getAcknowledgeMode()
                                     throws 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 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:
        JMSException - Actually never thrown.
      • setTransacted

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

        public void setMessageListener​(MessageListener listener)
                                throws 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 Session
        Parameters:
        listener - the message listener to associate with this session.
        Throws:
        JMSException - Actually never thrown.
      • getMessageListener

        public MessageListener getMessageListener()
                                           throws 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 Session
        Returns:
        the message listener associated with this session
        Throws:
        JMSException - Actually never thrown.
      • createProducer

        public MessageProducer createProducer​(Destination dest)
                                       throws 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 Session
        Parameters:
        dest - the Destination to send to, or null if this is a producer which does not have a specified destination.
        Returns:
        Throws:
        InvalidDestinationException - if an invalid destination is specified.
        IllegalStateException - If the session is closed or if the connection is broken.
        JMSException - If the creation fails for any other reason.
      • createConsumer

        public MessageConsumer createConsumer​(Destination dest,
                                              String selector,
                                              boolean noLocal)
                                       throws 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 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:
        InvalidDestinationException - if an invalid destination is specified.
        IllegalStateException - If the session is closed or if the connection is broken.
        JMSException - If the creation fails for any other reason.
      • createConsumer

        public MessageConsumer createConsumer​(Destination dest,
                                              String selector)
                                       throws 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 Session
        Parameters:
        dest - the Destination to access.
        selector - The selector allowing to filter messages.
        Returns:
        the created MessageConsumer object.
        Throws:
        InvalidDestinationException - if an invalid destination is specified.
        IllegalStateException - If the session is closed or if the connection is broken.
        JMSException - If the creation fails for any other reason.
      • createConsumer

        public MessageConsumer createConsumer​(Destination dest)
                                       throws 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 Session
        Parameters:
        dest - the Destination to access.
        Returns:
        the created MessageConsumer object.
        Throws:
        InvalidDestinationException - if an invalid destination is specified.
        IllegalStateException - If the session is closed or if the connection is broken.
        JMSException - If the creation fails for any other reason.
      • createDurableSubscriber

        public TopicSubscriber createDurableSubscriber​(Topic topic,
                                                       String name,
                                                       String selector,
                                                       boolean noLocal)
                                                throws 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 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:
        InvalidDestinationException - if an invalid destination is specified.
        IllegalStateException - If the session is closed or if the connection is broken or if the client identifier is unset.
        JMSException - If the creation fails for any other reason.
      • createDurableSubscriber

        public TopicSubscriber createDurableSubscriber​(Topic topic,
                                                       String name)
                                                throws 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 Session
        Parameters:
        topic - the non-temporary Topic to subscribe to.
        name - the name used to identify this subscription.
        Returns:
        the created TopicSubscriber object.
        Throws:
        InvalidDestinationException - if an invalid destination is specified.
        IllegalStateException - If the session is closed or if the connection is broken or if the client identifier is unset.
        JMSException - If the creation fails for any other reason.
      • createQueue

        public Queue createQueue​(String name)
                          throws 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 Session
        Parameters:
        name - the name of this queue.
        Returns:
        a queue with the given name.
        Throws:
        IllegalStateException - If the session is closed.
        JMSException - If the topic creation failed.
        See Also:
        Queue
      • createTopic

        public Topic createTopic​(String name)
                          throws 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 Session
        Parameters:
        name - the name of this topic.
        Returns:
        a topic with the given name.
        Throws:
        IllegalStateException - If the session is closed.
        JMSException - If the topic creation failed.
        See Also:
        Topic
      • createDestination

        private String createDestination​(byte type,
                                         String name)
                                  throws 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:
        JMSException
      • run

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

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

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

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

        public void unsubscribe​(String name)
                         throws 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 Session
        Specified by:
        unsubscribe in interface SessionMBean
        Parameters:
        name - the name used to identify this subscription.
        Throws:
        IllegalStateException - If the session is closed or if the connection is broken.
        InvalidDestinationException - If the subscription does not exist.
        JMSException - If the request fails for any other reason.
      • close

        public void close()
                   throws 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 Session
        Specified by:
        close in interface SessionMBean
        Throws:
        JMSException - if the JMS provider fails to close the session due to some internal error.
      • 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,
                                 org.objectweb.joram.shared.messages.Message msg)
                          throws 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:
        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 JMSException
        Method acknowledging the received messages. Called by Message.
        Throws:
        JMSException
      • doAcknowledge

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

        private void deny()
                   throws 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:
        JMSException
      • receive

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

        private void preReceive​(MessageConsumer mc)
                         throws 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:
        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 JMSException
        Called by Connection (i.e. temporary destinations deletion)
        Throws:
        JMSException
      • addProducer

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

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

        void removeMessageListener​(MessageConsumerListener mcl,
                                   boolean check)
                            throws 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:
        JMSException
      • pushMessages

        void pushMessages​(SingleSessionConsumer consumerListener,
                          org.objectweb.joram.shared.client.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​(org.objectweb.joram.shared.messages.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 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:
        JMSException
      • syncRequest

        org.objectweb.joram.shared.client.AbstractJmsReply syncRequest​(org.objectweb.joram.shared.client.AbstractJmsRequest request)
                                                                throws 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:
        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
      • createDurableConsumer

        public MessageConsumer createDurableConsumer​(Topic topic,
                                                     String name)
                                              throws 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 Session
        Parameters:
        topic - the non-temporary Topic to subscribe to.
        name - the name used to identify this subscription.
        Returns:
        the created MessageConsumer object.
        Throws:
        InvalidDestinationException - if an invalid destination is specified.
        IllegalStateException - If the session is closed or if the connection is broken or if the client identifier is unset.
        JMSException - If the creation fails for any other reason.
      • createDurableConsumer

        public MessageConsumer createDurableConsumer​(Topic topic,
                                                     String name,
                                                     String selector,
                                                     boolean noLocal)
                                              throws 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 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:
        InvalidDestinationException - if an invalid destination is specified.
        IllegalStateException - If the session is closed or if the connection is broken or if the client identifier is unset.
        JMSException - If the creation fails for any other reason.