Search in sources :

Example 6 with TNonblockingServerSocket

use of org.apache.thrift.transport.TNonblockingServerSocket in project jstorm by alibaba.

the class Drpc method initHandlerServer.

private THsHaServer initHandlerServer(Map conf, final Drpc service) throws Exception {
    int port = JStormUtils.parseInt(conf.get(Config.DRPC_PORT));
    int workerThreadNum = JStormUtils.parseInt(conf.get(Config.DRPC_WORKER_THREADS));
    int queueSize = JStormUtils.parseInt(conf.get(Config.DRPC_QUEUE_SIZE));
    LOG.info("Begin to init Handler Server " + port);
    TNonblockingServerSocket socket = new TNonblockingServerSocket(port);
    THsHaServer.Args targs = new THsHaServer.Args(socket);
    targs.workerThreads(64);
    targs.protocolFactory(new TBinaryProtocol.Factory());
    targs.processor(new DistributedRPC.Processor<DistributedRPC.Iface>(service));
    ThreadPoolExecutor executor = new ThreadPoolExecutor(workerThreadNum, workerThreadNum, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(queueSize));
    targs.executorService(executor);
    THsHaServer handlerServer = new THsHaServer(targs);
    LOG.info("Successfully init Handler Server " + port);
    return handlerServer;
}
Also used : THsHaServer(org.apache.thrift.server.THsHaServer) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) DistributedRPC(backtype.storm.generated.DistributedRPC) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 7 with TNonblockingServerSocket

use of org.apache.thrift.transport.TNonblockingServerSocket in project jstorm by alibaba.

the class NimbusServer method initThrift.

@SuppressWarnings("rawtypes")
private void initThrift(Map conf) throws TTransportException {
    Integer thrift_port = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_PORT));
    TNonblockingServerSocket socket = new TNonblockingServerSocket(thrift_port);
    Integer maxReadBufSize = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_MAX_BUFFER_SIZE));
    THsHaServer.Args args = new THsHaServer.Args(socket);
    args.workerThreads(ServiceHandler.THREAD_NUM);
    args.protocolFactory(new TBinaryProtocol.Factory(false, true, maxReadBufSize, -1));
    args.processor(new Nimbus.Processor<Iface>(serviceHandler));
    args.maxReadBufferBytes = maxReadBufSize;
    thriftServer = new THsHaServer(args);
    LOG.info("Successfully started nimbus: started Thrift server...");
    thriftServer.serve();
}
Also used : Iface(backtype.storm.generated.Nimbus.Iface) THsHaServer(org.apache.thrift.server.THsHaServer) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket) Nimbus(backtype.storm.generated.Nimbus) INimbus(backtype.storm.scheduler.INimbus)

Example 8 with TNonblockingServerSocket

use of org.apache.thrift.transport.TNonblockingServerSocket in project yyl_example by Relucent.

the class HelloServer method getNonblockingServer.

/** 使用非阻塞式IO,服务端和客户端需要指定 TFramedTransport 数据传输的方式 。 */
public static TServer getNonblockingServer(int port, HelloService.Processor<HelloServiceHandler> processor) throws TTransportException {
    TNonblockingServerSocket transport = new TNonblockingServerSocket(port);
    TNonblockingServer.Args args = new TNonblockingServer.Args(transport).processor(processor);
    //服务端和客户端需要指定TFramedTransport数据传输的方式
    TServer server = new TNonblockingServer(args);
    return server;
}
Also used : TServer(org.apache.thrift.server.TServer) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket) TNonblockingServer(org.apache.thrift.server.TNonblockingServer)

Example 9 with TNonblockingServerSocket

use of org.apache.thrift.transport.TNonblockingServerSocket in project yyl_example by Relucent.

the class HelloServer method getHsHaServer.

/** 半同步半异步的服务端模型,需要指定为: TFramedTransport 数据传输的方式 */
public static TServer getHsHaServer(int port, HelloService.Processor<HelloServiceHandler> processor) throws TTransportException {
    TNonblockingServerSocket transport = new TNonblockingServerSocket(port);
    THsHaServer.Args args = new THsHaServer.Args(transport).processor(processor);
    TServer server = new THsHaServer(args);
    return server;
}
Also used : THsHaServer(org.apache.thrift.server.THsHaServer) TServer(org.apache.thrift.server.TServer) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket)

Example 10 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)16 THsHaServer (org.apache.thrift.server.THsHaServer)9 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)6 TNonblockingServerTransport (org.apache.thrift.transport.TNonblockingServerTransport)6 TThreadedSelectorServer (org.apache.thrift.server.TThreadedSelectorServer)5 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)3 ExecutorService (java.util.concurrent.ExecutorService)3 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 TProcessor (org.apache.thrift.TProcessor)3 TNonblockingServer (org.apache.thrift.server.TNonblockingServer)3 TFramedTransport (org.apache.thrift.transport.TFramedTransport)3 TServer (org.apache.thrift.server.TServer)2 TServerSocket (org.apache.thrift.transport.TServerSocket)2 TTransportException (org.apache.thrift.transport.TTransportException)2 DistributedRPC (backtype.storm.generated.DistributedRPC)1 DistributedRPCInvocations (backtype.storm.generated.DistributedRPCInvocations)1 Nimbus (backtype.storm.generated.Nimbus)1 Iface (backtype.storm.generated.Nimbus.Iface)1 INimbus (backtype.storm.scheduler.INimbus)1 ThriftException (com.facebook.buck.slb.ThriftException)1