KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tcsimulator > ControlProviderImpl


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.ConfigLockLevel;
7 import com.tc.object.config.ConfigVisitor;
8 import com.tc.object.config.DSOClientConfigHelper;
9 import com.tc.simulator.control.Control;
10 import com.tc.simulator.crasher.ControlProvider;
11
12 import java.util.HashMap JavaDoc;
13 import java.util.Map JavaDoc;
14
15 public class ControlProviderImpl implements ControlProvider {
16
17   private final Map JavaDoc controls;
18
19   public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) {
20     String JavaDoc classname = ControlProviderImpl.class.getName();
21     config.addIncludePattern(classname);
22     config.addAutolock("* " + classname + ".*(..)", ConfigLockLevel.WRITE);
23     config.addRoot(classname, "controls", classname + ".controls", true);
24     ControlImpl.visitL1DSOConfig(visitor, config);
25   }
26
27   public static void visitDSOApplicationConfig(com.tc.object.config.ConfigVisitor visitor,
28                                                com.tc.object.config.DSOApplicationConfig config) {
29     String JavaDoc classname = ControlProviderImpl.class.getName();
30     config.addIncludePattern(classname);
31     config.addWriteAutolock("* " + classname + ".*(..)");
32     config.addRoot("controls", classname + ".controls");
33     visitor.visitDSOApplicationConfig(config, ControlImpl.class);
34   }
35
36   public ControlProviderImpl() {
37     controls = new HashMap JavaDoc();
38   }
39
40   public Control getOrCreateControlByName(String JavaDoc name, int parties) {
41     synchronized (controls) {
42       Control rv = (Control) controls.get(name);
43       if (rv == null) {
44         rv = new ControlImpl(parties);
45         controls.put(name, rv);
46       }
47       return rv;
48     }
49   }
50
51 }
52
Popular Tags