use of org.apache.thrift.server.TServer in project tech by ffyyhh995511.
the class Test1 method main.
/**
* 编写服务端,发布(阻塞式IO + 多线程处理)服务
*
* @param args
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
try {
// 设置传输通道,普通通道
TServerTransport serverTransport = new TServerSocket(7911);
// 使用高密度二进制协议
TProtocolFactory proFactory = new TCompactProtocol.Factory();
// 设置处理器HelloImpl
TProcessor processor = new Hello.Processor(new HelloImpl());
// 创建服务器
Args args2 = new Args(serverTransport);
args2.protocolFactory(proFactory);
args2.processor(processor);
TServer server = new TThreadPoolServer(args2);
System.out.println("Start server on port 7911...");
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.thrift.server.TServer 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.TServer 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