用word怎么做首页网站,通城网站建设,毕设网站代做一般预算多少钱,展览搭建设计网站当我们使用Thrift 通信的时候#xff0c;服务端有时候需要注册多个类#xff0c;去实现通信#xff0c;这时候我们就不能再使用单一Processor的方式#xff0c;就要使用多个Processor#xff0c;那么如何去实现呢#xff1f;
多个Process
服务端
public static void m…当我们使用Thrift 通信的时候服务端有时候需要注册多个类去实现通信这时候我们就不能再使用单一Processor的方式就要使用多个Processor那么如何去实现呢
多个Process
服务端
public static void main(String[] args) {try {AImpl aService new AImpl();BImpl bServicenew BImpl();TMultiplexedProcessor multiplexedProcessor new TMultiplexedProcessor();AService.ProcessorAImpl aProcessor new AService.Processor(aService);multiplexedProcessor.registerProcessor(aService, aProcessor);BService.ProcessorBImpl bProcessor new BService.Processor(bService);multiplexedProcessor.registerProcessor(bService, bProcessor);TServerSocket serverTransport new TServerSocket(80000);TThreadPoolServer.Args serverArgs new TThreadPoolServer.Args(serverTransport);serverArgs.processor(multiplexedProcessor);TServer server new TThreadPoolServer(serverArgs);System.out.println(Starting the multi-processor server...);server.serve();} catch (Exception e) {e.printStackTrace();System.out.println(e.getMessage());}}客户端
public static void main(String[] args) throws TException {TTransport transport new TSocket(localhost, 80000);transport.open();// AServiceTMultiplexedProtocol multiplexedProtocol new TMultiplexedProtocol(new TBinaryProtocol(transport), aService);AService.Client aClient new AService.Client(multiplexedProtocol);aClient.method();System.out.println(Calling AService method...);// BServicemultiplexedProtocol new TMultiplexedProtocol(new TBinaryProtocol(transport), bService);BService.Client bClient new BService.Client(multiplexedProtocol);BClient.method();System.out.println(Calling SystemLogService method...);transport.close();}这个Demo中我们要用到两个接口类那么A和B使用TMultiplexedProcessor 去注册两个Service启动服务。
单个Process
服务端 AImpl aService new AImpl();TServerSocket serverSocket new TServerSocket(90000);AService.ProcessorAImpl aProcessor new AService.Processor(aService);TThreadPoolServer.Args serverArg new TThreadPoolServer.Args(serverSocket);serverArg.processor(aProcessor);TThreadPoolServer server new TThreadPoolServer(serverArg);server.serve();客户端 TTransport transport new TSocket(localhost, 90000);transport.open();TBinaryProtocol protocol new TBinaryProtocol(transport);AService.Client aClient new AService.Client(protocol);aclient.method();附单个process的方式。