org.apache.thrift.server.TServer Java Examples

The following examples show how to use org.apache.thrift.server.TServer. 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: AsyncServer.java    From ThriftBook with Apache License 2.0 7 votes vote down vote up
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();
}
 
Example #2
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 #3
Source File: ThriftITest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
  final CountDownLatch latch = TestUtil.initExpectedSpanLatch(2);
  final TServerTransport serverTransport = new TServerSocket(port);
  final TServer server = startNewThreadPoolServer(serverTransport);

  final TTransport transport = new TSocket("localhost", port);
  transport.open();

  final TProtocol protocol = new TBinaryProtocol(transport);

  final CustomService.Client client = new CustomService.Client(protocol);
  final String res = client.say("one", "two");
  if (!"Say one two".equals(res))
    throw new AssertionError("ERROR: wrong result");

  TestUtil.checkSpan(latch, new ComponentSpanCount("java-thrift", 2, true));

  server.stop();
  transport.close();
}
 
Example #4
Source File: ThriftServerApplication.java    From spring-boot-demo with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    SpringApplication.run(ThriftServerApplication.class, args);

    try {
        System.out.println("服务端开启....");
        TProcessor tprocessor = new Hello.Processor<Hello.Iface>(new HelloServiceImpl());
        // 简单的单线程服务模型
        TServerSocket serverTransport = new TServerSocket(9898);
        TServer.Args tArgs = new TServer.Args(serverTransport);
        tArgs.processor(tprocessor);
        tArgs.protocolFactory(new TBinaryProtocol.Factory());
        TServer server = new TSimpleServer(tArgs);
        server.serve();
    } catch (TTransportException e) {
        e.printStackTrace();
    }
}
 
Example #5
Source File: SimpleTransportPlugin.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #6
Source File: HelloServerConfig.java    From jigsaw-payment with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #7
Source File: DKSearchService.java    From dk-fitting with Apache License 2.0 6 votes vote down vote up
/**
 *  线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。
 */
public void startTThreadPoolServer() {
    try {
        System.out.println("UserInfoServiceDemo TThreadPoolServer start ....");
        TMultiplexedProcessor processor = new TMultiplexedProcessor();
        processor.registerProcessor( "DKSearchOutput",new DKSearchOutput.Processor<DKSearchOutput.Iface>( new DKSearchOutputImpl() ) );
        processor.registerProcessor( "DKSearchInput",new DKSearchInput.Processor<DKSearchInput.Iface>(new DKSearchInputImpl()  ) );
        processor.registerProcessor( "DKSearchService",new SearchService.Processor<SearchService.Iface>(new SearchServiceImpl() ) );
        //TProcessor tprocessor = new UserInfoService.Processor<UserInfoService.Iface>(new UserInfoServiceImpl());
        TServerSocket serverTransport = new TServerSocket( Integer.valueOf(prop.get("dkSearch.port")));
        TThreadPoolServer.Args ttpsArgs = new TThreadPoolServer.Args(serverTransport);
        ttpsArgs.processor(processor);
        ttpsArgs.protocolFactory(new TBinaryProtocol.Factory());
        // 线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。
        TServer server = new TThreadPoolServer(ttpsArgs);
        server.serve();
    } catch (Exception e) {
        System.out.println("Server start error!!!");
        e.printStackTrace();

    }

}
 
Example #8
Source File: DKSearchService.java    From dk-fitting with Apache License 2.0 6 votes vote down vote up
/**
 *
 * 简单的单线程模式
 *
 */
public  void  startService(){
    System.out.println( " start ...." );
    //单接口声明
    //TProcessor tProcessor=new DKSearchOutput.Processor<DKSearchOutput.Iface>( new DKSearchOutputImpl() );
    //多接口声明
    TMultiplexedProcessor processor = new TMultiplexedProcessor();
    processor.registerProcessor( "DKSearchOutput",new DKSearchOutput.Processor<DKSearchOutput.Iface>( new DKSearchOutputImpl() ) );
    processor.registerProcessor( "DKSearchInput",new DKSearchInput.Processor<DKSearchInput.Iface>(new DKSearchInputImpl()  ) );
    processor.registerProcessor( "DKSearchService",new SearchService.Processor<SearchService.Iface>(new SearchServiceImpl() ) );
    try {
        TServerSocket serverSocket=new TServerSocket( Integer.valueOf(prop.get("dkSearch.port")) );
        TServer.Args targs=new TServer.Args( serverSocket );
        targs.processor( processor );
        //二进制TBinaryProtocol
        //二进制高密度TCompactProtocol
        targs.protocolFactory( new TCompactProtocol.Factory(  ) );
        TServer tServer=new TSimpleServer( targs );
        tServer.serve();
    } catch (TTransportException e) {
        System.err.println("Service Start error");
        e.printStackTrace();
    }
}
 
