01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tcsimulator;
06:
07: import com.tc.object.config.ConfigLockLevel;
08: import com.tc.object.config.ConfigVisitor;
09: import com.tc.object.config.DSOClientConfigHelper;
10: import com.tc.object.config.Root;
11: import com.tc.simulator.control.Control;
12: import com.tc.simulator.crasher.ControlProvider;
13:
14: import java.util.HashMap;
15: import java.util.Map;
16:
17: public class ControlProviderImpl implements ControlProvider {
18:
19: private final Map controls;
20:
21: public static void visitL1DSOConfig(ConfigVisitor visitor,
22: DSOClientConfigHelper config) {
23: String classname = ControlProviderImpl.class.getName();
24: config.addIncludePattern(classname);
25: config.addAutolock("* " + classname + ".*(..)",
26: ConfigLockLevel.WRITE);
27: config.addRoot(new Root(classname, "controls", classname
28: + ".controls"), true);
29: ControlImpl.visitL1DSOConfig(visitor, config);
30: }
31:
32: public static void visitDSOApplicationConfig(
33: com.tc.object.config.ConfigVisitor visitor,
34: com.tc.object.config.DSOApplicationConfig config) {
35: String classname = ControlProviderImpl.class.getName();
36: config.addIncludePattern(classname);
37: config.addWriteAutolock("* " + classname + ".*(..)");
38: config.addRoot("controls", classname + ".controls");
39: visitor.visitDSOApplicationConfig(config, ControlImpl.class);
40: }
41:
42: public ControlProviderImpl() {
43: controls = new HashMap();
44: }
45:
46: public Control getOrCreateControlByName(String name, int parties) {
47: synchronized (controls) {
48: Control rv = (Control) controls.get(name);
49: if (rv == null) {
50: rv = new ControlImpl(parties);
51: controls.put(name, rv);
52: }
53: return rv;
54: }
55: }
56:
57: }
|