int currentClients = this.clients.size();
if (currentClients < clients)
{
for (int i = 0; i < clients - currentClients; ++i)
{
final RHTTPClient client = new JettyClient(httpClient, gatewayAddress, gatewayURI, nodeName + (currentClients + i));
client.addListener(new EchoListener(client));
client.connect();
this.clients.add(client);
// Give some time to the server to accept connections and
// reply to handshakes and connects
if (i % 10 == 0)
{
Thread.sleep(100);
}
}
}
else if (currentClients > clients)
{
for (int i = 0; i < currentClients - clients; ++i)
{
RHTTPClient client = this.clients.remove(currentClients - i - 1);
client.disconnect();
}
}
System.err.println("Clients ready");
currentClients = this.clients.size();
if (currentClients > 0)
{
System.err.print("batch count [" + batchCount + "]: ");
value = console.readLine().trim();
if (value.length() == 0)
value = "" + batchCount;
batchCount = Integer.parseInt(value);
System.err.print("batch size [" + batchSize + "]: ");
value = console.readLine().trim();
if (value.length() == 0)
value = "" + batchSize;
batchSize = Integer.parseInt(value);
System.err.print("batch pause [" + batchPause + "]: ");
value = console.readLine().trim();
if (value.length() == 0)
value = "" + batchPause;
batchPause = Long.parseLong(value);
System.err.print("request size [" + requestSize + "]: ");
value = console.readLine().trim();
if (value.length() == 0)
value = "" + requestSize;
requestSize = Integer.parseInt(value);
String requestBody = "";
for (int i = 0; i < requestSize; i++)
requestBody += "x";
String externalURL = "http://" + host + ":" + port + context + externalPath;
if (!externalURL.endsWith("/"))
externalURL += "/";
reset();
long start = System.nanoTime();
long expected = 0;
for (int i = 0; i < batchCount; ++i)
{
for (int j = 0; j < batchSize; ++j)
{
int clientIndex = random.nextInt(this.clients.size());
RHTTPClient client = this.clients.get(clientIndex);
String targetId = client.getTargetId();
String url = externalURL + targetId;
ExternalExchange exchange = new ExternalExchange();
exchange.setMethod("GET");
exchange.setURL(url);