1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package jgroup.test.performance.arm;
20
21 import java.rmi.RemoteException;
22
23 import jgroup.core.ConfigManager;
24 import jgroup.core.GroupManager;
25 import jgroup.core.JgroupException;
26 import jgroup.core.protocols.Anycast;
27 import jgroup.core.protocols.Multicast;
28 import jgroup.test.performance.RemoteShutdown;
29 import jgroup.test.performance.SpeedTest;
30 import jgroup.util.Network;
31 import jgroup.util.log.Eventlogger;
32 import jgroup.util.log.ReplicaEvent;
33 import static jgroup.util.log.ReplicaEvent.Type.Initialized;
34
35
36
37
38
39
40
41
42 public class ReplicatedServer
43 implements SpeedTest, RemoteShutdown
44 {
45
46
47
48
49
50
51 private static final String localHost = Network.getLocalMachineName();
52
53
54
55
56
57
58 public ReplicatedServer()
59 throws JgroupException
60 {
61 ConfigManager.init();
62 GroupManager gm = GroupManager.getGroupManager(this);
63 if (Eventlogger.ENABLED)
64 Eventlogger.logEventFlush(new ReplicaEvent(Initialized, gm.getGroupId()));
65 System.out.println("ReplicatedServer initialized");
66 }
67
68
69
70
71
72
73 @Multicast public void mtest()
74 throws RemoteException
75 {
76 }
77
78 private int cnt = 0;
79
80
81 @Multicast public byte[] mtest(byte[] x)
82 throws RemoteException
83 {
84
85
86
87
88
89 return x;
90 }
91
92 @Multicast public void vmtest(byte[] x)
93 throws RemoteException
94 {
95 System.out.print("+");
96 if ((cnt % 20) == 0) {
97 System.out.println(cnt);
98 }
99 cnt++;
100 }
101
102 @Multicast public String mtest(String x)
103 throws RemoteException
104 {
105 System.out.println(x);
106 return x;
107 }
108
109 @Anycast public void test()
110 throws RemoteException
111 {
112 }
113
114 @Anycast public byte[] test(byte[] x)
115 throws RemoteException
116 {
117
118
119
120 return x;
121 }
122
123 @Anycast public String test(String x)
124 throws RemoteException
125 {
126 return localHost + ": " + x;
127 }
128
129
130
131
132
133
134 @Multicast public void preShutdown()
135 throws RemoteException
136 {
137 if (Eventlogger.ENABLED) {
138 Eventlogger.logEventFlush("PreShutdown localhost: " + localHost);
139 }
140 }
141
142 @Anycast public void shutdown(final int delay)
143 throws RemoteException
144 {
145 new Thread() {
146 public void run() {
147 System.out.println("I'm shuting down in " + delay + " milliseconds.");
148 if (delay > 0) {
149 try { sleep(delay); } catch (InterruptedException e) { }
150 }
151 System.exit(0);
152 }
153 }.start();
154 }
155
156
157
158
159
160
161 public static void main(String[] argv)
162 throws Exception
163 {
164 ReplicatedServer server = new ReplicatedServer();
165 }
166
167 }