001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq;
018    
019    import javax.jms.JMSException;
020    import javax.jms.Session;
021    import javax.jms.XAConnection;
022    import javax.jms.XAQueueConnection;
023    import javax.jms.XAQueueSession;
024    import javax.jms.XASession;
025    import javax.jms.XATopicConnection;
026    import javax.jms.XATopicSession;
027    
028    import org.apache.activemq.management.JMSStatsImpl;
029    import org.apache.activemq.transport.Transport;
030    import org.apache.activemq.util.IdGenerator;
031    
032    /**
033     * The XAConnection interface extends the capability of Connection by providing
034     * an XASession (optional).
035     * <p/>
036     * The XAConnection interface is optional. JMS providers are not required to
037     * support this interface. This interface is for use by JMS providers to
038     * support transactional environments. Client programs are strongly encouraged
039     * to use the transactional support  available in their environment, rather
040     * than use these XA  interfaces directly.
041     *
042     * @version $Revision: 1.6 $
043     * @see javax.jms.Connection
044     * @see javax.jms.ConnectionFactory
045     * @see javax.jms.QueueConnection
046     * @see javax.jms.TopicConnection
047     * @see javax.jms.TopicConnectionFactory
048     * @see javax.jms.QueueConnection
049     * @see javax.jms.QueueConnectionFactory
050     */
051    public class ActiveMQXAConnection extends ActiveMQConnection implements XATopicConnection, XAQueueConnection, XAConnection {
052    
053        protected ActiveMQXAConnection(Transport transport, IdGenerator clientIdGenerator, JMSStatsImpl factoryStats) throws Exception {
054            super(transport, clientIdGenerator, factoryStats);
055        }
056    
057        public XASession createXASession() throws JMSException {
058            return (XASession) createSession(true, Session.SESSION_TRANSACTED);
059        }
060    
061        public XATopicSession createXATopicSession() throws JMSException {
062            return (XATopicSession) createSession(true, Session.SESSION_TRANSACTED);
063        }
064    
065        public XAQueueSession createXAQueueSession() throws JMSException {
066            return (XAQueueSession) createSession(true, Session.SESSION_TRANSACTED);
067        }
068    
069        public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException {
070            checkClosedOrFailed();
071            ensureConnectionInfoSent();
072            return new ActiveMQXASession(this, getNextSessionId(), Session.SESSION_TRANSACTED, isDispatchAsync());
073        }
074    }