1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package jgroup.test.gm;
20
21 import java.io.InputStream;
22 import java.io.OutputStream;
23 import java.rmi.RemoteException;
24
25 import jgroup.core.GroupManager;
26 import jgroup.core.InternalGMIService;
27 import jgroup.core.JgroupException;
28 import jgroup.core.MemberId;
29 import jgroup.core.multicast.MulticastListener;
30 import jgroup.core.multicast.MulticastService;
31 import jgroup.relacs.config.AppConfig;
32 import jgroup.relacs.gm.DispatcherService;
33 import jgroup.relacs.rmi.SynchAckListener;
34
35 import org.apache.log4j.Logger;
36
37
38
39
40
41
42
43
44 public class RemoteTestLayer
45 implements RemoteTestService, MulticastListener, InternalRemoteTest
46 {
47
48
49
50
51
52
53 private static Logger log = Logger.getLogger(RemoteTestLayer.class);
54
55
56
57
58
59
60
61 private static final int NUM_CALLS = 2000;
62 private static final int INIT_CALLS = 2000;
63 private static final int INIT_SIZE = 0;
64 private static final int INC_SIZE = 5000;
65 private static final int MAX_SIZE = 20000;
66
67
68 private static final String PROTOCOL_NAME = "RTL";
69
70
71
72
73
74
75
76 private GroupManager gm;
77
78
79 private MulticastService multicastService;
80
81
82 private DispatcherService dispatcherService;
83
84
85 private InternalRemoteTest irt;
86
87
88 private int numCalls = NUM_CALLS;
89
90
91 private int initCalls = INIT_CALLS;
92
93
94 private int initSize = INIT_SIZE;
95
96
97 private int incSize = INC_SIZE;
98
99
100 private int maxSize = MAX_SIZE;
101
102
103 private String interactionStyle;
104
105
106 private volatile boolean halted = false;
107
108
109
110
111
112
113 private RemoteTestLayer(GroupManager gm, DispatcherService dispatcher, MulticastService multicastService)
114 throws JgroupException, RemoteException
115 {
116 this.gm = gm;
117 this.dispatcherService = dispatcher;
118 this.multicastService = multicastService;
119 }
120
121
122
123
124
125
126
127
128
129
130
131 public static RemoteTestLayer getLayer(GroupManager gm, DispatcherService dispatcher,
132 InternalGMIService igmis, MulticastService mcast)
133 throws JgroupException, RemoteException
134 {
135
136
137
138
139 return new RemoteTestLayer(gm, dispatcher, mcast);
140 }
141
142
143
144
145
146
147
148
149
150
151
152 public void addListener(Object listener)
153 {
154 AppConfig app = AppConfig.getApplication(listener);
155 interactionStyle = app.getParam("RemoteTest.interactionStyle");
156 numCalls = app.getIntParam("RemoteTest.numCalls", NUM_CALLS);
157 initCalls = app.getIntParam("RemoteTest.initCalls", INIT_CALLS);
158 initSize = app.getIntParam("RemoteTest.initSize", INIT_SIZE);
159 incSize = app.getIntParam("RemoteTest.incSize", INC_SIZE);
160 maxSize = app.getIntParam("RemoteTest.maxSize", MAX_SIZE);
161 if (interactionStyle.length() == 0) {
162
163 interactionStyle = "igmi";
164 } else {
165 interactionStyle = interactionStyle.toLowerCase();
166 if (!(interactionStyle.equals("igmi")
167 || interactionStyle.equals("mcast-obj")
168 || interactionStyle.equals("mcast-stream"))) {
169 throw new IllegalArgumentException("Unsupported interaction style: "
170 + interactionStyle);
171 }
172 }
173 }
174
175
176
177
178
179
180
181
182
183 public void activate()
184 {
185 irt = (InternalRemoteTest) gm.getService(InternalRemoteTest.class);
186 System.out.println("\n\n-- RemoteTest: " + interactionStyle + " ---------------------------------------");
187 int calls = numCalls + initCalls;
188 long start = 0;
189 long[] timeVals = new long[calls];
190 byte[] buffer = new byte[0];
191 for (int size = initSize; size <= maxSize; size += incSize) {
192 buffer = new byte[size];
193 for (int i = 0; !halted && i < calls; i++) {
194 try {
195 if (interactionStyle.equals("igmi")) {
196
197 irt.rtest(buffer);
198
199 } else if (interactionStyle.equals("mcast-obj")) {
200
201 SynchAckListener listener = new SynchAckListener(dispatcherService);
202 multicastService.mcast(PROTOCOL_NAME, "Some object", listener.getRemoteAckListener());
203 Object result = listener.getResults();
204
205 } else if (interactionStyle.equals("mcast-stream")) {
206
207 OutputStream msg = multicastService.getMessage(PROTOCOL_NAME);
208 msg.write(buffer);
209 SynchAckListener listener = new SynchAckListener(dispatcherService);
210 multicastService.mcast(msg, listener.getRemoteAckListener());
211 Object result = listener.getResults();
212
213 }
214 } catch (Exception e) {
215 e.printStackTrace();
216 }
217 }
218 int begin = 0;
219 if (calls != numCalls) {
220 System.out.println("JIT Compiling and optimization phase (initCalls):");
221 System.out.println("InitCalls phase - Size=" + size + "--------");
222 for (int i = 0; i < initCalls; i++) {
223 System.out.println(timeVals[i]);
224 }
225 begin = initCalls;
226 }
227 System.out.println("\n\n-- RemoteTest: " + interactionStyle + " ---------------------------------------");
228 System.out.println("Normal run phase - Size=" + size + "--------");
229 for (int i = begin; i < calls; i++) {
230 System.out.println(timeVals[i]);
231 }
232 calls = numCalls;
233 }
234 System.out.println("------------------ COMPLETED ------------------");
235 }
236
237
238 public void halt()
239 {
240 halted = true;
241 }
242
243
244
245
246
247
248
249
250
251 public void rtest(int[] array)
252 throws RemoteException
253 {
254 return;
255 }
256
257
258
259
260 public Object rtest(byte[] var)
261 throws RemoteException
262 {
263 return var;
264 }
265
266
267
268
269 public Object rtest(int var)
270 throws RemoteException
271 {
272 return new Integer(var);
273 }
274
275
276
277
278 public Object rtest(Object obj)
279 throws RemoteException
280 {
281 return obj;
282 }
283
284
285
286
287
288
289
290
291
292 public Object deliverObject(Object msg, MemberId sender, int seqNo)
293 {
294 log.debug("Received: " + msg);
295 return msg;
296 }
297
298
299
300
301 public Object deliverStream(InputStream msg, MemberId sender, int seqNo)
302 {
303
304
305
306
307 return null;
308 }
309
310
311
312
313 public String getProtocolName()
314 {
315 return PROTOCOL_NAME;
316 }
317
318 }