001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.objectserver.gtx;
006:
007: import com.tc.net.groups.NodeID;
008: import com.tc.object.gtx.GlobalTransactionID;
009: import com.tc.object.tx.ServerTransactionID;
010: import com.tc.objectserver.persistence.api.PersistenceTransaction;
011: import com.tc.objectserver.persistence.api.PersistenceTransactionProvider;
012: import com.tc.objectserver.persistence.api.TransactionStore;
013: import com.tc.util.SequenceValidator;
014: import com.tc.util.sequence.Sequence;
015:
016: import java.util.Collection;
017: import java.util.Set;
018:
019: public class ServerGlobalTransactionManagerImpl implements
020: ServerGlobalTransactionManager {
021:
022: private final TransactionStore transactionStore;
023: private final PersistenceTransactionProvider persistenceTransactionProvider;
024: private final SequenceValidator sequenceValidator;
025: private final GlobalTransactionIDSequenceProvider gidSequenceProvider;
026: private final Sequence globalTransactionIDSequence;
027:
028: public ServerGlobalTransactionManagerImpl(
029: SequenceValidator sequenceValidator,
030: TransactionStore transactionStore,
031: PersistenceTransactionProvider ptxp,
032: GlobalTransactionIDSequenceProvider gidSequenceProvider,
033: Sequence globalTransactionIDSequence) {
034: this .sequenceValidator = sequenceValidator;
035: this .transactionStore = transactionStore;
036: this .persistenceTransactionProvider = ptxp;
037: this .gidSequenceProvider = gidSequenceProvider;
038: this .globalTransactionIDSequence = globalTransactionIDSequence;
039: }
040:
041: public void shutdownNode(NodeID nodeID) {
042: this .sequenceValidator.remove(nodeID);
043: PersistenceTransaction tx = this .persistenceTransactionProvider
044: .newTransaction();
045: transactionStore.shutdownNode(tx, nodeID);
046: tx.commit();
047: }
048:
049: public void shutdownAllClientsExcept(Set cids) {
050: PersistenceTransaction tx = this .persistenceTransactionProvider
051: .newTransaction();
052: transactionStore.shutdownAllClientsExcept(tx, cids);
053: tx.commit();
054: }
055:
056: public boolean initiateApply(ServerTransactionID stxID) {
057: GlobalTransactionDescriptor gtx = this .transactionStore
058: .getTransactionDescriptor(stxID);
059: return gtx.initiateApply();
060: }
061:
062: public void clearCommitedTransactionsBelowLowWaterMark(
063: ServerTransactionID sid) {
064: PersistenceTransaction tx = this .persistenceTransactionProvider
065: .newTransaction();
066: transactionStore.clearCommitedTransactionsBelowLowWaterMark(tx,
067: sid);
068: tx.commit();
069: }
070:
071: public void clearCommitedTransactionsBelowLowWaterMark(
072: GlobalTransactionID lowGlobalTransactionIDWatermark) {
073: PersistenceTransaction tx = this .persistenceTransactionProvider
074: .newTransaction();
075: transactionStore.clearCommitedTransactionsBelowLowWaterMark(tx,
076: lowGlobalTransactionIDWatermark);
077: tx.commit();
078: }
079:
080: public void commit(PersistenceTransaction persistenceTransaction,
081: ServerTransactionID stxID) {
082: transactionStore.commitTransactionDescriptor(
083: persistenceTransaction, stxID);
084: }
085:
086: public void commitAll(
087: PersistenceTransaction persistenceTransaction,
088: Collection stxIDs) {
089: transactionStore.commitAllTransactionDescriptor(
090: persistenceTransaction, stxIDs);
091: }
092:
093: public GlobalTransactionID getLowGlobalTransactionIDWatermark() {
094: return transactionStore.getLeastGlobalTransactionID();
095: }
096:
097: public GlobalTransactionID getOrCreateGlobalTransactionID(
098: ServerTransactionID serverTransactionID) {
099: GlobalTransactionDescriptor gdesc = transactionStore
100: .getOrCreateTransactionDescriptor(serverTransactionID);
101: return gdesc.getGlobalTransactionID();
102: }
103:
104: public GlobalTransactionID getGlobalTransactionID(
105: ServerTransactionID serverTransactionID) {
106: GlobalTransactionDescriptor gdesc = transactionStore
107: .getTransactionDescriptor(serverTransactionID);
108: return (gdesc != null ? gdesc.getGlobalTransactionID()
109: : GlobalTransactionID.NULL_ID);
110:
111: }
112:
113: public void createGlobalTransactionDescIfNeeded(
114: ServerTransactionID stxnID,
115: GlobalTransactionID globalTransactionID) {
116: transactionStore.createGlobalTransactionDescIfNeeded(stxnID,
117: globalTransactionID);
118: }
119:
120: public GlobalTransactionIDSequenceProvider getGlobalTransactionIDSequenceProvider() {
121: return gidSequenceProvider;
122: }
123:
124: public Sequence getGlobalTransactionIDSequence() {
125: return globalTransactionIDSequence;
126: }
127: }
|