Search in sources :

Example 21 with TNonblockingServerSocket

use of org.apache.thrift.transport.TNonblockingServerSocket in project storm by nathanmarz.

the class SimpleTransportPlugin method getServer.

/**
 * We will let Thrift to apply default transport factory
 */
public TServer getServer(int port, TProcessor processor) throws IOException, TTransportException {
    TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(port);
    THsHaServer.Args server_args = new THsHaServer.Args(serverTransport).processor(new SimpleWrapProcessor(processor)).workerThreads(64).protocolFactory(new TBinaryProtocol.Factory());
    // construct THsHaServer
    return new THsHaServer(server_args);
}
Also used : THsHaServer(org.apache.thrift.server.THsHaServer) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket)

Example 22 with TNonblockingServerSocket

use of org.apache.thrift.transport.TNonblockingServerSocket 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;
}
Also used : TProcessor(org.apache.thrift.TProcessor) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TServer(org.apache.thrift.server.TServer) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket) TThreadedSelectorServer(org.apache.thrift.server.TThreadedSelectorServer)

Example 23 with TNonblockingServerSocket

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();
    }
}
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)

Example 24 with TNonblockingServerSocket

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();
    }
}
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 25 with TNonblockingServerSocket

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);
}
Also used : TNonblockingServerTransport(org.apache.thrift.transport.TNonblockingServerTransport) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket) TThreadedSelectorServer(org.apache.thrift.server.TThreadedSelectorServer) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

TNonblockingServerSocket (org.apache.thrift.transport.TNonblockingServerSocket)33 TThreadedSelectorServer (org.apache.thrift.server.TThreadedSelectorServer)14 THsHaServer (org.apache.thrift.server.THsHaServer)13 TProcessor (org.apache.thrift.TProcessor)12 TServer (org.apache.thrift.server.TServer)12 TNonblockingServerTransport (org.apache.thrift.transport.TNonblockingServerTransport)12 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)11 InetSocketAddress (java.net.InetSocketAddress)9 TFramedTransport (org.apache.thrift.transport.TFramedTransport)9 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)7 TNonblockingServer (org.apache.thrift.server.TNonblockingServer)7 ExecutorService (java.util.concurrent.ExecutorService)6 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)6 TProtocolFactory (org.apache.thrift.protocol.TProtocolFactory)5 TTransportException (org.apache.thrift.transport.TTransportException)5 TProcessorFactory (org.apache.thrift.TProcessorFactory)4 TServerSocket (org.apache.thrift.transport.TServerSocket)4 TTransportFactory (org.apache.thrift.transport.TTransportFactory)4 InetAddress (java.net.InetAddress)2 Map (java.util.Map)2