KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tcsimulator > GlobalVmNameGenerator


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
10 import java.util.List JavaDoc;
11
12 public class GlobalVmNameGenerator {
13
14   private static final String JavaDoc VM_NAME_PREFIX = "vm";
15   private List JavaDoc currentId = new ArrayList JavaDoc();
16
17   public String JavaDoc nextVmName() {
18     synchronized (currentId) {
19       Long JavaDoc newId;
20       if (currentId.size() == 0) {
21         newId = new Long JavaDoc(0);
22         currentId.add(newId);
23       } else {
24         Long JavaDoc id = (Long JavaDoc) currentId.get(0);
25         newId = new Long JavaDoc(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 JavaDoc classname = GlobalVmNameGenerator.class.getName();
35     config.addIncludePattern(classname);
36     config.addRoot("currentId", classname + ".currentId");
37     config.addWriteAutolock("* " + classname + ".*(..)");
38   }
39   
40 }
41
Popular Tags