cleaned-up to give better help and javadoc
diff --git a/apps/foo/src/main/java/org/onlab/onos/foo/NettyEchoHandler.java b/apps/foo/src/main/java/org/onlab/onos/foo/NettyEchoHandler.java
index 1049a6d..5f9bfa4 100644
--- a/apps/foo/src/main/java/org/onlab/onos/foo/NettyEchoHandler.java
+++ b/apps/foo/src/main/java/org/onlab/onos/foo/NettyEchoHandler.java
@@ -4,8 +4,6 @@
import org.onlab.netty.Message;
import org.onlab.netty.MessageHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
@@ -13,11 +11,8 @@
*/
public class NettyEchoHandler implements MessageHandler {
- private final Logger log = LoggerFactory.getLogger(getClass());
-
@Override
public void handle(Message message) throws IOException {
- //log.info("Received message. Echoing it back to the sender.");
message.respond(message.payload());
}
}
diff --git a/apps/foo/src/main/java/org/onlab/onos/foo/NettyNothingHandler.java b/apps/foo/src/main/java/org/onlab/onos/foo/NettyNothingHandler.java
new file mode 100644
index 0000000..05e2cb3
--- /dev/null
+++ b/apps/foo/src/main/java/org/onlab/onos/foo/NettyNothingHandler.java
@@ -0,0 +1,19 @@
+package org.onlab.onos.foo;
+
+import org.onlab.netty.Message;
+import org.onlab.netty.MessageHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A MessageHandler that simply logs the information.
+ */
+public class NettyNothingHandler implements MessageHandler {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Override
+ public void handle(Message message) {
+ // Do nothing
+ }
+}
diff --git a/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java
index 5e3f8f7..aafe084 100644
--- a/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java
+++ b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java
@@ -2,6 +2,7 @@
import java.io.IOException;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.onlab.metrics.MetricsComponent;
@@ -15,14 +16,29 @@
import com.codahale.metrics.Timer;
+/**
+ * The Simple netty client test.
+ */
// FIXME: Should be move out to test or app
public final class SimpleNettyClient {
private static Logger log = LoggerFactory.getLogger(SimpleNettyClient.class);
+ static NettyMessagingService messaging;
+ static MetricsManager metrics;
+
private SimpleNettyClient() {
}
+ /**
+ * The entry point of application.
+ *
+ * @param args the input arguments
+ * @throws IOException the iO exception
+ * @throws InterruptedException the interrupted exception
+ * @throws ExecutionException the execution exception
+ * @throws TimeoutException the timeout exception
+ */
public static void main(String[] args)
throws IOException, InterruptedException, ExecutionException,
TimeoutException {
@@ -34,13 +50,20 @@
System.exit(0);
}
+
+ /**
+ * Start standalone.
+ *
+ * @param args the args
+ * @throws Exception the exception
+ */
public static void startStandalone(String[] args) throws Exception {
String host = args.length > 0 ? args[0] : "localhost";
int port = args.length > 1 ? Integer.parseInt(args[1]) : 8081;
int warmup = args.length > 2 ? Integer.parseInt(args[2]) : 1000;
int iterations = args.length > 3 ? Integer.parseInt(args[3]) : 50 * 100000;
- NettyMessagingService messaging = new TestNettyMessagingService(9081);
- MetricsManager metrics = new MetricsManager();
+ messaging = new TestNettyMessagingService(9081);
+ metrics = new MetricsManager();
Endpoint endpoint = new Endpoint(host, port);
messaging.activate();
metrics.activate();
@@ -53,6 +76,7 @@
Response response = messaging
.sendAndReceive(endpoint, "echo",
"Hello World".getBytes());
+ response.get(100000, TimeUnit.MILLISECONDS);
}
log.info("measuring async sender");
@@ -64,19 +88,47 @@
context.stop();
}
+ log.info("measuring round-trip send & receive");
Timer sendAndReceiveTimer = metrics.createTimer(component, feature, "SendAndReceive");
+ int timeouts = 0;
+
for (int i = 0; i < iterations; i++) {
+ Response response;
Timer.Context context = sendAndReceiveTimer.time();
- Response response = messaging
- .sendAndReceive(endpoint, "echo",
- "Hello World".getBytes());
+ try {
+ response = messaging
+ .sendAndReceive(endpoint, "echo",
+ "Hello World".getBytes());
+ response.get(10000, TimeUnit.MILLISECONDS);
+ } catch (TimeoutException e) {
+ timeouts++;
+ log.info("timeout:" + timeouts + " at iteration:" + i);
+ } finally {
+ context.stop();
+ }
// System.out.println("Got back:" + new String(response.get(2, TimeUnit.SECONDS)));
- context.stop();
}
- metrics.deactivate();
}
+ public static void stop() {
+ try {
+ messaging.deactivate();
+ metrics.deactivate();
+ } catch (Exception e) {
+ log.info("Unable to stop client %s", e);
+ }
+ }
+
+ /**
+ * The type Test netty messaging service.
+ */
public static class TestNettyMessagingService extends NettyMessagingService {
+ /**
+ * Instantiates a new Test netty messaging service.
+ *
+ * @param port the port
+ * @throws Exception the exception
+ */
public TestNettyMessagingService(int port) throws Exception {
super(port);
}
diff --git a/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClientCommand.java b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClientCommand.java
index d308171..f089a72 100644
--- a/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClientCommand.java
+++ b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClientCommand.java
@@ -1,6 +1,7 @@
package org.onlab.onos.foo;
import static org.onlab.onos.foo.SimpleNettyClient.startStandalone;
+import static org.onlab.onos.foo.SimpleNettyClient.stop;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
@@ -24,11 +25,11 @@
@Argument(index = 2, name = "warmupCount", description = "Warm-up count",
required = false, multiValued = false)
- String warmupCount = "1000";
+ String warmupCount = "10000";
@Argument(index = 3, name = "messageCount", description = "Message count",
required = false, multiValued = false)
- String messageCount = "100000";
+ String messageCount = "1000000";
@Override
protected void execute() {
@@ -37,5 +38,6 @@
} catch (Exception e) {
error("Unable to start client %s", e);
}
+ stop();
}
}
diff --git a/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java
index 47b05cd..b1e14c6 100644
--- a/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java
+++ b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java
@@ -12,17 +12,30 @@
private SimpleNettyServer() {}
- public static void main(String... args) throws Exception {
+ /**
+ * The entry point of application.
+ *
+ * @param args the input arguments
+ * @throws Exception the exception
+ */
+ public static void main(String... args) throws Exception {
startStandalone(args);
System.exit(0);
}
- public static void startStandalone(String[] args) throws Exception {
+ /**
+ * Start standalone server.
+ *
+ * @param args the args
+ * @throws Exception the exception
+ */
+ public static void startStandalone(String[] args) throws Exception {
int port = args.length > 0 ? Integer.parseInt(args[0]) : 8081;
NettyMessagingService server = new NettyMessagingService(port);
server.activate();
- server.registerHandler("simple", new NettyLoggingHandler());
+ server.registerHandler("simple", new NettyNothingHandler());
server.registerHandler("echo", new NettyEchoHandler());
+ log.info("Netty Server server on port " + port);
}
}