List of usage examples for org.apache.thrift.server TThreadPoolServer.Args TThreadPoolServer.Args
public Args(TServerTransport transport)
From source file:StubServer.java
License:Apache License
public static void main(String argv[]) { try {//from w w w .j a v a2 s .com int port = 9090; int numThreads = 32; if (argv.length != 1) { usage(); } System.out.println(argv[0]); StubServer mapkeeper = new StubServer(); TServer server = null; if (argv[0].equals("hsha")) { TNonblockingServerTransport trans = new TNonblockingServerSocket(port); THsHaServer.Args args = new THsHaServer.Args(trans); args.transportFactory(new TFramedTransport.Factory()); args.protocolFactory(new TBinaryProtocol.Factory()); args.processor(new MapKeeper.Processor(mapkeeper)); args.workerThreads(numThreads); server = new THsHaServer(args); } else if (argv[0].equals("nonblocking")) { TNonblockingServerTransport trans = new TNonblockingServerSocket(port); TNonblockingServer.Args args = new TNonblockingServer.Args(trans); args.transportFactory(new TFramedTransport.Factory()); args.protocolFactory(new TBinaryProtocol.Factory()); args.processor(new MapKeeper.Processor(mapkeeper)); server = new TNonblockingServer(args); } else if (argv[0].equals("threadpool")) { TServerTransport trans = new TServerSocket(port); TThreadPoolServer.Args args = new TThreadPoolServer.Args(trans); args.transportFactory(new TFramedTransport.Factory()); args.protocolFactory(new TBinaryProtocol.Factory()); args.processor(new MapKeeper.Processor(mapkeeper)); server = new TThreadPoolServer(args); } else if (argv[0].equals("selector")) { TNonblockingServerTransport trans = new TNonblockingServerSocket(port); TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args(trans); args.transportFactory(new TFramedTransport.Factory()); args.protocolFactory(new TBinaryProtocol.Factory()); args.processor(new MapKeeper.Processor(mapkeeper)); args.selectorThreads(4); args.workerThreads(numThreads); server = new TThreadedSelectorServer(args); } else { usage(); } server.serve(); } catch (Exception x) { System.out.println(x.toString() + " " + x.getMessage()); } }
From source file:de.pgrp.core.ThriftServerWorker.java
License:Open Source License
/** * The run() method/*from ww w .j ava 2s .c o m*/ */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void run() { this.setName("Thrift-Server Thread"); try { this.serverTransport = new TServerSocket(Globals.p2pPort); this.processor = new DataTransfer.Processor(new ThriftDataHandler()); //Singlethreaded: //this.server = new TSimpleServer(new TServer.Args(serverTransport).processor(processor)); //Multithreaded: TThreadPoolServer.Args tpsa = new TThreadPoolServer.Args(serverTransport).processor(processor); tpsa.minWorkerThreads(1); tpsa.maxWorkerThreads(20); this.server = new TThreadPoolServer(tpsa); Globals.log.addMsg("Starting thrift handler on port " + Globals.p2pPort); this.server.serve(); } catch (TTransportException e) { Globals.log.addMsg("Thrift server error: " + e); } Globals.log.addMsg("Thrift-Server-Thread interrupted. Closing...", 4); }