Search in sources :

Example 1 with Args

use of org.apache.thrift.server.TThreadedSelectorServer.Args 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();
    }
}
Also used : TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) TNonblockingServerTransport(org.apache.thrift.transport.TNonblockingServerTransport) Args(org.apache.thrift.server.TThreadedSelectorServer.Args) TProcessor(org.apache.thrift.TProcessor) HelloImpl(org.tech.model.impl.HelloImpl) TProcessor(org.apache.thrift.TProcessor) TServer(org.apache.thrift.server.TServer) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket) TThreadedSelectorServer(org.apache.thrift.server.TThreadedSelectorServer) TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) TTransportFactory(org.apache.thrift.transport.TTransportFactory) TTransportFactory(org.apache.thrift.transport.TTransportFactory)

Example 2 with Args

use of org.apache.thrift.server.TThreadedSelectorServer.Args 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();
    }
}
Also used : TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) TNonblockingServerTransport(org.apache.thrift.transport.TNonblockingServerTransport) Args(org.apache.thrift.server.TThreadedSelectorServer.Args) TProcessor(org.apache.thrift.TProcessor) HelloImpl(org.tech.model.impl.HelloImpl) TProcessor(org.apache.thrift.TProcessor) TServer(org.apache.thrift.server.TServer) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket) TThreadedSelectorServer(org.apache.thrift.server.TThreadedSelectorServer) TTransportFactory(org.apache.thrift.transport.TTransportFactory) TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) TTransportFactory(org.apache.thrift.transport.TTransportFactory)

Aggregations

TProcessor (org.apache.thrift.TProcessor)2 TProtocolFactory (org.apache.thrift.protocol.TProtocolFactory)2 TServer (org.apache.thrift.server.TServer)2 TThreadedSelectorServer (org.apache.thrift.server.TThreadedSelectorServer)2 Args (org.apache.thrift.server.TThreadedSelectorServer.Args)2 TNonblockingServerSocket (org.apache.thrift.transport.TNonblockingServerSocket)2 TNonblockingServerTransport (org.apache.thrift.transport.TNonblockingServerTransport)2 TTransportFactory (org.apache.thrift.transport.TTransportFactory)2 HelloImpl (org.tech.model.impl.HelloImpl)2