Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.packetstreamer; |
| 2 | |
| 3 | import org.apache.thrift.protocol.TBinaryProtocol; |
| 4 | import org.apache.thrift.server.TServer; |
| 5 | import org.apache.thrift.server.THsHaServer; |
| 6 | import org.apache.thrift.transport.TFramedTransport; |
| 7 | import org.apache.thrift.transport.TNonblockingServerSocket; |
| 8 | import org.apache.thrift.transport.TNonblockingServerTransport; |
| 9 | |
| 10 | |
| 11 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; |
| 13 | |
| 14 | import net.floodlightcontroller.core.annotations.LogMessageCategory; |
| 15 | // Generated code |
| 16 | import net.floodlightcontroller.packetstreamer.thrift.*; |
| 17 | |
| 18 | /** |
| 19 | * The PacketStreamer Server that brokers the packet streaming service. |
| 20 | */ |
| 21 | @LogMessageCategory("OpenFlow Message Tracing") |
| 22 | public class PacketStreamerServer { |
| 23 | protected static Logger log = LoggerFactory.getLogger(PacketStreamerServer.class); |
| 24 | protected static int port = 9090; |
| 25 | protected static PacketStreamerHandler handler; |
| 26 | protected static PacketStreamer.Processor<PacketStreamerHandler> processor; |
| 27 | |
| 28 | |
| 29 | /** |
| 30 | * Main function entry point; |
| 31 | * @param args |
| 32 | */ |
| 33 | public static void main(String [] args) { |
| 34 | try { |
| 35 | port = Integer.parseInt(System.getProperty("net.floodlightcontroller.packetstreamer.port", "9090")); |
| 36 | |
| 37 | handler = new PacketStreamerHandler(); |
| 38 | processor = new PacketStreamer.Processor<PacketStreamerHandler>(handler); |
| 39 | |
| 40 | Runnable simple = new Runnable() { |
| 41 | public void run() { |
| 42 | hshaServer(processor); |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | new Thread(simple).start(); |
| 47 | } catch (Exception x) { |
| 48 | x.printStackTrace(); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | |
| 53 | /** |
| 54 | * The function to create a thrift Half-Sync and Half-Async Server. |
| 55 | * @param processor |
| 56 | */ |
| 57 | public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) { |
| 58 | try { |
| 59 | TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port); |
| 60 | THsHaServer.Args args = new THsHaServer.Args(serverTransport); |
| 61 | args.processor(processor); |
| 62 | args.transportFactory(new TFramedTransport.Factory()); |
| 63 | args.protocolFactory(new TBinaryProtocol.Factory(true, true)); |
| 64 | TServer server = new THsHaServer(args); |
| 65 | |
| 66 | log.info("Starting the packetstreamer hsha server on port {} ...", port); |
| 67 | server.serve(); |
| 68 | } catch (Exception e) { |
| 69 | e.printStackTrace(); |
| 70 | } |
| 71 | } |
| 72 | } |