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