Example #9
Source File: ThriftITest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
private static TServer startNewThreadPoolServer(final TServerTransport transport) {
  final TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();

  final CustomHandler customHandler = new CustomHandler();
  final CustomService.Processor<CustomService.Iface> customProcessor = new CustomService.Processor<CustomService.Iface>(customHandler);

  final TThreadPoolServer.Args args = new TThreadPoolServer
    .Args(transport)
    .processorFactory(new TProcessorFactory(customProcessor))
    .protocolFactory(protocolFactory)
    .minWorkerThreads(5)
    .maxWorkerThreads(10);

  final TServer server = new TThreadPoolServer(args);
  new Thread(new Runnable() {
    @Override
    public void run() {
      server.serve();
    }
  }).start();

  return server;
}
 
Example #10
Source File: HiveTableBaseTest.java    From iceberg with Apache License 2.0 6 votes vote down vote up
private TServer thriftServer() throws IOException,
        TTransportException,
        MetaException,
        InvocationTargetException,
        NoSuchMethodException,
        IllegalAccessException,
        NoSuchFieldException {
  final TServerSocketKeepAlive socket = new TServerSocketKeepAlive(new TServerSocket(0));
  this.hiveConf = hiveConf(new Configuration(), socket.getServerSocket().getLocalPort());
  HiveMetaStore.HMSHandler baseHandler = new HiveMetaStore.HMSHandler("new db based metaserver", hiveConf);
  IHMSHandler handler = RetryingHMSHandler.getProxy(hiveConf, baseHandler, true);
  final TTransportFactory transportFactory = new TTransportFactory();
  final TSetIpAddressProcessor<IHMSHandler> processor = new TSetIpAddressProcessor<>(handler);

  TThreadPoolServer.Args args = new TThreadPoolServer.Args(socket)
          .processor(processor)
          .transportFactory(transportFactory)
          .protocolFactory(new TBinaryProtocol.Factory())
          .minWorkerThreads(3)
          .maxWorkerThreads(5);

  return new TThreadPoolServer(args);
}
 
Example #11
Source File: MetaStoreProxyServer.java    From waggle-dance with Apache License 2.0 6 votes vote down vote up
private void signalOtherThreadsToStart(
    final TServer server,
    final Lock startLock,
    final Condition startCondition,
    final AtomicBoolean startedServing) {
  // A simple thread to wait until the server has started and then signal the other threads to
  // begin
  Thread t = new Thread(() -> {
    do {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        LOG.warn("Signalling thread was interuppted: " + e.getMessage());
      }
    } while (!server.isServing());
    startLock.lock();
    try {
      startedServing.set(true);
      startCondition.signalAll();
    } finally {
      startLock.unlock();
    }
  });
  t.start();
}
 
Example #12
Source File: ThriftServerTest.java    From ThriftJ with Apache License 2.0 6 votes vote down vote up
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");
				}
			}
		});
	}
}
 
