org.apache.thrift.server.TThreadedSelectorServer Java Examples

The following examples show how to use org.apache.thrift.server.TThreadedSelectorServer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppServer.java    From rpcx-benchmark with Apache License 2.0 6 votes vote down vote up
public static void simple(com.colobu.thrift.Greeter.Processor processor) {
        try {
            TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(8972);
            //TServer server = new TSimpleServer(new TServer.Args(serverTransport).processor(processor));

            // Use this for a multithreaded server
            //TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));

            //https://github.com/rpcx-ecosystem/rpcx-benchmark/issues/1
//            TThreadedSelectorServer server = new TThreadedSelectorServer(
//                new TThreadedSelectorServer.Args(serverTransport).processor(processor).
//                selectorThreads(2).workerThreads(512));

            TThreadedSelectorServer server = new TThreadedSelectorServer(
                    new TThreadedSelectorServer.Args(serverTransport).processor(processor).
                            selectorThreads(2).workerThreads(512));

            System.out.println("Starting the simple server...");
            server.serve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
Example #2
Source File: ThriftServer.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected TServer getTThreadedSelectorServer(TNonblockingServerTransport serverTransport,
    TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory,
    InetSocketAddress inetSocketAddress) {
  LOG.info("starting HBase ThreadedSelector Thrift server on " + inetSocketAddress.toString());
  TThreadedSelectorServer.Args serverArgs =
      new HThreadedSelectorServerArgs(serverTransport, conf);
  int queueSize = conf.getInt(TBoundedThreadPoolServer.MAX_QUEUED_REQUESTS_CONF_KEY,
      TBoundedThreadPoolServer.DEFAULT_MAX_QUEUED_REQUESTS);
  CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(queueSize), metrics);
  int workerThreads = conf.getInt(TBoundedThreadPoolServer.MAX_WORKER_THREADS_CONF_KEY,
      serverArgs.getWorkerThreads());
  int selectorThreads = conf.getInt(THRIFT_SELECTOR_NUM, serverArgs.getSelectorThreads());
  serverArgs.selectorThreads(selectorThreads);
  ExecutorService executorService = createExecutor(
      callQueue, workerThreads, workerThreads);
  serverArgs.executorService(executorService).processor(processor)
      .transportFactory(transportFactory).protocolFactory(protocolFactory);
  return new TThreadedSelectorServer(serverArgs);
}
 
Example #3
Source File: MultiServiceServer.java    From ThriftBook with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #4
Source File: ThriftServer.java    From plow with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #5
Source File: AsyncEchoTestServer.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
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);
        }
    };
}
 
Example #6
Source File: SyncEchoTestServer.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public static SyncEchoTestServer<TThreadedSelectorServer> threadedSelectorServer(
        final TestEnvironment environment) throws TTransportException {
    TThreadedSelectorServer server = new TThreadedSelectorServer(new TThreadedSelectorServer.Args(
            new TNonblockingServerSocket(environment.getPort())).processor(getProcessor())
            .inputProtocolFactory(environment.getProtocolFactory())
            .outputProtocolFactory(environment.getProtocolFactory()));
    return new SyncEchoTestServer<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);
        }
    };
}
 
Example #7
Source File: DasServer.java    From das with Apache License 2.0 5 votes vote down vote up
public static void startServer(int port) throws TTransportException, UnknownHostException, SQLException {
    final long start = System.currentTimeMillis();
    
    String address = InetAddress.getLocalHost().getHostAddress();
    
    DasServerContext serverContext = new DasServerContext(address, port);

    DasServer server = new DasServer(address, serverContext.getWorkerId());

    TBinaryProtocol.Factory protocolFactory = new TBinaryProtocol.Factory();

    DasService.Processor<DasService.Iface> processor = new DasService.Processor<>(
            server);

    int selector = Integer.parseInt(serverContext.getServerConfigure().get(SELECTING_NUMBER));
    int worker   = Integer.parseInt(serverContext.getServerConfigure().get(WORKING_NUMBER));
    TThreadedSelectorServer ttServer = new TThreadedSelectorServer(
            new TThreadedSelectorServer.Args(new TNonblockingServerSocket(port))
                    .selectorThreads(selector)
                    .processor(processor)
                    .workerThreads(worker)
                    .protocolFactory(protocolFactory));

    startupHSServer();
    logger.info("Start server duration on port [" + port + "]: [" +
            TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - start) + "] seconds.");
    ttServer.serve();
}
 
Example #8
Source File: Server.java    From rpc-benchmark with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws TTransportException {
	InetSocketAddress serverAddress = new InetSocketAddress("benchmark-server", 8080);

	TNonblockingServerTransport serverSocket = new TNonblockingServerSocket(serverAddress);
	TThreadedSelectorServer.Args serverParams = new TThreadedSelectorServer.Args(serverSocket);
	serverParams.protocolFactory(new TBinaryProtocol.Factory());
	serverParams.processor(new UserService.Processor<Iface>(new UserServiceThriftServerImpl()));
	TServer server = new TThreadedSelectorServer(serverParams);
	server.serve();
}
 
Example #9
Source File: NonblockingThriftServerImpl.java    From ikasoa with MIT License 5 votes vote down vote up
/**
 * 初始化Thrift服务
 * 
 * @param serverTransport
 *            服务传输类型
 */
@Override
protected void initServer(TServerTransport serverTransport) {
	ThriftServerConfiguration configuration = getServerConfiguration();
	// 使用多线程半同步半异步方式
	TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args((TNonblockingServerSocket) serverTransport)
			.transportFactory(configuration.getTransportFactory())
			.protocolFactory(configuration.getProtocolFactory());
	if (ObjectUtil.isNotNull(configuration.getExecutorService()))
		args.executorService(configuration.getExecutorService());
	server = new TThreadedSelectorServer(
			configuration.getServerArgsAspect().tThreadedSelectorServerArgsAspect(args).processor(getProcessor()));
	if (ObjectUtil.isNotNull(configuration.getServerEventHandler()))
		server.setServerEventHandler(configuration.getServerEventHandler());
}
 
Example #10
Source File: ServerArgsAspect.java    From ikasoa with MIT License 4 votes vote down vote up
public TThreadedSelectorServer.Args tThreadedSelectorServerArgsAspect(TThreadedSelectorServer.Args args) {
	return args;
}
 
Example #11
Source File: ThriftThreadedSelectorServerAsyncIT.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
protected ThriftEchoTestServer<TThreadedSelectorServer> createEchoServer(TestEnvironment environment)
        throws TTransportException {
    return AsyncEchoTestServerFactory.threadedSelectorServer(environment);
}
 
Example #12
Source File: ThriftThreadedSelectorServerIT.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
protected ThriftEchoTestServer<TThreadedSelectorServer> createEchoServer(TestEnvironment environment)
        throws TTransportException {
    return SyncEchoTestServerFactory.threadedSelectorServer(environment);
}