importhellodemo.Hello;importorg.apache.thrift.TProcessor;importorg.apache.thrift.protocol.TBinaryProtocol;importorg.apache.thrift.protocol.TBinaryProtocol.Factory;importorg.apache.thrift.server.TServer;importorg.apache.thrift.server.TSimpleServer;importorg.apache.thrift.server.TThreadPoolServer;importorg.apache.thrift.server.TThreadPoolServer.Args;importorg.apache.thrift.transport.TServerSocket;importorg.apache.thrift.transport.TServerTransport;importorg.apache.thrift.transport.TTransportException;public classHelloServiceServer {/*** 启动thrift服务器
*@paramargs*/
public static voidmain(String[] args) {try{//设置服务器端口为7911
TServerSocket serverTransport = new TServerSocket(7911);//设置协议工厂为TBinaryProtocol.Factory
Factory proFactory = newTBinaryProtocol.Factory();//关联处理器与Hello服务的实现
TProcessor processor = new Hello.Processor(newHelloServiceImpl());
TServer.Args tArgs= newTServer.Args(serverTransport);
tArgs.processor(processor);
tArgs.protocolFactory(proFactory);//使用TSimpleServer
TServer server = newTSimpleServer(tArgs);
System.out.println("Start server on port 7911....");
server.serve();//server.stop();
}catch(TTransportException e){
e.printStackTrace();
}/*try{
//设置服务器端口为7911
TServerSocket serverTransport = new TServerSocket(7911);
//设置协议工厂为TBinaryProtocol.Factory
Factory proFactory = new TBinaryProtocol.Factory();
//关联处理器与Hello服务的实现
TProcessor processor = new Hello.Processor(new HelloServiceImpl());
Args tArgs = new Args(serverTransport);
tArgs.processor(processor);
tArgs.protocolFactory(proFactory);
TServer server = new TThreadPoolServer(tArgs);
System.out.println("Start server on port 7911....");
server.serve();
TServerTransport s = new TServerSocket(11);
}catch(TTransportException e){
e.printStackTrace();
}*/}
}