Showing
2 changed files
with
0 additions
and
63 deletions
| 1 | -package org.onlab.netty; | ||
| 2 | - | ||
| 3 | -import java.util.concurrent.TimeUnit; | ||
| 4 | - | ||
| 5 | -import org.onlab.metrics.MetricsComponent; | ||
| 6 | -import org.onlab.metrics.MetricsFeature; | ||
| 7 | -import org.onlab.metrics.MetricsManager; | ||
| 8 | - | ||
| 9 | -import com.codahale.metrics.Timer; | ||
| 10 | - | ||
| 11 | -// FIXME: Should be move out to test or app | ||
| 12 | -public final class SimpleClient { | ||
| 13 | - private SimpleClient() { | ||
| 14 | - } | ||
| 15 | - | ||
| 16 | - public static void main(String... args) throws Exception { | ||
| 17 | - NettyMessagingService messaging = new TestNettyMessagingService(9081); | ||
| 18 | - MetricsManager metrics = new MetricsManager(); | ||
| 19 | - messaging.activate(); | ||
| 20 | - metrics.activate(); | ||
| 21 | - MetricsFeature feature = new MetricsFeature("timers"); | ||
| 22 | - MetricsComponent component = metrics.registerComponent("NettyMessaging"); | ||
| 23 | - Timer sendAsyncTimer = metrics.createTimer(component, feature, "AsyncSender"); | ||
| 24 | - final int warmup = 100; | ||
| 25 | - for (int i = 0; i < warmup; i++) { | ||
| 26 | - Timer.Context context = sendAsyncTimer.time(); | ||
| 27 | - messaging.sendAsync(new Endpoint("localhost", 8080), "simple", "Hello World".getBytes()); | ||
| 28 | - context.stop(); | ||
| 29 | - } | ||
| 30 | - metrics.registerMetric(component, feature, "AsyncTimer", sendAsyncTimer); | ||
| 31 | - | ||
| 32 | - Timer sendAndReceiveTimer = metrics.createTimer(component, feature, "SendAndReceive"); | ||
| 33 | - final int iterations = 1000000; | ||
| 34 | - for (int i = 0; i < iterations; i++) { | ||
| 35 | - Timer.Context context = sendAndReceiveTimer.time(); | ||
| 36 | - Response response = messaging | ||
| 37 | - .sendAndReceive(new Endpoint("localhost", 8080), "echo", | ||
| 38 | - "Hello World".getBytes()); | ||
| 39 | - System.out.println("Got back:" + new String(response.get(2, TimeUnit.SECONDS))); | ||
| 40 | - context.stop(); | ||
| 41 | - } | ||
| 42 | - metrics.registerMetric(component, feature, "AsyncTimer", sendAndReceiveTimer); | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - public static class TestNettyMessagingService extends NettyMessagingService { | ||
| 46 | - public TestNettyMessagingService(int port) throws Exception { | ||
| 47 | - super(port); | ||
| 48 | - } | ||
| 49 | - } | ||
| 50 | -} |
| 1 | -package org.onlab.netty; | ||
| 2 | - | ||
| 3 | -//FIXME: Should be move out to test or app | ||
| 4 | -public final class SimpleServer { | ||
| 5 | - private SimpleServer() {} | ||
| 6 | - | ||
| 7 | - public static void main(String... args) throws Exception { | ||
| 8 | - NettyMessagingService server = new NettyMessagingService(8080); | ||
| 9 | - server.activate(); | ||
| 10 | - server.registerHandler("simple", new LoggingHandler()); | ||
| 11 | - server.registerHandler("echo", new EchoHandler()); | ||
| 12 | - } | ||
| 13 | -} |
-
Please register or login to post a comment