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.tctest;
05:
06: import com.tc.config.schema.setup.FatalIllegalConfigurationChangeHandler;
07: import com.tc.config.schema.setup.L1TVSConfigurationSetupManager;
08: import com.tc.config.schema.setup.StandardTVSConfigurationSetupManagerFactory;
09: import com.tc.object.bytecode.hook.impl.PreparedComponentsFromL2Connection;
10: import com.tc.object.config.StandardDSOClientConfigHelperImpl;
11: import com.tc.object.loaders.IsolationClassLoader;
12:
13: import java.io.BufferedReader;
14: import java.io.InputStreamReader;
15: import java.lang.reflect.Method;
16: import java.util.HashMap;
17:
18: /**
19: * A little DSO client class. One use of this program (ie. the reason I'm writing it) is to easily create a few DSO
20: * requests of an L2 so that I can profile the server's basic operations in OptimizeIt
21: */
22: public class StupidSimpleDSOClient {
23:
24: private final HashMap root = new HashMap();
25: private final String putCountKey = "putCount";
26:
27: public void run() {
28: for (int i = 0; i < 10; i++) {
29: synchronized (root) {
30: System.out.println("put returned: "
31: + root.put("key", "value"));
32: incrementPutCount();
33: System.out.println("put count: "
34: + root.get(putCountKey));
35: }
36:
37: synchronized (root) {
38: System.out.println("value = " + root.get("key"));
39: }
40:
41: synchronized (root) {
42: root.remove("key");
43: System.out.println(root.size());
44: }
45: }
46: }
47:
48: private final void incrementPutCount() {
49: StupidSimpleDSOClientCounter counter = (StupidSimpleDSOClientCounter) root
50: .get(putCountKey);
51: if (counter == null) {
52: counter = new StupidSimpleDSOClientCounter();
53: root.put(putCountKey, counter);
54: }
55: counter.incrementCount();
56: }
57:
58: public static void main(String[] args) throws Exception {
59: StandardTVSConfigurationSetupManagerFactory factory;
60:
61: factory = new StandardTVSConfigurationSetupManagerFactory(args,
62: false, new FatalIllegalConfigurationChangeHandler());
63: L1TVSConfigurationSetupManager configManager = factory
64: .createL1TVSConfigurationSetupManager();
65: PreparedComponentsFromL2Connection components = new PreparedComponentsFromL2Connection(
66: configManager);
67: IsolationClassLoader classLoader = new IsolationClassLoader(
68: new StandardDSOClientConfigHelperImpl(configManager),
69: components);
70:
71: Class clientClass = classLoader
72: .loadClass(StupidSimpleDSOClient.class.getName());
73: final Object client = clientClass.newInstance();
74: final Method run = clientClass.getDeclaredMethod("run",
75: new Class[] {});
76:
77: Thread t = new Thread() {
78: public void run() {
79: try {
80: run.invoke(client, new Object[] {});
81: } catch (Exception e) {
82: e.printStackTrace();
83: }
84: }
85: };
86: t.setContextClassLoader(classLoader);
87: t.start();
88:
89: t.join();
90:
91: BufferedReader reader = new BufferedReader(
92: new InputStreamReader(System.in));
93: System.out.println("Hit ENTER to exit the program");
94: reader.readLine();
95: System.exit(0);
96: }
97: }
|