2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
22
package org.jboss.test.remoting.soak;
24
import java.net.InetAddress;
25
import java.util.Collections;
26
import java.util.HashMap;
27
import java.util.HashSet;
28
import java.util.Iterator;
30
import java.util.Random;
32
import java.util.Timer;
33
import java.util.TimerTask;
35
import org.apache.log4j.ConsoleAppender;
36
import org.apache.log4j.Level;
37
import org.apache.log4j.Logger;
38
import org.apache.log4j.PatternLayout;
39
import org.jboss.logging.XLevel;
44
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
45
* @version $Revision: 1.1 $
47
* Copyright Mar 13, 2008
50
public class ClientLauncher extends SoakConstants
52
private static Logger log = Logger.getLogger(ClientLauncher.class);
54
private static Set mockEJBClientsInUse = Collections.synchronizedSet(new HashSet());
55
private static Set mockJBMClientsInUse = Collections.synchronizedSet(new HashSet());
56
private static Set heavyComputeClientsInUse = Collections.synchronizedSet(new HashSet());
58
private static Counter mockEJBClientCounter = new Counter();
59
private static Counter mockJBMClientCounter = new Counter();
60
private static Counter heavyComputeClientCounter = new Counter();
62
private static Counter mockEJBClientFailureCounter = new Counter();
63
private static Counter mockJBMClientFailureCounter = new Counter();
64
private static Counter heavyComputeClientFailureCounter = new Counter();
66
private static Random random;
67
private static String[] transports = {"bisocket", "http", "rmi", "socket"};
68
private static int[] ports = {6666, 6667, 6668, 6669};
69
private static int[] transportCounters = new int[4];
70
private static String host;
71
private static boolean creationDone;
73
// Configuration parameters.
74
private static int MAX_CLIENTS = 30;
75
private static int NUMBER_OF_EJB_CALLS = 4000;
76
private static int NUMBER_OF_JBM_CALLS = 2000;
77
private static int NUMBER_OF_JBM_CALLBACKS = 4;
78
private static int NUMBER_OF_HEAVY_COMPUTE_CALLS = 5;
79
private static String HEAVY_COMPUTE_SPIN_TIME = "4000";
82
public static void main(String[] args)
86
Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
87
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
88
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
89
PatternLayout layout = new PatternLayout(pattern);
90
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
91
Logger.getRootLogger().addAppender(consoleAppender);
93
host = InetAddress.getLocalHost().getHostAddress();
94
random = new Random(System.currentTimeMillis());
95
Timer timer = new Timer(false);
96
timer.schedule(new DisplayTimerTask(), 30000, 30000);
97
long start = System.currentTimeMillis();
99
while (System.currentTimeMillis() - start < DURATION)
101
if (mockEJBClientsInUse.size() +
102
mockJBMClientsInUse.size() +
103
heavyComputeClientsInUse.size() < MAX_CLIENTS)
108
int n = random.nextInt(40) * 100;
109
log.debug("waiting " + n + " ms");
114
log.info("Client creation phase complete.");
118
log.error("Error", t);
123
protected static void createClient() throws Throwable
125
int k = random.nextInt(4);
126
String transport = transports[k];
128
transportCounters[k]++;
129
int clientType = random.nextInt(25);
133
createMockEJBClient(transport, port);
135
else if (clientType < 20)
137
createMockJBMClient(transport, port);
141
createHeavyComputeClient(transport, port);
146
protected static void createMockEJBClient(String transport, int port) throws Throwable
148
String locatorURI = transport + "://" + host + ":" + port + "/?timeout=0";
149
Map metadata = new HashMap();
150
metadata.put(NAME, "MockEJBClient" + mockEJBClientCounter.increment() + "[" + transport + "]");
151
metadata.put(IN_USE_SET, mockEJBClientsInUse);
152
metadata.put(FAILURE_COUNTER, mockEJBClientFailureCounter);
153
metadata.put(NUMBER_OF_CALLS, Integer.toString(random.nextInt(NUMBER_OF_EJB_CALLS)));
154
MockEJBClient c = new MockEJBClient(locatorURI, metadata);
155
Thread t = new Thread(c);
160
protected static void createMockJBMClient(String transport, int port) throws Throwable
162
String locatorURI = transport + "://" + host + ":" + port + "/?timeout=0";
163
Map metadata = new HashMap();
164
metadata.put(NAME, "MockJBMClient" + mockJBMClientCounter.increment() + "[" + transport + "]");
165
metadata.put(IN_USE_SET, mockJBMClientsInUse);
166
metadata.put(FAILURE_COUNTER, mockJBMClientFailureCounter);
167
metadata.put(NUMBER_OF_CALLS, Integer.toString(random.nextInt(NUMBER_OF_JBM_CALLS)));
168
metadata.put(NUMBER_OF_CALLBACKS, Integer.toString(random.nextInt(NUMBER_OF_JBM_CALLBACKS)));
169
MockJBMClient c = new MockJBMClient(locatorURI, metadata);
170
Thread t = new Thread(c);
175
protected static void createHeavyComputeClient(String transport, int port) throws Throwable
177
String locatorURI = transport + "://" + host + ":" + port + "/?timeout=0";
178
Map metadata = new HashMap();
179
metadata.put(NAME, "HeavyComputeClient" + heavyComputeClientCounter.increment() + "[" + transport + "]");
180
metadata.put(IN_USE_SET, heavyComputeClientsInUse);
181
metadata.put(FAILURE_COUNTER, heavyComputeClientFailureCounter);
182
metadata.put(NUMBER_OF_CALLS, Integer.toString(random.nextInt(NUMBER_OF_HEAVY_COMPUTE_CALLS)));
183
metadata.put(SPIN_TIME, HEAVY_COMPUTE_SPIN_TIME);
184
HeavyComputeClient c = new HeavyComputeClient(locatorURI, metadata);
185
heavyComputeClientCounter.increment();
186
Thread t = new Thread(c);
195
public synchronized int getCount() { return count; }
196
public synchronized int increment() { return count++; }
197
public synchronized int decrement() { return --count; }
200
static class DisplayTimerTask extends TimerTask
204
System.out.println("");
205
System.out.println("=========================================");
206
System.out.println("current MockEJBCLients: " + mockEJBClientsInUse.size());
207
System.out.println("current MockJBMClients: " + mockJBMClientsInUse.size());
208
System.out.println("current HeavyComputeClients: " + heavyComputeClientsInUse.size());
209
System.out.println("-----------------------------------------");
210
System.out.println("bisocket clients: " + transportCounters[0]);
211
System.out.println("http clients: " + transportCounters[1]);
212
System.out.println("rmi clients: " + transportCounters[2]);
213
System.out.println("socket clients: " + transportCounters[3]);
214
System.out.println("-----------------------------------------");
215
System.out.println("failed MockEJBCLients: " + mockEJBClientFailureCounter.getCount());
216
System.out.println("failed MockJBMClients: " + mockJBMClientFailureCounter.getCount());
217
System.out.println("failed HeavyComputeClients: " + heavyComputeClientFailureCounter.getCount());
218
System.out.println("-----------------------------------------");
219
printSet(mockEJBClientsInUse);
220
printSet(mockJBMClientsInUse);
221
printSet(heavyComputeClientsInUse);
222
System.out.println("=========================================");
223
System.out.println("");
226
mockEJBClientsInUse.size() == 0 &&
227
mockJBMClientsInUse.size() == 0 &&
228
heavyComputeClientsInUse.size() == 0)
233
private void printSet(Set set)
237
Iterator it = set.iterator();
240
System.out.println(it.next().toString());