Java 类org.apache.thrift.server.TServer 实例源码

项目: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");
}
项目:jigsaw-payment    文件:HelloServerConfig.java   
@Bean(name = "pool-server")
public TServer poolServer() throws Exception {
    TServerTransport transport = new TServerSocket(this.port());

    TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport);
    args.transportFactory(new TTransportFactory());
    args.protocolFactory(new TBinaryProtocol.Factory());

    args.processor(this.processor());
    args.executorService(new ThreadPoolExecutor(env.getProperty(
            "rpc.server.min.worker.threads", Integer.class, 512), env
            .getProperty("rpc.server.max.worker.threads", Integer.class,
                    65535), env.getProperty(
            "rpc.server.thread.keep.alive.time", Long.class, 600l),
            TimeUnit.SECONDS, new SynchronousQueue<Runnable>()));

    return new TThreadPoolServer(args);
}
项目:scheduler    文件:ProgramEntrance.java   
/**
 * @Title: startSchedulerThriftService
 * @Description: 开启scheduler 同步、异步调用服务
 * @return void 返回类型
 */
private static void startSchedulerThriftService() {
    LOG.info("start scheduler thrift service....");
    new Thread() {
        @Override
        public void run(){
            try {
                SchedulerServiceImpl schedulerServiceImpl =  SpringUtil.getBean(SchedulerServiceImpl.class); 
                TProcessor tprocessor = new SchedulerService.Processor<SchedulerService.Iface>(schedulerServiceImpl);
                TServerSocket serverTransport = new TServerSocket(PropertyLoader.THRIFT_SCHEDULER_PORT);
                TThreadPoolServer.Args ttpsArgs = new TThreadPoolServer.Args(serverTransport);
                ttpsArgs.processor(tprocessor);
                ttpsArgs.protocolFactory(new TBinaryProtocol.Factory());
                //线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。
                TServer server = new TThreadPoolServer(ttpsArgs);
                server.serve();
            } catch (Exception e) {
                LOG.error("start scheduler thrift service error,msg:"+ExceptionUtil.getStackTraceAsString(e));
            }
        }
    }.start();
    LOG.info("start scheduler thrift server success!");
}
项目:algorithm.annotation    文件:SimpleBackendServer.java   
public void startServer() {
    try {
        logger.info("TSimpleServer start ....");

        // TMultiplexedProcessor
        TMultiplexedProcessor processor = new TMultiplexedProcessor();
        processor.registerProcessor("Algorithm", 
                new AlgorithmService.Processor<>(new AlgorithmServiceImpl()));

        TServerSocket serverTransport = new TServerSocket(SERVER_PORT);
        TServer.Args args = new TServer.Args(serverTransport);
        args.processor(processor);
        args.protocolFactory(new TBinaryProtocol.Factory());
        // args.protocolFactory(new TJSONProtocol.Factory());
        TServer server = new TSimpleServer(args);
        server.serve();
        } catch (Exception e) {
        logger.error("Server start error!!!");
        e.printStackTrace();
    }
}
项目: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");
                }
            }
        });
    }
}
项目:ditb    文件:ThriftServer.java   
private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory,
                                            TProcessor processor,
                                            TTransportFactory transportFactory,
                                            int workerThreads,
                                            InetSocketAddress inetSocketAddress,
                                            int backlog,
                                            int clientTimeout)
    throws TTransportException {
  TServerTransport serverTransport = new TServerSocket(
                                         new TServerSocket.ServerSocketTransportArgs().
                                             bindAddr(inetSocketAddress).backlog(backlog).
                                             clientTimeout(clientTimeout));
  log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
  TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
  serverArgs.processor(processor);
  serverArgs.transportFactory(transportFactory);
  serverArgs.protocolFactory(protocolFactory);
  if (workerThreads > 0) {
    serverArgs.maxWorkerThreads(workerThreads);
  }
  return new TThreadPoolServer(serverArgs);
}
项目: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();
    }
}
项目:gemfirexd-oss    文件:GfxdThriftServer.java   
public synchronized void stop() {
  final TServer thriftServer = this.thriftServer;
  if (thriftServer != null) {
    this.service.stop();
    thriftServer.stop();
    final ThreadPoolExecutor connExecutor = this.thriftThreadPerConnExecutor;
    if (connExecutor != null) {
      connExecutor.shutdown();
    }
    this.thriftExecutor.shutdown();
    try {
      this.thriftMainThread.join(5000L);
      // force stop the executor if required
      if (this.thriftMainThread.isAlive()) {
        if (connExecutor != null) {
          connExecutor.shutdownNow();
        }
        this.thriftExecutor.shutdownNow();
        this.thriftMainThread.join();
      }
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
    }
  }
}
项目: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();
    }
}
项目:allocateme    文件:UserProfileServer.java   
public static void main(String[] args) {
    try {
        userProfileServerHandler = new UserProfileServerHandler();
        userProfileProcessor = new UserProfileService.Processor(userProfileServerHandler);

        TMultiplexedProcessor airavataServerProcessor = new TMultiplexedProcessor();

        airavataServerProcessor.registerProcessor("UserProfileService", userProfileProcessor);

        TServerTransport serverTransport = new TServerSocket(9190);

        TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(airavataServerProcessor));

        System.out.println("Starting User Profile server...");
        server.serve();

    } catch (Exception x) {
        x.printStackTrace();
    }
}
项目: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();
    }
}
项目:cassandra-kmean    文件:CustomTNonBlockingServer.java   
public TServer buildTServer(Args args)
{
    if (DatabaseDescriptor.getClientEncryptionOptions().enabled)
        throw new RuntimeException("Client SSL is not supported for non-blocking sockets. Please remove client ssl from the configuration.");

    final InetSocketAddress addr = args.addr;
    TNonblockingServerTransport serverTransport;
    try
    {
        serverTransport = new TCustomNonblockingServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize);
    }
    catch (TTransportException e)
    {
        throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e);
    }

    // This is single threaded hence the invocation will be all
    // in one thread.
    TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport).inputTransportFactory(args.inTransportFactory)
                                                                                     .outputTransportFactory(args.outTransportFactory)
                                                                                     .inputProtocolFactory(args.tProtocolFactory)
                                                                                     .outputProtocolFactory(args.tProtocolFactory)
                                                                                     .processor(args.processor);
    return new CustomTNonBlockingServer(serverArgs);
}
项目:gemfirexd-oss    文件:GfxdThriftServer.java   
public synchronized void stop() {
  final TServer thriftServer = this.thriftServer;
  if (thriftServer != null) {
    this.service.stop();
    thriftServer.stop();
    final ThreadPoolExecutor connExecutor = this.thriftThreadPerConnExecutor;
    if (connExecutor != null) {
      connExecutor.shutdown();
    }
    this.thriftExecutor.shutdown();
    try {
      this.thriftMainThread.join(5000L);
      // force stop the executor if required
      if (this.thriftMainThread.isAlive()) {
        if (connExecutor != null) {
          connExecutor.shutdownNow();
        }
        this.thriftExecutor.shutdownNow();
        this.thriftMainThread.join();
      }
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
    }
  }
}
项目:Blitz-2015    文件:ReferenceMain.java   
public void startServer2() throws Exception
{
    AwesomeService.Processor<AwesomeService.Iface> processor = new AwesomeService.Processor<>(referenceServer);
    TServerTransport serverTransport = new TServerSocket(9090);
    TServer server = new TSimpleServer(new TSimpleServer.Args(serverTransport).processor(processor));

    ServerRunner serverRunner = new ServerRunner(server);
    Thread serverThread = new Thread(serverRunner);

    serverThread.start();
    logger.info("Started binary interface");

    joinMethods.add(() -> {
        try {
            serverThread.join();
        } catch (InterruptedException ignored) {
        }
    });
}
项目: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();
    }
}
项目:ACaZoo    文件:CustomTNonBlockingServer.java   
public TServer buildTServer(Args args)
{
    if (DatabaseDescriptor.getClientEncryptionOptions().enabled)
        throw new RuntimeException("Client SSL is not supported for non-blocking sockets. Please remove client ssl from the configuration.");

    final InetSocketAddress addr = args.addr;
    TNonblockingServerTransport serverTransport;
    try
    {
        serverTransport = new TCustomNonblockingServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize);
    }
    catch (TTransportException e)
    {
        throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e);
    }

    // This is single threaded hence the invocation will be all
    // in one thread.
    TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport).inputTransportFactory(args.inTransportFactory)
                                                                                     .outputTransportFactory(args.outTransportFactory)
                                                                                     .inputProtocolFactory(args.tProtocolFactory)
                                                                                     .outputProtocolFactory(args.tProtocolFactory)
                                                                                     .processor(args.processor);
    return new CustomTNonBlockingServer(serverArgs);
}
项目:providence    文件:RPCThriftSocketTest.java   
@Before
public void setUp() throws Exception {
    Log.setLog(new NoLogging());

    rc = copyResourceTo("/pvdrc", temp.getRoot());
    copyResourceTo("/test.thrift", temp.getRoot());

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

    TServerSocket transport = new TServerSocket(0);
    server = new TSimpleServer(
            new TServer.Args(transport)
                    .protocolFactory(new TBinaryProtocol.Factory())
                    .processor(new MyService.Processor<>(impl)));
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.submit(server::serve);
    Thread.sleep(1);
    port = transport.getServerSocket().getLocalPort();

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

    port = findFreePort();
    impl = Mockito.mock(Iface.class);

    TServerSocket transport = new TServerSocket(port);
    server = new TSimpleServer(
            new TServer.Args(transport)
                    .protocolFactory(new TBinaryProtocol.Factory())
                    .processor(new Processor<>(impl)));
    executor = Executors.newSingleThreadExecutor();
    executor.submit(server::serve);
    serializer = new BinarySerializer();
    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();
    }
}
项目:ezbake-common-java    文件:ThriftUtils.java   
private static TServer startSimpleServer(final TServerTransport transport, final TProcessor processor,
        Properties properties) throws Exception {

    TServer.AbstractServerArgs<?> serverArgs;
    if (properties == null) {
        serverArgs = new TServer.Args(transport).processor(processor);
    } else {
        serverArgs = ThriftUtils.getServerArgs(transport, properties).processor(processor);
    }

    final TServer server = new TSimpleServer(serverArgs);
    new Thread(new Runnable() {

        @Override
        public void run() {
            server.serve();
        }
    }).start();
    return server;
}
项目:ezbake-common-java    文件:ThriftUtils.java   
private static TServer startThreadedPoolServer(final TServerTransport transport, final TProcessor processor,
        Properties properties) throws Exception {

    TThreadPoolServer.Args serverArgs;
    if (properties == null) {
        serverArgs = new TThreadPoolServer.Args(transport).processor(processor);
    } else {
        serverArgs =
                (TThreadPoolServer.Args) ThriftUtils.getServerArgs(transport, properties).processor(
                        processor);
    }

    final TServer server = new TThreadPoolServer(serverArgs);
    new Thread(new Runnable() {
        @Override
        public void run() {
            server.serve();
        }
    }).start();
    return server;
}
项目:ezbake-common-java    文件:ThriftUtils.java   
@VisibleForTesting
public static TServer startHshaServer(TProcessor processor, int portNumber) throws Exception {

    final TNonblockingServerSocket socket = new TNonblockingServerSocket(portNumber);
    final THsHaServer.Args serverArgs = new THsHaServer.Args(socket);
    serverArgs.processor(processor);
    serverArgs.inputProtocolFactory(new TCompactProtocol.Factory());
    serverArgs.outputProtocolFactory(new TCompactProtocol.Factory());
    final TServer server = new THsHaServer(serverArgs);
    final Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            server.serve();
        }
    });
    t.start();
    return server;
}
项目:ezbake-common-java    文件:ThriftUtils.java   
@SuppressWarnings("null")
public static TServer.AbstractServerArgs<?> getServerArgs(TServerTransport transport, Properties properties) {
    TServer.AbstractServerArgs<?> args = null;
    ThriftConfigurationHelper thriftConfiguration = new ThriftConfigurationHelper(properties);
    switch (thriftConfiguration.getServerMode()) {
        case Simple:
            args = new TServer.Args(transport);
            break;
        case ThreadedPool:
            args = new TThreadPoolServer.Args(transport);
            break;
        case HsHa:
            throw new IllegalArgumentException("Unable to create an HsHa Server Args at this time");
    }

    // Use the EzSecureTransport (exposes peer ssl certs) if using SSL
    if (thriftConfiguration.useSSL()) {
        args.inputTransportFactory(new EzSecureServerTransport.Factory(properties));
    }

    return args;
}
项目:jstrom    文件:SaslTransportPlugin.java   
@Override
public TServer getServer(TProcessor processor) throws IOException, TTransportException {
    int port = type.getPort(storm_conf);
    TTransportFactory serverTransportFactory = getServerTransportFactory();
    TServerSocket serverTransport = new TServerSocket(port);
    int numWorkerThreads = type.getNumThreads(storm_conf);
    Integer queueSize = type.getQueueSize(storm_conf);

    TThreadPoolServer.Args server_args =
            new TThreadPoolServer.Args(serverTransport).processor(new TUGIWrapProcessor(processor)).minWorkerThreads(numWorkerThreads)
                    .maxWorkerThreads(numWorkerThreads).protocolFactory(new TBinaryProtocol.Factory(false, true));

    if (serverTransportFactory != null) {
        server_args.transportFactory(serverTransportFactory);
    }
    BlockingQueue workQueue = new SynchronousQueue();
    if (queueSize != null) {
        workQueue = new ArrayBlockingQueue(queueSize);
    }
    ThreadPoolExecutor executorService = new ExtendedThreadPoolExecutor(numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, workQueue);
    server_args.executorService(executorService);
    return new TThreadPoolServer(server_args);
}
项目: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();
    }
}
项目:scylla-tools-java    文件:CustomTNonBlockingServer.java   
@SuppressWarnings("resource")
public TServer buildTServer(Args args)
{
    if (DatabaseDescriptor.getClientEncryptionOptions().enabled)
        throw new RuntimeException("Client SSL is not supported for non-blocking sockets. Please remove client ssl from the configuration.");

    final InetSocketAddress addr = args.addr;
    TNonblockingServerTransport serverTransport;
    try
    {
        serverTransport = new TCustomNonblockingServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize);
    }
    catch (TTransportException e)
    {
        throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e);
    }

    // This is single threaded hence the invocation will be all
    // in one thread.
    TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport).inputTransportFactory(args.inTransportFactory)
                                                                                     .outputTransportFactory(args.outTransportFactory)
                                                                                     .inputProtocolFactory(args.tProtocolFactory)
                                                                                     .outputProtocolFactory(args.tProtocolFactory)
                                                                                     .processor(args.processor);
    return new CustomTNonBlockingServer(serverArgs);
}
项目: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();
    }
}
项目:springside-engine    文件:StandardBIOServer.java   
public static void main(String[] args) {
    try {
        handler = new CalculatorHandler();
        processor = new Calculator.Processor(handler);

        try {
            TServerTransport serverTransport = new TServerSocket(9090);
            TServer server = new TThreadPoolServer(new TThreadPoolServer.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();
    }
}
项目:GraphTrek    文件:CustomTNonBlockingServer.java   
public TServer buildTServer(Args args)
{
    if (DatabaseDescriptor.getClientEncryptionOptions().enabled)
        throw new RuntimeException("Client SSL is not supported for non-blocking sockets. Please remove client ssl from the configuration.");

    final InetSocketAddress addr = args.addr;
    TNonblockingServerTransport serverTransport;
    try
    {
        serverTransport = new TCustomNonblockingServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize);
    }
    catch (TTransportException e)
    {
        throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e);
    }

    // This is single threaded hence the invocation will be all
    // in one thread.
    TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport).inputTransportFactory(args.inTransportFactory)
                                                                                     .outputTransportFactory(args.outTransportFactory)
                                                                                     .inputProtocolFactory(args.tProtocolFactory)
                                                                                     .outputProtocolFactory(args.tProtocolFactory)
                                                                                     .processor(args.processor);
    return new CustomTNonBlockingServer(serverArgs);
}