47 lines
1.3 KiB
Java
47 lines
1.3 KiB
Java
|
/*
|
||
|
* Copyright (c) 2011 Tony Garnock-Jones. All rights reserved.
|
||
|
*/
|
||
|
|
||
|
package hop;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
public class Test1 {
|
||
|
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");
|
||
|
Subscription sub = api.subscribe("q1", null);
|
||
|
long startTime = 0;
|
||
|
int count = 0;
|
||
|
while (true) {
|
||
|
Object x = sub.getQueue().take();
|
||
|
if (startTime == 0) {
|
||
|
startTime = System.currentTimeMillis();
|
||
|
}
|
||
|
count++;
|
||
|
if ((count % 100000) == 0) {
|
||
|
long now = System.currentTimeMillis();
|
||
|
double delta = (now - startTime) / 1000.0;
|
||
|
System.out.println("Received "+count+" messages in "+delta+" seconds, rate = " + (count / delta) + " Hz");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|