ActiveMQXAConnection xref

View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Protique Ltd
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.codehaus.activemq;
    19
    20  import org.apache.commons.logging.Log;
    21  import org.apache.commons.logging.LogFactory;
    22  import org.codehaus.activemq.message.ResponseReceipt;
    23  import org.codehaus.activemq.message.TransactionInfo;
    24  import org.codehaus.activemq.message.XATransactionInfo;
    25  import org.codehaus.activemq.transport.TransportChannel;
    26
    27  import javax.jms.*;
    28
    29  /***
    30   * The XAConnection interface extends the capability of Connection by providing
    31   * an XASession (optional).
    32   * <p/>
    33   * The XAConnection interface is optional. JMS providers are not required to
    34   * support this interface. This interface is for use by JMS providers to
    35   * support transactional environments. Client programs are strongly encouraged
    36   * to use the transactional support  available in their environment, rather
    37   * than use these XA  interfaces directly.
    38   *
    39   * @version $Revision: 1.6 $
    40   * @see javax.jms.Connection
    41   * @see javax.jms.ConnectionFactory
    42   * @see javax.jms.QueueConnection
    43   * @see javax.jms.TopicConnection
    44   * @see javax.jms.TopicConnectionFactory
    45   * @see javax.jms.QueueConnection
    46   * @see javax.jms.QueueConnectionFactory
    47   */
    48  public class ActiveMQXAConnection extends ActiveMQConnection implements XATopicConnection, XAQueueConnection, XAConnection {
    49
    50      private static final Log log = LogFactory.getLog(ActiveMQXAConnection.class);
    51      private final String resourceManagerId;
    52
    53      public ActiveMQXAConnection(ActiveMQConnectionFactory factory, String theUserName, String thePassword, TransportChannel transportChannel) throws JMSException {
    54          super(factory, theUserName, thePassword, transportChannel);
    55          resourceManagerId = determineResourceManagerId();
    56      }
    57
    58      public ActiveMQXAConnection(ActiveMQConnectionFactory factory, String theUserName, String thePassword) throws JMSException {
    59          super(factory, theUserName, thePassword);
    60          resourceManagerId = determineResourceManagerId();
    61      }
    62
    63      /***
    64       * Get's the resource manager id.
    65       */
    66      private String determineResourceManagerId() throws JMSException {
    67
    68          XATransactionInfo info = new XATransactionInfo();
    69          info.setId(this.packetIdGenerator.generateId());
    70          info.setType(TransactionInfo.GET_RM_ID);
    71
    72          ResponseReceipt receipt = (ResponseReceipt) syncSendRequest(info);
    73          String rmId = (String) receipt.getResult();
    74          assert rmId != null;
    75          return rmId;
    76      }
    77
    78      public XASession createXASession() throws JMSException {
    79          return createActiveMQXASession();
    80      }
    81
    82      public QueueSession createQueueSession(boolean transacted, int acknowledgeMode) throws JMSException {
    83          return createActiveMQXASession();
    84      }
    85
    86      public TopicSession createTopicSession(boolean transacted, int acknowledgeMode) throws JMSException {
    87          return createActiveMQXASession();
    88      }
    89
    90      public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException {
    91          return createActiveMQXASession();
    92      }
    93
    94      public XATopicSession createXATopicSession() throws JMSException {
    95          return createActiveMQXASession();
    96      }
    97
    98      public XAQueueSession createXAQueueSession() throws JMSException {
    99          return createActiveMQXASession();
    100     }
    101
    102     protected ActiveMQXASession createActiveMQXASession() throws JMSException {
    103         checkClosed();
    104         return new ActiveMQXASession(this);
    105     }
    106
    107     /***
    108      * @return Returns the resourceManagerId.
    109      */
    110     public String getResourceManagerId() {
    111         return resourceManagerId;
    112     }
    113 }