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.command;
018    
019    import java.io.IOException;
020    
021    import org.apache.activemq.state.CommandVisitor;
022    
023    /**
024     * 
025     * @openwire:marshaller code="7"
026     * 
027     */
028    public class TransactionInfo extends BaseCommand {
029    
030        public static final byte DATA_STRUCTURE_TYPE = CommandTypes.TRANSACTION_INFO;
031    
032        public static final byte BEGIN = 0;
033        public static final byte PREPARE = 1;
034        public static final byte COMMIT_ONE_PHASE = 2;
035        public static final byte COMMIT_TWO_PHASE = 3;
036        public static final byte ROLLBACK = 4;
037        public static final byte RECOVER = 5;
038        public static final byte FORGET = 6;
039        public static final byte END = 7;
040    
041        protected byte type;
042        protected ConnectionId connectionId;
043        protected TransactionId transactionId;
044    
045        public TransactionInfo() {
046        }
047    
048        public TransactionInfo(ConnectionId connectionId, TransactionId transactionId, byte type) {
049            this.connectionId = connectionId;
050            this.transactionId = transactionId;
051            this.type = type;
052        }
053    
054        public byte getDataStructureType() {
055            return DATA_STRUCTURE_TYPE;
056        }
057    
058        /**
059         * @openwire:property version=1 cache=true
060         */
061        public ConnectionId getConnectionId() {
062            return connectionId;
063        }
064    
065        public void setConnectionId(ConnectionId connectionId) {
066            this.connectionId = connectionId;
067        }
068    
069        /**
070         * @openwire:property version=1 cache=true
071         */
072        public TransactionId getTransactionId() {
073            return transactionId;
074        }
075    
076        public void setTransactionId(TransactionId transactionId) {
077            this.transactionId = transactionId;
078        }
079    
080        /**
081         * @openwire:property version=1
082         */
083        public byte getType() {
084            return type;
085        }
086    
087        public void setType(byte type) {
088            this.type = type;
089        }
090    
091        public Response visit(CommandVisitor visitor) throws Exception {
092            switch (type) {
093            case TransactionInfo.BEGIN:
094                return visitor.processBeginTransaction(this);
095            case TransactionInfo.END:
096                return visitor.processEndTransaction(this);
097            case TransactionInfo.PREPARE:
098                return visitor.processPrepareTransaction(this);
099            case TransactionInfo.COMMIT_ONE_PHASE:
100                return visitor.processCommitTransactionOnePhase(this);
101            case TransactionInfo.COMMIT_TWO_PHASE:
102                return visitor.processCommitTransactionTwoPhase(this);
103            case TransactionInfo.ROLLBACK:
104                return visitor.processRollbackTransaction(this);
105            case TransactionInfo.RECOVER:
106                return visitor.processRecoverTransactions(this);
107            case TransactionInfo.FORGET:
108                return visitor.processForgetTransaction(this);
109            default:
110                throw new IOException("Transaction info type unknown: " + type);
111            }
112        }
113    
114    }