1 4 package com.tcsimulator; 5 6 import com.tc.object.config.ConfigVisitor; 7 import com.tc.object.config.DSOApplicationConfig; 8 9 import java.util.ArrayList ; 10 import java.util.List ; 11 12 public class GlobalVmNameGenerator { 13 14 private static final String VM_NAME_PREFIX = "vm"; 15 private List currentId = new ArrayList (); 16 17 public String nextVmName() { 18 synchronized (currentId) { 19 Long newId; 20 if (currentId.size() == 0) { 21 newId = new Long (0); 22 currentId.add(newId); 23 } else { 24 Long id = (Long ) currentId.get(0); 25 newId = new Long (id.longValue() + 1); 26 currentId.set(0, newId); 27 } 28 29 return GlobalVmNameGenerator.VM_NAME_PREFIX + newId.longValue(); 30 } 31 } 32 33 public static void visitDSOApplicationConfig(ConfigVisitor visitor, DSOApplicationConfig config) { 34 String classname = GlobalVmNameGenerator.class.getName(); 35 config.addIncludePattern(classname); 36 config.addRoot("currentId", classname + ".currentId"); 37 config.addWriteAutolock("* " + classname + ".*(..)"); 38 } 39 40 } 41 | Popular Tags |