Home » activemq-parent-5.3.1-source-release » org.apache » activemq » state » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  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   package org.apache.activemq.state;
   18   
   19   import java.util.ArrayList;
   20   import java.util.List;
   21   import java.util.Map;
   22   import java.util.concurrent.ConcurrentHashMap;
   23   import java.util.concurrent.atomic.AtomicBoolean;
   24   
   25   import org.apache.activemq.command.Command;
   26   import org.apache.activemq.command.ProducerId;
   27   import org.apache.activemq.command.TransactionId;
   28   
   29   public class TransactionState {
   30   
   31       private final List<Command> commands = new ArrayList<Command>();
   32       private final TransactionId id;
   33       private final AtomicBoolean shutdown = new AtomicBoolean(false);
   34       private boolean prepared;
   35       private int preparedResult;
   36       private final Map<ProducerId, ProducerState> producers = new ConcurrentHashMap<ProducerId, ProducerState>();
   37   
   38       public TransactionState(TransactionId id) {
   39           this.id = id;
   40       }
   41   
   42       public String toString() {
   43           return id.toString();
   44       }
   45   
   46       public void addCommand(Command operation) {
   47           checkShutdown();
   48           commands.add(operation);
   49       }
   50   
   51       public List<Command> getCommands() {
   52           return commands;
   53       }
   54   
   55       private void checkShutdown() {
   56           if (shutdown.get()) {
   57               throw new IllegalStateException("Disposed");
   58           }
   59       }
   60   
   61       public void shutdown() {
   62           shutdown.set(false);
   63       }
   64   
   65       public TransactionId getId() {
   66           return id;
   67       }
   68   
   69       public void setPrepared(boolean prepared) {
   70           this.prepared = prepared;
   71       }
   72   
   73       public boolean isPrepared() {
   74           return prepared;
   75       }
   76   
   77       public void setPreparedResult(int preparedResult) {
   78           this.preparedResult = preparedResult;
   79       }
   80   
   81       public int getPreparedResult() {
   82           return preparedResult;
   83       }
   84   
   85       public void addProducerState(ProducerState producerState) {
   86           if (producerState != null) {
   87               producers.put(producerState.getInfo().getProducerId(), producerState);
   88           }
   89       }
   90   
   91       public Map<ProducerId, ProducerState> getProducerStates() {
   92           return producers;
   93       }
   94   
   95   }

Home » activemq-parent-5.3.1-source-release » org.apache » activemq » state » [javadoc | source]