Class XASession

  • All Implemented Interfaces:
    jakarta.jms.Session, jakarta.jms.XASession, AutoCloseable, Runnable
    Direct Known Subclasses:
    XAQueueSession, XATopicSession

    public class XASession
    extends Object
    implements jakarta.jms.XASession
    Implements the jakarta.jms.XASession interface.

    An XA session actually extends the behaviour of a normal session by providing an XA resource representing it to a Transaction Manager, so that it is part of a distributed transaction. The XASession wraps what looks like a "normal" Session object. This object takes care of producing and consuming messages, the actual sendings and acknowledgement being managed by this XA wrapper.

    This class offers support to transactional environments. Client programs are strongly encouraged to use the transactional support available in their environment, rather than use these XA interfaces directly.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Session sess  
      private XAResource xaResource
      The XA resource representing the session to the transaction manager.
      • Fields inherited from interface jakarta.jms.Session

        AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE, SESSION_TRANSACTED
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      API method.
      void commit()
      API method inherited from session, but intercepted here for forbidding its use in the XA context (as defined by the API).
      jakarta.jms.QueueBrowser createBrowser​(jakarta.jms.Queue queue)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.QueueBrowser createBrowser​(jakarta.jms.Queue queue, String selector)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.BytesMessage createBytesMessage()
      Delegates the call to the wrapped JMS session.
      jakarta.jms.MessageConsumer createConsumer​(jakarta.jms.Destination dest)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.MessageConsumer createConsumer​(jakarta.jms.Destination dest, String selector)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.MessageConsumer createConsumer​(jakarta.jms.Destination dest, String selector, boolean noLocal)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.MessageConsumer createDurableConsumer​(jakarta.jms.Topic topic, String name)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.MessageConsumer createDurableConsumer​(jakarta.jms.Topic topic, String name, String messageSelector, boolean noLocal)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.TopicSubscriber createDurableSubscriber​(jakarta.jms.Topic topic, String name)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.TopicSubscriber createDurableSubscriber​(jakarta.jms.Topic topic, String name, String selector, boolean noLocal)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.MapMessage createMapMessage()
      Delegates the call to the wrapped JMS session.
      jakarta.jms.Message createMessage()
      Delegates the call to the wrapped JMS session.
      jakarta.jms.ObjectMessage createObjectMessage()
      Delegates the call to the wrapped JMS session.
      jakarta.jms.ObjectMessage createObjectMessage​(Serializable obj)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.MessageProducer createProducer​(jakarta.jms.Destination dest)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.Queue createQueue​(String queueName)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.MessageConsumer createSharedConsumer​(jakarta.jms.Topic topic, String sharedSubscriptionName)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.MessageConsumer createSharedConsumer​(jakarta.jms.Topic topic, String sharedSubscriptionName, String messageSelector)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.MessageConsumer createSharedDurableConsumer​(jakarta.jms.Topic topic, String name)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.MessageConsumer createSharedDurableConsumer​(jakarta.jms.Topic topic, String name, String messageSelector)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.StreamMessage createStreamMessage()
      Delegates the call to the wrapped JMS session.
      jakarta.jms.TemporaryQueue createTemporaryQueue()
      Delegates the call to the wrapped JMS session.
      jakarta.jms.TemporaryTopic createTemporaryTopic()
      Delegates the call to the wrapped JMS session.
      jakarta.jms.TextMessage createTextMessage()
      Delegates the call to the wrapped JMS session.
      jakarta.jms.TextMessage createTextMessage​(String text)
      Delegates the call to the wrapped JMS session.
      jakarta.jms.Topic createTopic​(String topicName)
      Delegates the call to the wrapped JMS session.
      int getAcknowledgeMode()
      Delegates the call to the wrapped JMS session.
      Session getDelegateSession()  
      jakarta.jms.MessageListener getMessageListener()
      Delegates the call to the wrapped JMS session.
      jakarta.jms.Session getSession()
      API method.
      boolean getTransacted()
      API method.
      XAResource getXAResource()
      API method.
      void recover()
      API method inherited from session, but intercepted here for forbidding its use in the XA context (as defined by the API).
      void rollback()
      API method inherited from session, but intercepted here for forbidding its use in the XA context (as defined by the API).
      void run()
      Delegates the call to the wrapped JMS session.
      void setMessageListener​(jakarta.jms.MessageListener messageListener)
      Delegates the call to the wrapped JMS session.
      String toString()
      Returns a String image of this session.
      void unsubscribe​(String name)
      Delegates the call to the wrapped JMS session.
    • Field Detail

      • xaResource

        private XAResource xaResource
        The XA resource representing the session to the transaction manager.
    • Constructor Detail

      • XASession

        public XASession​(Connection cnx,
                         Session sess,
                         XAResourceMngr rm)
                  throws jakarta.jms.JMSException
        Constructs an XASession.

        This constructor is called by subclasses.

        Parameters:
        cnx - The connection the session belongs to.
        sess - The wrapped "regular" session.
        rm - The resource manager.
        Throws:
        jakarta.jms.JMSException - Actually never thrown.
    • Method Detail

      • getDelegateSession

        public final Session getDelegateSession()
      • toString

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

        public jakarta.jms.Session getSession()
                                       throws jakarta.jms.JMSException
        API method. Gets the session associated with this XASession.
        Specified by:
        getSession in interface jakarta.jms.XASession
        Returns:
        the session object.
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException
      • getXAResource

        public XAResource getXAResource()
        API method. Returns an XA resource to the caller.
        Specified by:
        getXAResource in interface jakarta.jms.XASession
        Returns:
        an XA resource.
      • getTransacted

        public 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 jakarta.jms.XASession
        Returns:
        true
        Throws:
        jakarta.jms.IllegalStateException - If the session is closed.
        jakarta.jms.JMSException
      • createBrowser

        public jakarta.jms.QueueBrowser createBrowser​(jakarta.jms.Queue queue,
                                                      String selector)
                                               throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createBrowser in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createBrowser

        public jakarta.jms.QueueBrowser createBrowser​(jakarta.jms.Queue queue)
                                               throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createBrowser in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createProducer

        public jakarta.jms.MessageProducer createProducer​(jakarta.jms.Destination dest)
                                                   throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createProducer in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createConsumer

        public jakarta.jms.MessageConsumer createConsumer​(jakarta.jms.Destination dest,
                                                          String selector,
                                                          boolean noLocal)
                                                   throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createConsumer in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createConsumer

        public jakarta.jms.MessageConsumer createConsumer​(jakarta.jms.Destination dest,
                                                          String selector)
                                                   throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createConsumer in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createConsumer

        public jakarta.jms.MessageConsumer createConsumer​(jakarta.jms.Destination dest)
                                                   throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createConsumer in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createDurableSubscriber

        public jakarta.jms.TopicSubscriber createDurableSubscriber​(jakarta.jms.Topic topic,
                                                                   String name,
                                                                   String selector,
                                                                   boolean noLocal)
                                                            throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createDurableSubscriber in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createDurableSubscriber

        public jakarta.jms.TopicSubscriber createDurableSubscriber​(jakarta.jms.Topic topic,
                                                                   String name)
                                                            throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createDurableSubscriber in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • commit

        public void commit()
                    throws jakarta.jms.JMSException
        API method inherited from session, but intercepted here for forbidding its use in the XA context (as defined by the API).
        Specified by:
        commit in interface jakarta.jms.Session
        Specified by:
        commit in interface jakarta.jms.XASession
        Throws:
        jakarta.jms.IllegalStateException - Systematically thrown.
        jakarta.jms.JMSException
      • rollback

        public void rollback()
                      throws jakarta.jms.JMSException
        API method inherited from session, but intercepted here for forbidding its use in the XA context (as defined by the API).
        Specified by:
        rollback in interface jakarta.jms.Session
        Specified by:
        rollback in interface jakarta.jms.XASession
        Throws:
        jakarta.jms.IllegalStateException - Systematically thrown.
        jakarta.jms.JMSException
      • recover

        public void recover()
                     throws jakarta.jms.JMSException
        API method inherited from session, but intercepted here for forbidding its use in the XA context (as defined by the API).
        Specified by:
        recover in interface jakarta.jms.Session
        Throws:
        jakarta.jms.IllegalStateException - Systematically thrown.
        jakarta.jms.JMSException
      • close

        public void close()
                   throws jakarta.jms.JMSException
        API method. Closes the session.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException - Actually never thrown.
        See Also:
        Session.close
      • run

        public void run()
        Delegates the call to the wrapped JMS session.
        Specified by:
        run in interface Runnable
        Specified by:
        run in interface jakarta.jms.Session
      • unsubscribe

        public void unsubscribe​(String name)
                         throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        unsubscribe in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createTemporaryQueue

        public jakarta.jms.TemporaryQueue createTemporaryQueue()
                                                        throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createTemporaryQueue in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createTemporaryTopic

        public jakarta.jms.TemporaryTopic createTemporaryTopic()
                                                        throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createTemporaryTopic in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createTopic

        public jakarta.jms.Topic createTopic​(String topicName)
                                      throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createTopic in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createQueue

        public jakarta.jms.Queue createQueue​(String queueName)
                                      throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createQueue in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • setMessageListener

        public void setMessageListener​(jakarta.jms.MessageListener messageListener)
                                throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        setMessageListener in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • getMessageListener

        public jakarta.jms.MessageListener getMessageListener()
                                                       throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        getMessageListener in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • getAcknowledgeMode

        public int getAcknowledgeMode()
                               throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        getAcknowledgeMode in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createTextMessage

        public jakarta.jms.TextMessage createTextMessage()
                                                  throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createTextMessage in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createTextMessage

        public jakarta.jms.TextMessage createTextMessage​(String text)
                                                  throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createTextMessage in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createStreamMessage

        public jakarta.jms.StreamMessage createStreamMessage()
                                                      throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createStreamMessage in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createObjectMessage

        public jakarta.jms.ObjectMessage createObjectMessage()
                                                      throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createObjectMessage in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createObjectMessage

        public jakarta.jms.ObjectMessage createObjectMessage​(Serializable obj)
                                                      throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createObjectMessage in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createMessage

        public jakarta.jms.Message createMessage()
                                          throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createMessage in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createMapMessage

        public jakarta.jms.MapMessage createMapMessage()
                                                throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createMapMessage in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createBytesMessage

        public jakarta.jms.BytesMessage createBytesMessage()
                                                    throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createBytesMessage in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createSharedConsumer

        public jakarta.jms.MessageConsumer createSharedConsumer​(jakarta.jms.Topic topic,
                                                                String sharedSubscriptionName)
                                                         throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        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 messageSelector)
                                                         throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        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
        Delegates the call to the wrapped JMS session.
        Specified by:
        createDurableConsumer in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createDurableConsumer

        public jakarta.jms.MessageConsumer createDurableConsumer​(jakarta.jms.Topic topic,
                                                                 String name,
                                                                 String messageSelector,
                                                                 boolean noLocal)
                                                          throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createDurableConsumer in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException
      • createSharedDurableConsumer

        public jakarta.jms.MessageConsumer createSharedDurableConsumer​(jakarta.jms.Topic topic,
                                                                       String name)
                                                                throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        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 messageSelector)
                                                                throws jakarta.jms.JMSException
        Delegates the call to the wrapped JMS session.
        Specified by:
        createSharedDurableConsumer in interface jakarta.jms.Session
        Throws:
        jakarta.jms.JMSException