Java 类org.apache.thrift.transport.TNonblockingServerSocket 实例源码

项目:ThriftBook    文件:MultiServiceServer.java   
public static void main(String[] args) throws TTransportException, IOException, InterruptedException {
    TNonblockingServerSocket trans_svr = new TNonblockingServerSocket(9090);
    TMultiplexedProcessor proc = new TMultiplexedProcessor();
    proc.registerProcessor("Message", new Message.Processor<>(new MessageHandler()));
    proc.registerProcessor("ServerTime", new ServerTime.Processor<>(new ServerTimeHandler()));

    TServer server = new TThreadedSelectorServer(
            new TThreadedSelectorServer.Args(trans_svr)
            .processor(proc)
            .protocolFactory(new TJSONProtocol.Factory())
            .workerThreads(6)
            .selectorThreads(3));
    Thread server_thread = new Thread(new RunnableServer(server), "server_thread");
    server_thread.start();

    System.out.println("[Server] press enter to shutdown> ");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    br.readLine();
    System.out.println("[Server] shutting down...");
    server.stop();
    server_thread.join();
    System.out.println("[Server] down, exiting");
}
项目:rpc-comparison    文件:AskerServer.java   
private void nonBlockMode() {
        AskerHandler handler = new AskerHandler();
        Asker.Processor processor = new Asker.Processor(handler);
        try {
            TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
            THsHaServer.Args arg = new THsHaServer.Args(transport);
            arg.protocolFactory(new TCompactProtocol.Factory());
//            arg.transportFactory(new TFramedTransport.Factory());
//            arg.processorFactory(new TProcessorFactory(processor));
            arg.processor(processor);
            server = new THsHaServer(arg);
            start.countDown();

            System.out.println("Starting the nonBlock server...");
            server.serve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
项目:flume-release-1.7.0    文件:ThriftTestingSource.java   
public ThriftTestingSource(String handlerName, int port, String protocol) throws Exception {
  TNonblockingServerTransport serverTransport =
      new TNonblockingServerSocket(new InetSocketAddress("0.0.0.0", port));
  ThriftSourceProtocol.Iface handler = getHandler(handlerName);

  TProtocolFactory transportProtocolFactory = null;
  if (protocol != null && protocol == ThriftRpcClient.BINARY_PROTOCOL) {
    transportProtocolFactory = new TBinaryProtocol.Factory();
  } else {
    transportProtocolFactory = new TCompactProtocol.Factory();
  }
  server = new THsHaServer(new THsHaServer.Args(serverTransport).processor(
      new ThriftSourceProtocol.Processor(handler)).protocolFactory(
          transportProtocolFactory));
  Executors.newSingleThreadExecutor().submit(new Runnable() {
    @Override
    public void run() {
      server.serve();
    }
  });
}
项目:flume-release-1.7.0    文件:ScribeSource.java   
public void run() {
  try {
    Scribe.Processor processor = new Scribe.Processor(new Receiver());
    TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
    THsHaServer.Args args = new THsHaServer.Args(transport);

    args.workerThreads(workers);
    args.processor(processor);
    args.transportFactory(new TFramedTransport.Factory(maxReadBufferBytes));
    args.protocolFactory(new TBinaryProtocol.Factory(false, false));
    args.maxReadBufferBytes = maxReadBufferBytes;

    server = new THsHaServer(args);

    LOG.info("Starting Scribe Source on port " + port);

    server.serve();
  } catch (Exception e) {
    LOG.warn("Scribe failed", e);
  }
}
项目:fresco_floodlight    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:iTAP-controller    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:ThriftJ    文件:ThriftServerTest2.java   
public static void main(String[] args){
    ExecutorService es = Executors.newFixedThreadPool(2);
    for(int i=0; i<ports.length; i++){
        final int index = i;
        es.execute(new Runnable() {
            @Override
            public void run() {
                try{
                    TNonblockingServerSocket socket = new TNonblockingServerSocket(ports[index]);
                    TestThriftJ.Processor processor = new TestThriftJ.Processor(new QueryImp());
                    TNonblockingServer.Args arg = new TNonblockingServer.Args(socket);
                    arg.protocolFactory(new TBinaryProtocol.Factory());
                    arg.transportFactory(new TFramedTransport.Factory());
                    arg.processorFactory(new TProcessorFactory(processor));
                    TServer server = new TNonblockingServer (arg);

                    logger.info("127.0.0.1:" + ports[index] + " start");
                    server.serve();
                }catch(Exception e){
                    logger.error("127.0.0.1:" + ports[index] + " error");
                }
            }
        });
    }
}
项目:ThriftJ    文件:ThriftServerTest.java   
public static void main(String[] args){
    ExecutorService es = Executors.newFixedThreadPool(2);
    for(int i=0; i<ports.length; i++){
        final int index = i;
        es.execute(new Runnable() {
            @Override
            public void run() {
                try{
                    TNonblockingServerSocket socket = new TNonblockingServerSocket(ports[index]);
                    TestThriftJ.Processor processor = new TestThriftJ.Processor(new QueryImp());
                    TNonblockingServer.Args arg = new TNonblockingServer.Args(socket);
                    arg.protocolFactory(new TBinaryProtocol.Factory());
                    arg.transportFactory(new TFramedTransport.Factory());
                    arg.processorFactory(new TProcessorFactory(processor));
                    TServer server = new TNonblockingServer(arg);

                    logger.info("127.0.0.1:" + ports[index] + " start");
                    server.serve();
                }catch(Exception e){
                    logger.error("127.0.0.1:" + ports[index] + " error");
                }
            }
        });
    }
}
项目:leaf-snowflake    文件:rpcServer.java   
public static void startRPCServer2(leafServer leafserver , String ip , int port) throws Exception
{
    //关联处理器leafrpc的实现
    TProcessor processor = new leafrpc.Processor<leafrpc.Iface>(new RPCService(leafserver));
    //传输通道,非阻塞模式
    InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(ip),port);
    TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(address,10000);
    //多线程半同步半异步
    TThreadedSelectorServer.Args tArgs = new TThreadedSelectorServer.Args(serverTransport);
    tArgs.processor(processor);
    //二进制协议
    tArgs.protocolFactory(new TBinaryProtocol.Factory());
    //多线程半同步半异步的服务模型
    TServer server = new TThreadedSelectorServer(tArgs);
    LOG.info("leaf RPCServer(type:TThreadedSelectorServer) start at ip:port : "+ ip +":" + port );
    server.serve();
}
项目:SDN-Multicast    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:arscheduler    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:trpc    文件:DemoServer.java   
public void start(CountDownLatch latch, int port) {
    try {
        TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(port);
        //异步IO,需要使用TFramedTransport,它将分块缓存读取。
        TTransportFactory transportFactory = new TFramedTransport.Factory();
        //使用高密度二进制协议
        TProtocolFactory proFactory = new TBinaryProtocol.Factory();
        //发布多个服务
        TMultiplexedProcessor processor = new TMultiplexedProcessor();
        processor.registerProcessor(ClassNameUtils.getClassName(Hello.class), new Hello.Processor<>(new HelloServer()));

        TServer server = new TThreadedSelectorServer(new
                TThreadedSelectorServer.Args(serverTransport)
                .transportFactory(transportFactory)
                .protocolFactory(proFactory)
                .processor(processor)
        );
        System.out.println("Starting the hello server...");
        latch.countDown();
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:QoS-floodlight    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:floodlight1.2-delay    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:floodlight-hardware    文件:PacketStreamerServer.java   
/**
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:ACAMPController    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:frc    文件:Application.java   
private static boolean createThrift() {
    String flag = getClassName() + ".createThrift";
    try {
        TProcessor tProcessor = new FrcService.Processor<FrcService.Iface>(theInstance);

        TNonblockingServerSocket tnbSocketTransport = new TNonblockingServerSocket(thrift_port);
        TNonblockingServer.Args tnbArgs = new TNonblockingServer.Args(tnbSocketTransport);
        tnbArgs.maxReadBufferBytes = DefaultValues.THRIFT_MAX_READ_BUF;
        tnbArgs.processor(tProcessor);
        // tnbArgs.transportFactory(new LCQTFramedTransport.Factory());
        tnbArgs.transportFactory(new TFramedTransport.Factory());
        tnbArgs.protocolFactory(new TBinaryProtocol.Factory());

        server = new TNonblockingServer(tnbArgs);
        // server.setServerEventHandler(new LCQTServerEventHandler());
        return true;
    } catch (Exception e) {
        FRCLogger.getInstance().warn(-100, flag, "exception", e);
        return false;
    }
}
项目:fast-failover-demo    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:floodlightLB    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:DSC    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:providence    文件:RPCThriftNonblockingSocketTest.java   
@Before
public void setUp() throws Exception {
    rc = copyResourceTo("/pvdrc", temp.getRoot());
    copyResourceTo("/test.thrift", temp.getRoot());

    impl = Mockito.mock(MyService.Iface.class);

    TNonblockingServerSocket transport = new TNonblockingServerSocket(0);
    server = new TNonblockingServer(new TNonblockingServer.Args(transport).protocolFactory(new TBinaryProtocol.Factory())
                                                                          .processor(new MyService.Processor<>(impl)));

    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.submit(server::serve);
    Thread.sleep(1);
    port = transport.getPort();

    exitCode = 0;
    rpc = new RPC(console.tty()) {
        @Override
        protected void exit(int i) {
            exitCode = i;
        }
    };
}
项目:providence    文件:NonblockingSocketClientHandlerTest.java   
@BeforeClass
public static void setUpServer() throws Exception {
    setDefaultPollDelay(10, TimeUnit.MILLISECONDS);

    serializer = new TBinaryProtocolSerializer();
    factory = new TBinaryProtocol.Factory();
    port = findFreePort();
    impl = Mockito.mock(Iface.class);

    TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
    server = new TNonblockingServer(
            new TNonblockingServer.Args(transport)
                    .protocolFactory(factory)
                    .processor(new Processor<>(impl)));

    executor = Executors.newSingleThreadExecutor();
    executor.submit(server::serve);
    address = new InetSocketAddress("localhost", port);
}
项目:Multipath-Hedera-system-in-Floodlight-controller    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:jstrom    文件:Drpc.java   
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));

    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;
}
项目:jstrom    文件:NimbusServer.java   
@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();
}
项目:jstrom    文件:SimpleTransportPlugin.java   
@Override
public TServer getServer(TProcessor processor) throws IOException, TTransportException {
    int port = type.getPort(storm_conf);
    TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(port);
    int numWorkerThreads = type.getNumThreads(storm_conf);
    int maxBufferSize = type.getMaxBufferSize(storm_conf);
    Integer queueSize = type.getQueueSize(storm_conf);

    THsHaServer.Args server_args =
            new THsHaServer.Args(serverTransport).processor(new SimpleWrapProcessor(processor)).workerThreads(numWorkerThreads)
                    .protocolFactory(new TBinaryProtocol.Factory(false, true, maxBufferSize, -1));

    if (queueSize != null) {
        server_args.executorService(new ThreadPoolExecutor(numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(queueSize)));
    }

    // construct THsHaServer
    return new THsHaServer(server_args);
}
项目:floodlight_with_topoguard    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:floodlight    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:springside-engine    文件:StandardNIOServer.java   
public static void main(String[] args) {
    try {
        handler = new CalculatorHandler();
        processor = new Calculator.Processor(handler);
        try {
            TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(9090);
            TServer server = new TThreadedSelectorServer(
                    new TThreadedSelectorServer.Args(serverTransport).processor(processor));

            System.out.println("Starting the  server...");
            server.serve();
        } catch (TTransportException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } catch (Exception x) {
        x.printStackTrace();
    }
}
项目:hbase    文件:ThriftServer.java   
private static TServer getTHsHaServer(TProtocolFactory protocolFactory,
    TProcessor processor, TTransportFactory transportFactory,
    int workerThreads, int maxCallQueueSize,
    InetSocketAddress inetSocketAddress, ThriftMetrics metrics)
    throws TTransportException {
  TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);
  log.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString());
  THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);
  if (workerThreads > 0) {
    // Could support the min & max threads, avoiding to preserve existing functionality.
    serverArgs.minWorkerThreads(workerThreads).maxWorkerThreads(workerThreads);
  }
  ExecutorService executorService = createExecutor(
      workerThreads, maxCallQueueSize, metrics);
  serverArgs.executorService(executorService);
  serverArgs.processor(processor);
  serverArgs.transportFactory(transportFactory);
  serverArgs.protocolFactory(protocolFactory);
  return new THsHaServer(serverArgs);
}
项目:hbase    文件:ThriftServer.java   
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);
}
项目:FloodligtModule    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:osgi-bundle-frontapi    文件:ThriftUtils.java   
public static TServer createThreadedSelectorServer(TProcessorFactory processorFactory,
        int port, int clientTimeoutMillisecs, int maxFrameSize, long maxReadBufferSize)
        throws TTransportException {
    int numThreads = Math.max(2, Runtime.getRuntime().availableProcessors());
    int selectorThreads = Math.max(2, Runtime.getRuntime().availableProcessors() / 2);
    TNonblockingServerTransport transport = new TNonblockingServerSocket(port,
            clientTimeoutMillisecs);
    TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
    TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize);
    TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args(transport)
            .processorFactory(processorFactory).protocolFactory(protocolFactory)
            .transportFactory(transportFactory).workerThreads(numThreads)
            .acceptPolicy(AcceptPolicy.FAIR_ACCEPT).acceptQueueSizePerThread(10000)
            .selectorThreads(selectorThreads);
    args.maxReadBufferBytes = maxReadBufferSize;
    TThreadedSelectorServer server = new TThreadedSelectorServer(args);
    return server;
}
项目:smartenit    文件:PacketStreamerServer.java   
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:ThriftBook    文件:AsyncServer.java   
public static void main(String[] args)
        throws TTransportException, IOException, InterruptedException {

    FloorBroker floor = new FloorBroker();
    (new Thread(floor)).start();

    TProcessor proc = new TradeReporting.TradeHistory.AsyncProcessor(
        new AsyncTradeHistoryHandler(floor.getQ()));
    TNonblockingServerSocket trans_svr = new TNonblockingServerSocket(9090);
    TServer server = 
        new THsHaServer(new THsHaServer.Args(trans_svr)
            .processor(proc)
            .protocolFactory(new TBinaryProtocol.Factory())
            .minWorkerThreads(4)
            .maxWorkerThreads(4));
    System.out.println("[Server] listening of port 9090");
    server.serve();
}
项目:lucida    文件:CalendarDaemon.java   
public static void main(String [] args) 
        throws TTransportException, IOException, InterruptedException { 
    Properties port_cfg = new Properties();
    InputStream input = new FileInputStream("../config.properties");
    port_cfg.load(input);
    String port_str = port_cfg.getProperty("CA_PORT");
    Integer port = Integer.valueOf(port_str);
    TProcessor proc = new LucidaService.AsyncProcessor(
            new CAServiceHandler.AsyncCAServiceHandler());
    TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
    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 " + port_str);
    server.serve();
}
项目:lucida    文件:QADaemon.java   
/** 
 * 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 { 
    Properties port_cfg = new Properties();
    InputStream input = new FileInputStream("../../config.properties");
    port_cfg.load(input);
    String port_str = port_cfg.getProperty("QA_PORT");
    Integer port = Integer.valueOf(port_str);
    TProcessor proc = new LucidaService.AsyncProcessor(
            new QAServiceHandler.AsyncQAServiceHandler());
    TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
    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 " + port_str);
    server.serve();
}
项目:plow    文件:ThriftServer.java   
@PostConstruct
public void start() {
    logger.info("Starting thift server " + name + " on port " + port);

    try {
        transport = new TNonblockingServerSocket(port);
        server = new TThreadedSelectorServer(
                new TThreadedSelectorServer.Args(transport)
            .processor(processor)
            .workerThreads(threads)
            .selectorThreads((threads / 16) + 1)
            .protocolFactory(protocolFactory)
            .transportFactory(new TFramedTransport.Factory()));
        thread.start();

    } catch (TTransportException e) {
        throw new RuntimeException("Unable to start thrift server " + e, e);
    }
}
项目:pinpoint    文件:AsyncEchoTestServer.java   
public static AsyncEchoTestServer<TThreadedSelectorServer> threadedSelectorServer(
        final TestEnvironment environment) throws TTransportException {
    TThreadedSelectorServer server = new TThreadedSelectorServer(new TThreadedSelectorServer.Args(
            new TNonblockingServerSocket(environment.getPort())).processor(getAsyncProcessor())
            .inputProtocolFactory(environment.getProtocolFactory())
            .outputProtocolFactory(environment.getProtocolFactory()));
    return new AsyncEchoTestServer<TThreadedSelectorServer>(server, environment) {
        @Override
        public SyncEchoTestClient getSynchronousClient() throws TTransportException {
            return new SyncEchoTestClient.ClientForNonblockingServer(environment);
        }

        @Override
        public AsyncEchoTestClient getAsynchronousClient() throws IOException {
            return new AsyncEchoTestClient.Client(environment);
        }
    };
}
项目:pinpoint    文件:AsyncEchoTestServer.java   
public static AsyncEchoTestServer<TNonblockingServer> nonblockingServer(final TestEnvironment environment)
        throws TTransportException {
    TNonblockingServer server = new TNonblockingServer(new TNonblockingServer.Args(
            new TNonblockingServerSocket(environment.getPort())).processor(getAsyncProcessor())
            .inputProtocolFactory(environment.getProtocolFactory())
            .outputProtocolFactory(environment.getProtocolFactory()));
    return new AsyncEchoTestServer<TNonblockingServer>(server, environment) {
        @Override
        public SyncEchoTestClient getSynchronousClient() throws TTransportException {
            return new SyncEchoTestClient.ClientForNonblockingServer(environment);
        }

        @Override
        public AsyncEchoTestClient getAsynchronousClient() throws IOException {
            return new AsyncEchoTestClient.Client(environment);
        }
    };
}