hop-2012/java/hop/Test3.java

45 lines
1.2 KiB
Java

/*
* Copyright (c) 2011 Tony Garnock-Jones. All rights reserved.
*/
package hop;
import java.io.IOException;
/**
*/
public class Test3 {
public static void main(String[] args) {
try {
run(args[0]);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void run(String hostname) throws IOException, InterruptedException {
NodeContainer nc = new NodeContainer();
System.out.println("Hostname: " + hostname);
System.out.println("Container: " + nc.getName());
Relay r = new Relay(nc, hostname);
ServerApi api = new ServerApi(nc, r.getRemoteName());
api.createQueue("q1");
long startTime = System.currentTimeMillis();
int count = 0;
for (int i = 0; i < 10000000; i++) {
api.post("q1", null, Integer.toString(i), null);
count++;
if ((count % 100000) == 0) {
api.flush();
long now = System.currentTimeMillis();
double delta = (now - startTime) / 1000.0;
System.out.println("Sent "+count+" messages in "+delta+" seconds, rate = " + (count / delta) + " Hz");
}
}
}
}