01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.gtx;
06:
07: import com.tc.object.gtx.GlobalTransactionID;
08: import com.tc.object.tx.ServerTransactionID;
09: import com.tc.object.tx.TransactionID;
10: import com.tc.util.State;
11:
12: public class GlobalTransactionDescriptor {
13:
14: private static final State INIT = new State("INIT");
15: private static final State APPLY_INITIATED = new State(
16: "APPLY_INITIATED");
17: private static final State COMMIT_COMPLETE = new State(
18: "COMMIT_COMPLETE");
19:
20: private final ServerTransactionID stxn;
21: private final GlobalTransactionID gid;
22: private volatile State state;
23:
24: public GlobalTransactionDescriptor(
25: ServerTransactionID serverTransactionID,
26: GlobalTransactionID gid) {
27: this .stxn = serverTransactionID;
28: this .gid = gid;
29: this .state = INIT;
30: }
31:
32: public void saveStateFrom(GlobalTransactionDescriptor old) {
33: this .state = old.state;
34: }
35:
36: public void commitComplete() {
37: if (this .state == COMMIT_COMPLETE) {
38: throw new AssertionError("Already commited : " + this
39: + " state = " + state);
40: }
41: this .state = COMMIT_COMPLETE;
42: }
43:
44: public boolean initiateApply() {
45: boolean toInitiate = (this .state == INIT);
46: if (toInitiate) {
47: this .state = APPLY_INITIATED;
48: }
49: return toInitiate;
50: }
51:
52: public boolean isCommitted() {
53: return this .state == COMMIT_COMPLETE;
54: }
55:
56: public String toString() {
57: return "GlobalTransactionDescriptor[" + stxn + "," + gid + ","
58: + state + "]";
59: }
60:
61: public TransactionID getClientTransactionID() {
62: return stxn.getClientTransactionID();
63: }
64:
65: public int hashCode() {
66: return (37 * stxn.hashCode()) + gid.hashCode();
67: }
68:
69: public boolean equals(Object o) {
70: if (o == null)
71: return false;
72: if (!(o instanceof GlobalTransactionDescriptor))
73: return false;
74: if (o == this )
75: return true;
76: GlobalTransactionDescriptor c = (GlobalTransactionDescriptor) o;
77: return this .stxn.equals(c.stxn) && this .gid.equals(c.gid);
78: }
79:
80: public ServerTransactionID getServerTransactionID() {
81: return stxn;
82: }
83:
84: public GlobalTransactionID getGlobalTransactionID() {
85: return gid;
86: }
87:
88: public boolean complete() {
89: return (state == COMMIT_COMPLETE);
90: }
91: }
|