01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.tx;
06:
07: import com.tc.net.groups.NodeID;
08: import com.tc.object.tx.ServerTransactionID;
09: import com.tc.object.tx.TransactionID;
10:
11: import java.util.Collections;
12: import java.util.HashSet;
13: import java.util.Set;
14:
15: public class PassiveTransactionAccount implements TransactionAccount {
16:
17: private final NodeID nodeID;
18: private final Set txnIDs = Collections
19: .synchronizedSet(new HashSet());
20: private CallBackOnComplete callback;
21: private boolean dead = false;
22:
23: public PassiveTransactionAccount(NodeID source) {
24: this .nodeID = source;
25: }
26:
27: public void addWaitee(NodeID waitee, TransactionID requestID) {
28: throw new AssertionError(
29: "Transactions should never be broadcasted in Passive Server : "
30: + waitee + " , " + requestID);
31: }
32:
33: public boolean applyCommitted(TransactionID requestID) {
34: synchronized (txnIDs) {
35: txnIDs.remove(new ServerTransactionID(nodeID, requestID));
36: invokeCallBackOnCompleteIfNecessary();
37: }
38: return true;
39: }
40:
41: public boolean broadcastCompleted(TransactionID requestID) {
42: throw new AssertionError(
43: "Transactions should never be broadcasted in Passive Server");
44: }
45:
46: public NodeID getNodeID() {
47: return nodeID;
48: }
49:
50: public boolean hasWaitees(TransactionID requestID) {
51: return false;
52: }
53:
54: public boolean removeWaitee(NodeID waitee, TransactionID requestID) {
55: throw new AssertionError(
56: "Transactions should never be ACKED to Passive Server");
57: }
58:
59: public Set requestersWaitingFor(NodeID waitee) {
60: return Collections.EMPTY_SET;
61: }
62:
63: public boolean skipApplyAndCommit(TransactionID requestID) {
64: synchronized (txnIDs) {
65: txnIDs.remove(new ServerTransactionID(nodeID, requestID));
66: invokeCallBackOnCompleteIfNecessary();
67: }
68: return true;
69: }
70:
71: public boolean relayTransactionComplete(TransactionID requestID) {
72: throw new AssertionError(
73: "Transactions should never be relayed from Passive Server");
74: }
75:
76: public void addAllPendingServerTransactionIDsTo(HashSet txnsInSystem) {
77: synchronized (txnIDs) {
78: txnsInSystem.addAll(txnIDs);
79: }
80: }
81:
82: public void incommingTransactions(Set serverTxnsIDs) {
83: txnIDs.addAll(serverTxnsIDs);
84: }
85:
86: public void nodeDead(CallBackOnComplete callBack) {
87: synchronized (txnIDs) {
88: this .callback = callBack;
89: this .dead = true;
90: invokeCallBackOnCompleteIfNecessary();
91: }
92: }
93:
94: private void invokeCallBackOnCompleteIfNecessary() {
95: if (dead && txnIDs.isEmpty()) {
96: callback.onComplete(nodeID);
97: }
98: }
99: }
|