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.tctest;
06:
07: import com.tc.object.config.ConfigVisitor;
08: import com.tc.object.config.DSOClientConfigHelper;
09: import com.tc.simulator.app.ApplicationConfig;
10: import com.tc.simulator.listener.ListenerProvider;
11: import com.tctest.runner.AbstractTransparentApp;
12: import com.tctest.runner.TransparentAppConfig;
13:
14: import java.util.HashMap;
15: import java.util.Iterator;
16: import java.util.Map;
17:
18: public class RootInRootClassTestApp extends AbstractTransparentApp {
19:
20: private Map myInnerInMap;
21:
22: public RootInRootClassTestApp() {
23: super ("", new TransparentAppConfig(null, null, 0, 0, null),
24: null);
25: Map m = new HashMap();
26: m.put(new Long(System.currentTimeMillis()), new TestObject());
27: myInnerInMap = m;
28:
29: System.out.println("CALLED NO ARG CONST:");
30: new Error().printStackTrace();
31: }
32:
33: public RootInRootClassTestApp(String appId, ApplicationConfig cfg,
34: ListenerProvider listenerProvider) {
35: super (appId, cfg, listenerProvider);
36: Map m = new HashMap();
37: m.put(new Long(System.currentTimeMillis()), new TestObject());
38: myInnerInMap = m;
39: }
40:
41: public int getMapSize() {
42: synchronized (myInnerInMap) {
43: return myInnerInMap.size();
44: }
45: }
46:
47: public void run() {
48:
49: try {
50: synchronized (myInnerInMap) {
51: myInnerInMap.put("test" + myInnerInMap.size(),
52: new TestObject());
53: System.out.println("myInnerMap size:"
54: + myInnerInMap.size());
55: for (Iterator i = myInnerInMap.values().iterator(); i
56: .hasNext();) {
57: TestObject to = (TestObject) i.next();
58: to.doStuff();
59: }
60: }
61: Thread.sleep(1000);
62: } catch (Exception e) {
63: e.printStackTrace();
64: }
65: }
66:
67: public class TestObject {
68:
69: public void doStuff() {
70: System.out.println("myInner:" + getMapSize());
71: }
72: // blah
73: }
74:
75: public static void visitL1DSOConfig(ConfigVisitor visitor,
76: DSOClientConfigHelper config) {
77: String testClass = RootInRootClassTestApp.class.getName();
78: config.addIncludePattern(testClass, false);
79:
80: String methodExpression = "* " + testClass + "*.*(..)";
81: config.addWriteAutolock(methodExpression);
82: config.getOrCreateSpec(testClass).addRoot("myInnerInMap",
83: "myInnerInMap");
84:
85: config.addIncludePattern(TestObject.class.getName());
86: }
87:
88: }
|