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 */
017package org.apache.activemq;
018
019import java.net.URI;
020import java.util.Properties;
021
022import javax.jms.JMSException;
023import javax.jms.XAConnection;
024import javax.jms.XAConnectionFactory;
025import javax.jms.XAQueueConnection;
026import javax.jms.XAQueueConnectionFactory;
027import javax.jms.XATopicConnection;
028import javax.jms.XATopicConnectionFactory;
029
030import org.apache.activemq.management.JMSStatsImpl;
031import org.apache.activemq.transport.Transport;
032
033/**
034 * A factory of {@link XAConnection} instances
035 * 
036 * 
037 */
038public class ActiveMQXAConnectionFactory extends ActiveMQConnectionFactory implements XAConnectionFactory, XAQueueConnectionFactory, XATopicConnectionFactory {
039
040    public ActiveMQXAConnectionFactory() {
041    }
042
043    public ActiveMQXAConnectionFactory(String userName, String password, String brokerURL) {
044        super(userName, password, brokerURL);
045    }
046
047    public ActiveMQXAConnectionFactory(String userName, String password, URI brokerURL) {
048        super(userName, password, brokerURL);
049    }
050
051    public ActiveMQXAConnectionFactory(String brokerURL) {
052        super(brokerURL);
053    }
054
055    public ActiveMQXAConnectionFactory(URI brokerURL) {
056        super(brokerURL);
057    }
058
059    public XAConnection createXAConnection() throws JMSException {
060        return (XAConnection) createActiveMQConnection();
061    }
062
063    public XAConnection createXAConnection(String userName, String password) throws JMSException {
064        return (XAConnection) createActiveMQConnection(userName, password);
065    }
066
067    public XAQueueConnection createXAQueueConnection() throws JMSException {
068        return (XAQueueConnection) createActiveMQConnection();
069    }
070
071    public XAQueueConnection createXAQueueConnection(String userName, String password) throws JMSException {
072        return (XAQueueConnection) createActiveMQConnection(userName, password);
073    }
074
075    public XATopicConnection createXATopicConnection() throws JMSException {
076        return (XATopicConnection) createActiveMQConnection();
077    }
078
079    public XATopicConnection createXATopicConnection(String userName, String password) throws JMSException {
080        return (XATopicConnection) createActiveMQConnection(userName, password);
081    }
082
083    protected ActiveMQConnection createActiveMQConnection(Transport transport, JMSStatsImpl stats) throws Exception {
084        ActiveMQXAConnection connection = new ActiveMQXAConnection(transport, getClientIdGenerator(), getConnectionIdGenerator(), stats);
085        configureXAConnection(connection);
086        return connection;
087    }
088
089    private void configureXAConnection(ActiveMQXAConnection connection) {
090        connection.setXaAckMode(xaAckMode);
091    }
092
093    public int getXaAckMode() {
094        return xaAckMode;
095    }
096
097    public void setXaAckMode(int xaAckMode) {
098        this.xaAckMode = xaAckMode;
099    }
100
101    @Override
102    public void populateProperties(Properties props) {
103        super.populateProperties(props);
104        props.put("xaAckMode", Integer.toString(xaAckMode));
105    }
106}