TSimpleServer.Args mgmtArgs = new TSimpleServer.Args(mgmtSocket); mgmtArgs.processor(new ConcourseManagementService.Processor<>(this)); this.mgmtServer = new TSimpleServer(mgmtArgs);
TMultiplexedProcessor processor = new TMultiplexedProcessor(); processor.registerProcessor( "AddService", new AddService.Processor(new AddHandler())); processor.registerProcessor( "MultiplyService", new MultiplyService.Processor(new MultiplyHandler())); TServerTransport serverTransport = new TServerSocket(7911); TTransportFactory factory = new TFramedTransport.Factory(); TServer.Args args = new TServer.Args(serverTransport); args.processor(processor); args.transportFactory(factory); TSimpleServer server = new TSimpleServer(args); System.out.println("Starting server on port 7911 ..."); server.serve();
TServer server = new TSimpleServer(new Args(serverSocket) .protocolFactory(protocolFactory) .transportFactory(transportFactory) .processor(processor));
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients) throws Exception { try (TServerSocket serverTransport = new TServerSocket(0)) { TProtocolFactory protocolFactory = new Factory(); TTransportFactory transportFactory = new TFramedTransport.Factory(); TServer server = new TSimpleServer(new Args(serverTransport) .protocolFactory(protocolFactory) .transportFactory(transportFactory) .processor(processor)); Thread serverThread = new Thread(server::serve); try { serverThread.start(); int localPort = serverTransport.getServerSocket().getLocalPort(); HostAndPort address = HostAndPort.fromParts("localhost", localPort); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { server.stop(); serverThread.interrupt(); } } }
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients) throws Exception { try (TServerSocket serverTransport = new TServerSocket(0)) { TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); TTransportFactory transportFactory = new TFramedTransport.Factory(); TServer server = new TSimpleServer(new Args(serverTransport) .protocolFactory(protocolFactory) .transportFactory(transportFactory) .processor(processor)); Thread serverThread = new Thread(server::serve); try { serverThread.start(); int localPort = serverTransport.getServerSocket().getLocalPort(); HostAndPort address = HostAndPort.fromParts("localhost", localPort); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { server.stop(); serverThread.interrupt(); } } }
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients) throws Exception { try (TServerSocket serverTransport = new TServerSocket(0)) { TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); TTransportFactory transportFactory = new TFramedTransport.Factory(); TServer server = new TSimpleServer(new Args(serverTransport) .protocolFactory(protocolFactory) .transportFactory(transportFactory) .processor(processor)); Thread serverThread = new Thread(server::serve); try { serverThread.start(); int localPort = serverTransport.getServerSocket().getLocalPort(); HostAndPort address = HostAndPort.fromParts("localhost", localPort); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { server.stop(); serverThread.interrupt(); } } }
public void run() { try { TServerTransport serverTransport = new TServerSocket( thriftServerPort); TServer server = new TSimpleServer( new TServer.Args( serverTransport).processor(processor)); LOG.debug("Starting the thrift server on port " + thriftServerPort); server.serve(); } catch (Exception e) { LOG.error("Thrift server died!", e); } } };
public static void main(String[] args) throws TException{ //设置处理器 TProcessor tprocessor = new HelloService.Processor<HelloService.Iface>(new HelloServiceImpl()); // 简单的单线程服务模型,阻塞IO TServerSocket serverTransport = new TServerSocket(SERVER_PORT); TServer.Args tArgs = new TServer.Args(serverTransport); tArgs.processor(tprocessor); ////使用二进制协议 tArgs.protocolFactory(new TBinaryProtocol.Factory()); //创建服务器 TServer server = new TSimpleServer(tArgs); System.out.println("HelloServer start...."); server.serve(); // 启动服务 } }
public void run() { try { TServerTransport serverTransport = new TServerSocket( thriftServerPort); TServer server = new TSimpleServer( new TServer.Args( serverTransport).processor(processor)); LOG.debug("Starting the thrift server on port " + thriftServerPort); server.serve(); } catch (Exception e) { LOG.error("Thrift server died!", e); } } };
public static void simple(MultiplicationService.Processor processor) { try { TServerTransport serverTransport = new TServerSocket(9090); TServer server = new TSimpleServer(new Args(serverTransport).processor(processor)); System.out.println("Starting the simple server..."); server.serve(); } catch (Exception e) { e.printStackTrace(); } }
public void run() { log.info("Starting up!"); try { serverTransport = new TServerSocket(bindAddress); server = new TSimpleServer(new Args(serverTransport).processor(processor)); server.serve(); // blocks until stop() is called. // timer and timer task should be stopped at this point writeToStorage(); } catch (TTransportException e) { log.error("Couldn't start Configurator {}", this, e); } }
public void run() { try { BgpUpdater.Processor processor = new BgpUpdater.Processor(this); TServerTransport transport = new TServerSocket(ourPort); server = new TSimpleServer(new Args(transport).processor(processor)); server.serve(); } catch (Exception e) { LOGGER.error("Exception in BGP Updater server"+e); } }
public void startSingleThreadServer() throws TTransportException { TServerTransport serverTransport = new TServerSocket(this.port); Send.Processor<Send.Iface> processor = new Send.Processor<Send.Iface>(this.handler); TServer.Args tArgs = new TServer.Args(serverTransport); tArgs.processor(processor); tArgs.protocolFactory(new TBinaryProtocol.Factory()); TServer server = new TSimpleServer(tArgs); server.serve(); }
public void startServer() throws Exception { TProcessor tprocessor = new HelloWorldService.Processor<HelloWorldService.Iface>( new HelloWorldImpl()); TServerSocket serverTransport = new TServerSocket(SERVER_PORT); TSimpleServer.Args tArgs = new TSimpleServer.Args(serverTransport); tArgs.processor(tprocessor); tArgs.protocolFactory(new TBinaryProtocol.Factory()); TServer server = new TSimpleServer(tArgs); server.serve(); } }