use of org.apache.thrift.server.TThreadedSelectorServer in project summer by foxsugar.
the class AdminRpcServer method StartServer.
public static TServer StartServer(int port, AdminRPC.AsyncIface iface) throws TTransportException {
TProcessor tprocessor = new AdminRPC.AsyncProcessor<>(iface);
TNonblockingServerSocket serverTransport = null;
serverTransport = new TNonblockingServerSocket(port);
TThreadedSelectorServer.Args tArgs = new TThreadedSelectorServer.Args(serverTransport);
tArgs.processor(tprocessor);
tArgs.maxReadBufferBytes = 1024 * 1024L;
tArgs.transportFactory(new TFramedTransport.Factory());
tArgs.protocolFactory(new TBinaryProtocol.Factory());
TServer server = new TThreadedSelectorServer(tArgs);
server.serve();
return server;
}
use of org.apache.thrift.server.TThreadedSelectorServer in project tech by ffyyhh995511.
the class Test2 method main.
public static void main(String[] args) {
try {
// 传输通道 - 非阻塞方式
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(7911);
// 异步IO,需要使用TFramedTransport,它将分块缓存读取。
TTransportFactory transportFactory = new TFramedTransport.Factory();
// 使用高密度二进制协议
TProtocolFactory proFactory = new TCompactProtocol.Factory();
// 设置处理器 HelloImpl
TProcessor processor = new Hello.Processor(new HelloImpl());
// 创建服务器
Args tArgs = new Args(serverTransport);
tArgs.transportFactory(transportFactory);
tArgs.protocolFactory(proFactory);
tArgs.processor(processor);
TServer server = new TThreadedSelectorServer(tArgs);
System.out.println("Start server on port 7911...");
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.thrift.server.TThreadedSelectorServer in project tech by ffyyhh995511.
the class ThriftDemo method nioServer.
/**
* 基于非阻塞IO(NIO)的服务端
*/
public void nioServer() {
try {
// 传输通道 - 非阻塞方式
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(7911);
// 异步IO,需要使用TFramedTransport,它将分块缓存读取。
TTransportFactory transportFactory = new TFramedTransport.Factory();
// 使用高密度二进制协议
TProtocolFactory proFactory = new TCompactProtocol.Factory();
// 设置处理器 HelloImpl
TProcessor processor = new Hello.Processor(new HelloImpl());
// 创建服务器
Args tArgs = new Args(serverTransport);
tArgs.transportFactory(transportFactory);
tArgs.protocolFactory(proFactory);
tArgs.processor(processor);
TServer server = new TThreadedSelectorServer(tArgs);
System.out.println("Start server on port 7911...");
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations