1 4 package com.tc.object.gtx; 5 6 import com.tc.net.protocol.tcm.ChannelID; 7 import com.tc.object.lockmanager.api.LockFlushCallback; 8 import com.tc.object.lockmanager.api.LockID; 9 import com.tc.object.tx.RemoteTransactionManager; 10 import com.tc.object.tx.ServerTransactionID; 11 import com.tc.object.tx.TransactionID; 12 13 import java.util.Collection ; 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 import java.util.Set ; 18 import java.util.SortedMap ; 19 import java.util.TreeMap ; 20 import java.util.Map.Entry; 21 22 public class ClientGlobalTransactionManagerImpl implements ClientGlobalTransactionManager { 23 24 private static final int ALLOWED_LWM_DELTA = 100; 25 private final Set applied = new HashSet (); 26 private final SortedMap globalTransactionIDs = new TreeMap (GlobalTransactionID.COMPARATOR); 27 28 private GlobalTransactionID lowWatermark = GlobalTransactionID.NULL_ID; 29 private final RemoteTransactionManager remoteTransactionManager; 30 31 public ClientGlobalTransactionManagerImpl(RemoteTransactionManager remoteTransactionManager) { 32 this.remoteTransactionManager = remoteTransactionManager; 33 } 34 35 public synchronized int size() { 37 return applied.size(); 38 } 39 40 public int getAllowedLowWaterMarkDelta() { 42 return ALLOWED_LWM_DELTA; 43 } 44 45 public synchronized boolean startApply(ChannelID committerID, TransactionID transactionID, GlobalTransactionID gtxID) { 46 if (gtxID.lessThan(getLowGlobalTransactionIDWatermark())) { 47 throw new UnknownTransactionError("Attempt to apply a transaction lower than the low watermark: gtxID=" + gtxID 49 + ", low watermark=" + getLowGlobalTransactionIDWatermark()); 50 } 51 ServerTransactionID serverTransactionID = new ServerTransactionID(committerID, transactionID); 52 globalTransactionIDs.put(gtxID, serverTransactionID); 53 return applied.add(serverTransactionID); 54 } 55 56 public synchronized GlobalTransactionID getLowGlobalTransactionIDWatermark() { 57 return lowWatermark; 58 } 59 60 public synchronized void setLowWatermark(GlobalTransactionID lowWatermark) { 61 if (this.lowWatermark.toLong() + ALLOWED_LWM_DELTA > lowWatermark.toLong()) { 62 return; 64 } 65 this.lowWatermark = lowWatermark; 66 Map toDelete = globalTransactionIDs.headMap(lowWatermark); 67 for (Iterator i = toDelete.entrySet().iterator(); i.hasNext();) { 68 Entry e = (Entry) i.next(); 69 ServerTransactionID stxID = (ServerTransactionID) e.getValue(); 70 i.remove(); 71 applied.remove(stxID); 72 } 73 } 74 75 public void flush(LockID lockID) { 76 remoteTransactionManager.flush(lockID); 77 } 78 79 public boolean isTransactionsForLockFlushed(LockID lockID, LockFlushCallback callback) { 80 return remoteTransactionManager.isTransactionsForLockFlushed(lockID, callback); 81 } 82 83 public void unpause() { 84 remoteTransactionManager.unpause(); 85 } 86 87 public void pause() { 88 remoteTransactionManager.pause(); 89 } 90 91 public void resendOutstanding() { 92 remoteTransactionManager.resendOutstanding(); 93 } 94 95 public Collection getTransactionSequenceIDs() { 96 return remoteTransactionManager.getTransactionSequenceIDs(); 97 } 98 99 public Collection getResentTransactionIDs() { 100 return remoteTransactionManager.getResentTransactionIDs(); 101 } 102 103 public void starting() { 104 remoteTransactionManager.starting(); 105 } 106 107 public void resendOutstandingAndUnpause() { 108 remoteTransactionManager.resendOutstandingAndUnpause(); 109 } 110 111 } 112 | Popular Tags |