KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > state > TransactionState


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.state;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.apache.activemq.command.Command;
24 import org.apache.activemq.command.TransactionId;
25
26 import java.util.concurrent.atomic.AtomicBoolean JavaDoc;
27
28 public class TransactionState {
29     final TransactionId id;
30     
31     public final ArrayList JavaDoc commands = new ArrayList JavaDoc();
32     private final AtomicBoolean JavaDoc shutdown = new AtomicBoolean JavaDoc(false);
33
34     private boolean prepared;
35
36     private int preparedResult;
37     
38     public TransactionState(TransactionId id) {
39         this.id = id;
40     }
41     public String JavaDoc toString() {
42         return id.toString();
43     }
44     
45     public void addCommand(Command operation) {
46         checkShutdown();
47         commands.add(operation);
48     }
49
50     public List JavaDoc getCommands() {
51         return commands;
52     }
53     
54     private void checkShutdown() {
55         if( shutdown.get() )
56             throw new IllegalStateException JavaDoc("Disposed");
57     }
58     
59     public void shutdown() {
60         shutdown.set(false);
61     }
62     public TransactionId getId() {
63         return id;
64     }
65     
66     public void setPrepared(boolean prepared) {
67         this.prepared = prepared;
68     }
69     public boolean isPrepared() {
70         return prepared;
71     }
72     public void setPreparedResult(int preparedResult) {
73         this.preparedResult = preparedResult;
74     }
75     public int getPreparedResult() {
76         return preparedResult;
77     }
78
79 }
80
Popular Tags