01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tcsimulator;
05:
06: import com.tc.object.config.ConfigVisitor;
07: import com.tc.object.config.DSOApplicationConfig;
08:
09: 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
30: + newId.longValue();
31: }
32: }
33:
34: public static void visitDSOApplicationConfig(ConfigVisitor visitor,
35: DSOApplicationConfig config) {
36: String classname = GlobalVmNameGenerator.class.getName();
37: config.addIncludePattern(classname);
38: config.addRoot("currentId", classname + ".currentId");
39: config.addWriteAutolock("* " + classname + ".*(..)");
40: }
41:
42: }
|