Example #13
Source File: DKMLServer.java    From dk-fitting with Apache License 2.0 6 votes vote down vote up
/**
 * 阻塞式、多线程处理
 *
 * @param args
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
    try {
        int port = Integer.valueOf(prop.get("dkml.port"));
        //设置传输通道,普通通道
        TServerTransport serverTransport = new TServerSocket(port);
        //使用高密度二进制协议
        TProtocolFactory proFactory = new TCompactProtocol.Factory();
        //设置处理器
        TProcessor processor = new DKML.Processor(new DKMLImpl());
        //创建服务器
        TServer server = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport)
                        .protocolFactory(proFactory)
                        .processor(processor)
        );

        System.out.println("Start server on port "+ port +"...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #14
Source File: ThriftServer.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected TServer getTThreadPoolServer(TProtocolFactory protocolFactory, TProcessor processor,
    TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws Exception {
  LOG.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
  // Thrift's implementation uses '0' as a placeholder for 'use the default.'
  int backlog = conf.getInt(BACKLOG_CONF_KEY, BACKLOG_CONF_DEAFULT);
  int readTimeout = conf.getInt(THRIFT_SERVER_SOCKET_READ_TIMEOUT_KEY,
      THRIFT_SERVER_SOCKET_READ_TIMEOUT_DEFAULT);
  TServerTransport serverTransport = new TServerSocket(
      new TServerSocket.ServerSocketTransportArgs().
          bindAddr(inetSocketAddress).backlog(backlog).
          clientTimeout(readTimeout));

  TBoundedThreadPoolServer.Args serverArgs =
      new TBoundedThreadPoolServer.Args(serverTransport, conf);
  serverArgs.processor(processor).transportFactory(transportFactory)
      .protocolFactory(protocolFactory);
  return new TBoundedThreadPoolServer(serverArgs, metrics);
}
 
Example #15
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 #16
Source File: ThriftServer.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected TServer getTHsHaServer(TNonblockingServerTransport serverTransport,
    TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory,
    InetSocketAddress inetSocketAddress) {
  LOG.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString());
  THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);
  int queueSize = conf.getInt(TBoundedThreadPoolServer.MAX_QUEUED_REQUESTS_CONF_KEY,
      TBoundedThreadPoolServer.DEFAULT_MAX_QUEUED_REQUESTS);
  CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(queueSize), metrics);
  int workerThread = conf.getInt(TBoundedThreadPoolServer.MAX_WORKER_THREADS_CONF_KEY,
      serverArgs.getMaxWorkerThreads());
  ExecutorService executorService = createExecutor(
      callQueue, workerThread, workerThread);
  serverArgs.executorService(executorService).processor(processor)
      .transportFactory(transportFactory).protocolFactory(protocolFactory);
  return new THsHaServer(serverArgs);
}
 
Example #17
Source File: GfxdThriftServer.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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();
    }
  }
}
 
Example #18
Source File: CustomTNonBlockingServer.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #19
Source File: GfxdThriftServer.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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();
    }
  }
}
 
Example #20
Source File: ThriftQueueServer.java    From bigqueue with Apache License 2.0 6 votes vote down vote up
public void start() {
	try {
		System.out.println("Thrift queue server start ...");
		
		BigQueueService.Iface bigQueueSerivce = new ThriftQueueServiceImpl(QUEUE_DIR);
		TProcessor tprocessor = new BigQueueService.Processor(bigQueueSerivce);
		
		TNonblockingServerSocket tnbSocketTransport = new TNonblockingServerSocket(SERVER_PORT);
		TNonblockingServer.Args tnbArgs = new TNonblockingServer.Args(tnbSocketTransport);
		tnbArgs.processor(tprocessor);
		// Nonblocking server mode needs TFramedTransport
		tnbArgs.transportFactory(new TFramedTransport.Factory());
		tnbArgs.protocolFactory(new TBinaryProtocol.Factory());
		
		TServer server = new TNonblockingServer(tnbArgs);
		System.out.println("Thrift queue server started on port " + SERVER_PORT);
		server.serve();
	} catch (Exception e) {
		System.err.println("Server start error!!!");
		e.printStackTrace();
	}
}
 
Example #21
Source File: ThriftServerTest2.java    From ThriftJ with Apache License 2.0 6 votes vote down vote up
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");
				}
			}
		});
	}
}
 
Example #22
Source File: FactoryServer.java    From ThriftBook with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws TTransportException {
  TServerSocket trans_svr = new TServerSocket(9090);
  TProcessor proc = new Message.Processor<>(new MessageHandler());
  
  TServer server = new TThreadPoolServer(
          new TThreadPoolServer.Args(trans_svr)
            .processor(proc)
            .protocolFactory(new TJSONProtocol.Factory())
            .inputTransportFactory(new TFramedTransport.Factory())
            .outputTransportFactory(new TWritelogTransportFactory(100)));
  server.serve();
}
 
Example #23
Source File: TServerCustomFactory.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public TServer buildTServer(TServerFactory.Args args)
{
    TServer server;
    if (ThriftServer.SYNC.equalsIgnoreCase(serverType))
    {
        server = new CustomTThreadPoolServer.Factory().buildTServer(args);
    }
    else if(ThriftServer.ASYNC.equalsIgnoreCase(serverType))
    {
        server = new CustomTNonBlockingServer.Factory().buildTServer(args);
        logger.info(String.format("Using non-blocking/asynchronous thrift server on %s : %s", args.addr.getHostName(), args.addr.getPort()));
    }
    else if(ThriftServer.HSHA.equalsIgnoreCase(serverType))
    {
        server = new THsHaDisruptorServer.Factory().buildTServer(args);
        logger.info(String.format("Using custom half-sync/half-async thrift server on %s : %s", args.addr.getHostName(), args.addr.getPort()));
    }
    else
    {
        TServerFactory serverFactory;
        try
        {
            serverFactory = (TServerFactory) Class.forName(serverType).newInstance();
        }
        catch (Exception e)
        {
            throw new RuntimeException("Failed to instantiate server factory:" + serverType, e);
        }
        server = serverFactory.buildTServer(args);
        logger.info(String.format("Using custom thrift server %s on %s : %s", server.getClass().getName(), args.addr.getHostName(), args.addr.getPort()));
    }
    return server;
}
 
Example #24
Source File: THsHaDisruptorServer.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public TServer buildTServer(Args args)
{
    if (DatabaseDescriptor.getClientEncryptionOptions().enabled)
        throw new RuntimeException("Client SSL is not supported for non-blocking sockets (hsha). 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);
    }

    ThreadPoolExecutor invoker = new JMXEnabledThreadPoolExecutor(DatabaseDescriptor.getRpcMinThreads(),
                                                                  DatabaseDescriptor.getRpcMaxThreads(),
                                                                  60L,
                                                                  TimeUnit.SECONDS,
                                                                  new SynchronousQueue<Runnable>(),
                                                                  new NamedThreadFactory("RPC-Thread"), "RPC-THREAD-POOL");

    com.thinkaurelius.thrift.util.TBinaryProtocol.Factory protocolFactory = new com.thinkaurelius.thrift.util.TBinaryProtocol.Factory(true, true);

    TDisruptorServer.Args serverArgs = new TDisruptorServer.Args(serverTransport).useHeapBasedAllocation(true)
                                                                                 .inputTransportFactory(args.inTransportFactory)
                                                                                 .outputTransportFactory(args.outTransportFactory)
                                                                                 .inputProtocolFactory(protocolFactory)
                                                                                 .outputProtocolFactory(protocolFactory)
                                                                                 .processor(args.processor)
                                                                                 .maxFrameSizeInBytes(DatabaseDescriptor.getThriftFramedTransportSize())
                                                                                 .invocationExecutor(invoker)
                                                                                 .alwaysReallocateBuffers(true);

    return new THsHaDisruptorServer(serverArgs);
}
 
Example #25
Source File: PacketStreamerServer.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
/** 
 * 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();
    }
}
 
Example #26
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 #27
Source File: DKGraphxServer.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
/**
 * 阻塞式、多线程处理
 *
 * @param args
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
    try {
        int port = Integer.valueOf(prop.get("dkgraphx.port"));
        //设置传输通道,普通通道
        TServerTransport serverTransport = new TServerSocket(port);

        //使用高密度二进制协议
        TProtocolFactory proFactory = new TCompactProtocol.Factory();

        //设置处理器
        TProcessor processor = new DKGraphx.Processor(new DKGraphxImpl());

        //创建服务器
        TServer server = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport)
                        .protocolFactory(proFactory)
                        .processor(processor)
        );

        System.out.println("Start server on port "+ port +"...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #28
Source File: ThriftServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected TServer getTNonBlockingServer(TNonblockingServerTransport serverTransport,
    TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory,
    InetSocketAddress inetSocketAddress) {
  LOG.info("starting HBase Nonblocking Thrift server on " + inetSocketAddress.toString());
  TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport);
  serverArgs.processor(processor);
  serverArgs.transportFactory(transportFactory);
  serverArgs.protocolFactory(protocolFactory);
  return new TNonblockingServer(serverArgs);
}
 
Example #29
Source File: AMServer.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public void simple(JstormAM.Processor processor) {
    try {
        TServerTransport serverTransport = new TServerSocket(port);
        TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
        LOG.info("Starting the simple server...");

        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #30
Source File: HelloServer.java    From ThriftBook with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws TTransportException {
    TServerSocket trans_svr = new TServerSocket(9090);
    TProcessor proc = new helloSvc.Processor<>(new MessageHandler());
    TServer server =
            new TSimpleServer(
                    new TSimpleServer.Args(trans_svr)
                            .processor(proc)
            );
    System.out.println("[Server] waiting for connections");
    server.serve();
}