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.object.gtx;
06:
07: import com.tc.object.tx.ServerTransactionID;
08:
09: import java.util.HashMap;
10: import java.util.Map;
11: import java.util.SortedSet;
12: import java.util.TreeSet;
13:
14: public class DefaultGlobalTransactionIDGenerator implements
15: GlobalTransactionIDGenerator {
16:
17: SortedSet gidSet = new TreeSet();
18: Map sid2Gid = new HashMap();
19: long id = 0;
20:
21: public GlobalTransactionID getOrCreateGlobalTransactionID(
22: ServerTransactionID serverTransactionID) {
23:
24: GlobalTransactionID gid = (GlobalTransactionID) sid2Gid
25: .get(serverTransactionID);
26: if (gid == null) {
27: gid = new GlobalTransactionID(id++);
28: sid2Gid.put(serverTransactionID, gid);
29: gidSet.add(gid);
30: }
31: return gid;
32: }
33:
34: public GlobalTransactionID getLowGlobalTransactionIDWatermark() {
35: if (gidSet.isEmpty()) {
36: return GlobalTransactionID.NULL_ID;
37: } else {
38: GlobalTransactionID lowWaterMark = (GlobalTransactionID) gidSet
39: .first();
40: return lowWaterMark;
41: }
42: }
43: }
|