KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > ServerCrashAndRestartTestApp


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tctest;
6
7 import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
8
9 import com.tc.cluster.ClusterEventListener;
10 import com.tc.object.bytecode.ManagerUtil;
11 import com.tc.simulator.app.ApplicationConfig;
12 import com.tc.simulator.listener.ListenerProvider;
13
14 public class ServerCrashAndRestartTestApp extends ServerCrashingAppBase implements ClusterEventListener {
15
16   public ServerCrashAndRestartTestApp(String JavaDoc appId, ApplicationConfig config, ListenerProvider listenerProvider) {
17     super(appId, config, listenerProvider);
18   }
19
20   private final int initialNodeCount = getParticipantCount();
21   private final CyclicBarrier barrier = new CyclicBarrier(initialNodeCount);
22   private String JavaDoc thisNode;
23
24   public void run() {
25     try {
26       runTest();
27     } catch (Throwable JavaDoc t) {
28       notifyError(t);
29     }
30   }
31
32   private void runTest() throws Throwable JavaDoc {
33     ManagerUtil.addClusterEventListener(this);
34     final boolean isMasterNode = barrier.barrier() == 0;
35     if (isMasterNode) {
36       getConfig().getServerControl().crash();
37       getConfig().getServerControl().start(30 * 1000);
38     }
39     barrier.barrier();
40   }
41
42   public void nodeConnected(String JavaDoc nodeId) {
43     trace("nodeConnected");
44   }
45
46   public void nodeDisconnected(String JavaDoc nodeId) {
47     trace("nodeDisconnected");
48   }
49
50   public void thisNodeConnected(String JavaDoc thisNodeId, String JavaDoc[] nodesCurrentlyInCluster) {
51     this.thisNode = thisNodeId;
52     trace("thisNodeConnected");
53   }
54
55   public void thisNodeDisconnected(String JavaDoc thisNodeId) {
56     trace("thisNodeDisconnected");
57   }
58
59   private void trace(String JavaDoc msg) {
60     System.err.println("### " + msg + " -> nodeId=" + thisNode + ", ThreadId=" + Thread.currentThread().getName());
61   }
62 }
63
Popular Tags