1 4 package com.tcsimulator; 5 6 import com.tc.object.config.ConfigVisitor; 7 import com.tc.object.config.DSOClientConfigHelper; 8 import com.tc.object.config.TransparencyClassSpec; 9 import com.tc.simulator.app.GlobalIdGenerator; 10 11 import java.util.ArrayList ; 12 import java.util.List ; 13 14 public class DistributedGlobalIdGenerator implements GlobalIdGenerator { 15 16 private final List currentId = new ArrayList (); 17 18 public long nextId() { 19 synchronized (currentId) { 20 Long newId; 21 if (currentId.size() == 0) { 22 newId = new Long (0); 23 currentId.add(newId); 24 } else { 25 Long id = (Long ) currentId.get(0); 26 newId = new Long (id.longValue() + 1); 27 currentId.set(0, newId); 28 } 29 return newId.longValue(); 30 } 31 } 32 33 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper cfg) { 34 String classname = DistributedGlobalIdGenerator.class.getName(); 35 TransparencyClassSpec spec = cfg.getOrCreateSpec(classname); 36 spec.addRoot("DistributedGlobalIdGeneratorcurrentId", classname + ".currentId"); 37 cfg.addWriteAutolock("long " + classname + ".nextId()"); 38 } 39 40 public static void visitDSOApplicationConfig(com.tc.object.config.ConfigVisitor visitor, 41 com.tc.object.config.DSOApplicationConfig config) { 42 String classname = DistributedGlobalIdGenerator.class.getName(); 43 config.addIncludePattern(classname); 44 config.addRoot("DistributedGlobalIdGeneratorcurrentId", classname + ".currentId"); 45 config.addWriteAutolock("* " + classname + ".*(..)"); 46 } 47 48 }
| Popular Tags
|