KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > StupidSimpleDSOClient


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.tctest;
5
6 import com.tc.config.schema.setup.FatalIllegalConfigurationChangeHandler;
7 import com.tc.config.schema.setup.L1TVSConfigurationSetupManager;
8 import com.tc.config.schema.setup.StandardTVSConfigurationSetupManagerFactory;
9 import com.tc.object.bytecode.hook.impl.PreparedComponentsFromL2Connection;
10 import com.tc.object.config.StandardDSOClientConfigHelper;
11 import com.tc.object.loaders.IsolationClassLoader;
12
13 import java.io.BufferedReader JavaDoc;
14 import java.io.InputStreamReader JavaDoc;
15 import java.lang.reflect.Method JavaDoc;
16 import java.util.HashMap JavaDoc;
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 JavaDoc root = new HashMap JavaDoc();
25   private final String JavaDoc putCountKey = "putCount";
26
27   public void run() {
28     for (int i = 0; i < 10; i++) {
29       synchronized (root) {
30         System.out.println("put returned: " + root.put("key", "value"));
31         incrementPutCount();
32         System.out.println("put count: " + root.get(putCountKey));
33       }
34
35       synchronized (root) {
36         System.out.println("value = " + root.get("key"));
37       }
38
39       synchronized (root) {
40         root.remove("key");
41         System.out.println(root.size());
42       }
43     }
44   }
45
46   private final void incrementPutCount() {
47     StupidSimpleDSOClientCounter counter = (StupidSimpleDSOClientCounter) root.get(putCountKey);
48     if (counter == null) {
49       counter = new StupidSimpleDSOClientCounter();
50       root.put(putCountKey, counter);
51     }
52     counter.incrementCount();
53   }
54
55   public static void main(String JavaDoc[] args) throws Exception JavaDoc {
56     StandardTVSConfigurationSetupManagerFactory factory;
57
58     factory = new StandardTVSConfigurationSetupManagerFactory(args, false, new FatalIllegalConfigurationChangeHandler());
59     L1TVSConfigurationSetupManager configManager = factory.createL1TVSConfigurationSetupManager();
60     PreparedComponentsFromL2Connection components = new PreparedComponentsFromL2Connection(configManager);
61     IsolationClassLoader classLoader = new IsolationClassLoader(new StandardDSOClientConfigHelper(configManager),
62                                                                 components);
63
64     Class JavaDoc clientClass = classLoader.loadClass(StupidSimpleDSOClient.class.getName());
65     final Object JavaDoc client = clientClass.newInstance();
66     final Method JavaDoc run = clientClass.getDeclaredMethod("run", new Class JavaDoc[] {});
67
68     Thread JavaDoc t = new Thread JavaDoc() {
69       public void run() {
70         try {
71           run.invoke(client, new Object JavaDoc[] {});
72         } catch (Exception JavaDoc e) {
73           e.printStackTrace();
74         }
75       }
76     };
77     t.setContextClassLoader(classLoader);
78     t.start();
79
80     t.join();
81
82     BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(System.in));
83     System.out.println("Hit ENTER to exit the program");
84     reader.readLine();
85     System.exit(0);
86   }
87 }
88
Free Books   Free Magazines  
Popular Tags