1 4 package com.tc.objectserver.gtx; 5 6 import com.tc.net.protocol.tcm.ChannelID; 7 import com.tc.object.gtx.GlobalTransactionID; 8 import com.tc.object.tx.ServerTransactionID; 9 import com.tc.objectserver.persistence.api.PersistenceTransaction; 10 import com.tc.objectserver.persistence.api.PersistenceTransactionProvider; 11 import com.tc.objectserver.persistence.api.TransactionStore; 12 import com.tc.util.SequenceValidator; 13 14 import java.util.Collection ; 15 import java.util.HashSet ; 16 import java.util.Iterator ; 17 import java.util.Set ; 18 19 public class ServerGlobalTransactionManagerImpl implements ServerGlobalTransactionManager { 20 21 private final TransactionStore transactionStore; 22 private final PersistenceTransactionProvider persistenceTransactionProvider; 23 private final SequenceValidator sequenceValidator; 24 private final Set resentServerTransactionIDs = new HashSet (); 25 26 public ServerGlobalTransactionManagerImpl(SequenceValidator sequenceValidator, TransactionStore transactionStore, 27 PersistenceTransactionProvider ptxp) { 28 super(); 29 this.sequenceValidator = sequenceValidator; 30 this.transactionStore = transactionStore; 31 this.persistenceTransactionProvider = ptxp; 32 } 33 34 public void shutdownClient(ChannelID channelID) { 35 this.sequenceValidator.remove(channelID); 36 PersistenceTransaction tx = this.persistenceTransactionProvider.newTransaction(); 37 transactionStore.shutdownClient(tx, channelID); 38 tx.commit(); 39 } 40 41 public boolean needsApply(ServerTransactionID stxID) { 42 GlobalTransactionDescriptor gtx = this.transactionStore.getTransactionDescriptor(stxID); 43 return (gtx == null); 44 } 45 46 private void assertNull(ServerTransactionID stxID, GlobalTransactionDescriptor gtx) { 47 if (gtx != null) throw new TransactionCommittedError("Transaction Already exists : " + stxID); 48 } 49 50 public void completeTransactions(PersistenceTransaction tx, Collection collection) { 51 if(collection.isEmpty()) return; 52 transactionStore.removeAllByServerTransactionID(tx, collection); 53 } 54 55 public void commit(PersistenceTransaction persistenceTransaction, ServerTransactionID stxID) { 56 GlobalTransactionDescriptor desc = transactionStore.getTransactionDescriptor(stxID); 57 assertNull(stxID, desc); 58 desc = transactionStore.createTransactionDescriptor(stxID); 59 transactionStore.commitTransactionDescriptor(persistenceTransaction, desc); 60 } 61 62 public void commitAll(PersistenceTransaction persistenceTransaction, Collection stxIDs) { 63 for (Iterator i = stxIDs.iterator(); i.hasNext();) { 64 ServerTransactionID stxID = (ServerTransactionID) i.next(); 65 commit(persistenceTransaction, stxID); 66 } 67 } 68 69 public synchronized GlobalTransactionID getLowGlobalTransactionIDWatermark() { 70 if (resentServerTransactionIDs.isEmpty()) { 71 return transactionStore.getLeastGlobalTransactionID(); 72 } else { 73 return GlobalTransactionID.NULL_ID; 74 } 75 } 76 77 public GlobalTransactionID createGlobalTransactionID(ServerTransactionID stxnID) { 78 return transactionStore.createGlobalTransactionID(stxnID); 79 } 80 81 public synchronized void addResentServerTransactionIDs(Collection stxIDs) { 82 resentServerTransactionIDs.addAll(stxIDs); 83 } 84 85 public synchronized void transactionCompleted(ServerTransactionID stxID) { 87 resentServerTransactionIDs.remove(stxID); 88 } 89 90 public void clearAllTransactionsFor(ChannelID client) { 91 for (Iterator iter = resentServerTransactionIDs.iterator(); iter.hasNext();) { 92 ServerTransactionID stxID = (ServerTransactionID) iter.next(); 93 if (stxID.getChannelID().equals(client)) { 94 iter.remove(); 95 } 96 } 97 } 98 99 public void transactionApplied(ServerTransactionID stxID) { 100 return; 101 } 102 103 public void incomingTransactions(ChannelID cid, Set serverTxnIDs) { 104 return; 105 } 106 } 107 | Popular Tags |