Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
pankaj | 09b5838 | 2014-10-07 13:52:24 -0700 | [diff] [blame] | 19 | package org.onlab.onos.foo; |
| 20 | |
pankaj | 09b5838 | 2014-10-07 13:52:24 -0700 | [diff] [blame] | 21 | import org.onlab.netty.NettyMessagingService; |
| 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
| 25 | /** |
| 26 | * Test to measure Messaging performance. |
| 27 | */ |
Madan Jampani | a5d0d78 | 2014-10-07 14:36:00 -0700 | [diff] [blame] | 28 | public final class SimpleNettyServer { |
pankaj | 9c060c0 | 2014-10-08 10:21:29 -0700 | [diff] [blame] | 29 | private static Logger log = LoggerFactory.getLogger(SimpleNettyServer.class); |
pankaj | 09b5838 | 2014-10-07 13:52:24 -0700 | [diff] [blame] | 30 | |
| 31 | private SimpleNettyServer() {} |
| 32 | |
pankaj | 9fc8759 | 2014-10-10 15:40:43 -0700 | [diff] [blame] | 33 | /** |
| 34 | * The entry point of application. |
| 35 | * |
| 36 | * @param args the input arguments |
| 37 | * @throws Exception the exception |
| 38 | */ |
| 39 | public static void main(String... args) throws Exception { |
pankaj | 09b5838 | 2014-10-07 13:52:24 -0700 | [diff] [blame] | 40 | startStandalone(args); |
| 41 | System.exit(0); |
| 42 | } |
| 43 | |
pankaj | 9fc8759 | 2014-10-10 15:40:43 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Start standalone server. |
| 46 | * |
| 47 | * @param args the args |
| 48 | * @throws Exception the exception |
| 49 | */ |
| 50 | public static void startStandalone(String[] args) throws Exception { |
pankaj | 9d7e4be | 2014-10-09 14:10:03 -0700 | [diff] [blame] | 51 | int port = args.length > 0 ? Integer.parseInt(args[0]) : 8081; |
| 52 | NettyMessagingService server = new NettyMessagingService(port); |
pankaj | f49b45e | 2014-10-07 14:24:22 -0700 | [diff] [blame] | 53 | server.activate(); |
pankaj | 9fc8759 | 2014-10-10 15:40:43 -0700 | [diff] [blame] | 54 | server.registerHandler("simple", new NettyNothingHandler()); |
pankaj | 366ce8b | 2014-10-07 17:18:37 -0700 | [diff] [blame] | 55 | server.registerHandler("echo", new NettyEchoHandler()); |
pankaj | 9fc8759 | 2014-10-10 15:40:43 -0700 | [diff] [blame] | 56 | log.info("Netty Server server on port " + port); |
pankaj | 09b5838 | 2014-10-07 13:52:24 -0700 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |