use of org.apache.thrift.transport.TNonblockingServerSocket 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.transport.TNonblockingServerSocket 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();
}
}
use of org.apache.thrift.transport.TNonblockingServerSocket in project hbase by apache.
the class ThriftServer method getTThreadedSelectorServer.
private static TServer getTThreadedSelectorServer(TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, int workerThreads, int selectorThreads, int maxCallQueueSize, InetSocketAddress inetSocketAddress, ThriftMetrics metrics) throws TTransportException {
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);
log.info("starting HBase ThreadedSelector Thrift server on " + inetSocketAddress.toString());
TThreadedSelectorServer.Args serverArgs = new TThreadedSelectorServer.Args(serverTransport);
if (workerThreads > 0) {
serverArgs.workerThreads(workerThreads);
}
if (selectorThreads > 0) {
serverArgs.selectorThreads(selectorThreads);
}
ExecutorService executorService = createExecutor(workerThreads, maxCallQueueSize, metrics);
serverArgs.executorService(executorService);
serverArgs.processor(processor);
serverArgs.transportFactory(transportFactory);
serverArgs.protocolFactory(protocolFactory);
return new TThreadedSelectorServer(serverArgs);
}
use of org.apache.thrift.transport.TNonblockingServerSocket in project lucida by claritylab.
the class CalendarDaemon method main.
public static void main(String[] args) throws TTransportException, IOException, InterruptedException {
TProcessor proc = new LucidaService.AsyncProcessor(new CAServiceHandler.AsyncCAServiceHandler());
TNonblockingServerTransport transport = new TNonblockingServerSocket(8084);
TThreadedSelectorServer.Args arguments = new TThreadedSelectorServer.Args(transport).processor(proc).protocolFactory(new TBinaryProtocol.Factory()).transportFactory(new TFramedTransport.Factory());
final TThreadedSelectorServer server = new TThreadedSelectorServer(arguments);
System.out.println("CA at port 8084");
server.serve();
}
use of org.apache.thrift.transport.TNonblockingServerSocket in project lucida by claritylab.
the class QADaemon method main.
/**
* Entry point for question-answer.
* @param args the argument list. Provide port numbers
* for both sirius and qa.
*/
public static void main(String[] args) throws TTransportException, IOException, InterruptedException {
TProcessor proc = new LucidaService.AsyncProcessor(new QAServiceHandler.AsyncQAServiceHandler());
TNonblockingServerTransport transport = new TNonblockingServerSocket(8083);
TThreadedSelectorServer.Args arguments = new TThreadedSelectorServer.Args(transport).processor(proc).protocolFactory(new TBinaryProtocol.Factory()).transportFactory(new TFramedTransport.Factory());
final TThreadedSelectorServer server = new TThreadedSelectorServer(arguments);
System.out.println("QA at port 8083");
server.serve();
}
Aggregations