1 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 ; 14 import java.io.InputStreamReader ; 15 import java.lang.reflect.Method ; 16 import java.util.HashMap ; 17 18 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: " + 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 [] args) throws Exception { 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 clientClass = classLoader.loadClass(StupidSimpleDSOClient.class.getName()); 65 final Object client = clientClass.newInstance(); 66 final Method run = clientClass.getDeclaredMethod("run", new Class [] {}); 67 68 Thread t = new Thread () { 69 public void run() { 70 try { 71 run.invoke(client, new Object [] {}); 72 } catch (Exception e) { 73 e.printStackTrace(); 74 } 75 } 76 }; 77 t.setContextClassLoader(classLoader); 78 t.start(); 79 80 t.join(); 81 82 BufferedReader reader = new BufferedReader (new InputStreamReader (System.in)); 83 System.out.println("Hit ENTER to exit the program"); 84 reader.readLine(); 85 System.exit(0); 86 } 87 } 88
| Popular Tags
|