KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > BatchRootFaultTestApp


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.object.config.ConfigVisitor;
7 import com.tc.object.config.DSOClientConfigHelper;
8 import com.tc.object.config.TransparencyClassSpec;
9 import com.tc.simulator.app.ApplicationConfig;
10 import com.tc.simulator.listener.ListenerProvider;
11 import com.tctest.runner.AbstractTransparentApp;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 public class BatchRootFaultTestApp extends AbstractTransparentApp {
17   private TestRoot root1;
18   private TestRoot root2;
19   private Set JavaDoc nodes = new HashSet JavaDoc();
20
21   public BatchRootFaultTestApp(String JavaDoc appId, ApplicationConfig cfg, ListenerProvider listenerProvider) {
22     super(appId, cfg, listenerProvider);
23   }
24
25   public void run() {
26
27     synchronized (nodes) {
28
29       if (nodes.size() == 0) {
30         createBigRoot();
31       } else {
32         long l = System.currentTimeMillis();
33         int count = 0;
34         TestRoot current = root1;
35         while (current != null) {
36           count++;
37           current = current.getNext();
38         }
39         current = root2;
40         while (current != null) {
41           count++;
42           current = current.getNext();
43         }
44         System.out.println("******Took******:" + (System.currentTimeMillis() - l) + " count:" + count);
45       }
46       nodes.add(new Object JavaDoc());
47     }
48   }
49
50   private void createBigRoot() {
51     root1 = new TestRoot();
52     TestRoot current = root1;
53     for (int i = 0; i < 1000; i++) {
54       current.setNext(new TestRoot());
55       current = current.getNext();
56     }
57     root2 = new TestRoot();
58     root2.setNext(root1);
59   }
60
61   private static class TestRoot {
62     private TestRoot next;
63
64     public void setNext(TestRoot m) {
65       this.next = m;
66     }
67
68     public TestRoot getNext() {
69       return this.next;
70     }
71   }
72
73   public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) {
74     String JavaDoc testClass = BatchRootFaultTestApp.class.getName();
75     config.getOrCreateSpec(TestRoot.class.getName());
76     TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
77
78     String JavaDoc methodExpression = "* " + testClass + "*.*(..)";
79     config.addWriteAutolock(methodExpression);
80     spec.addRoot("root1", "root1");
81     spec.addRoot("root2", "root2");
82     spec.addRoot("nodes", "nodes");
83   }
84 }
85
Popular Tags