org.apache.thrift.transport.TNonblockingServerTransport Java Examples

The following examples show how to use org.apache.thrift.transport.TNonblockingServerTransport. 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: TThreadedSelectorServerWithFix.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
/**
 * Start the accept and selector threads running to deal with clients.
 *
 * @return true if everything went ok, false if we couldn't start for some
 *         reason.
 */
@Override
protected boolean startThreads() {
  LOGGER.info("Starting {}", TThreadedSelectorServerWithFix.class.getSimpleName());
  try {
    for (int i = 0; i < args.selectorThreads; ++i) {
      selectorThreads.add(new SelectorThread(args.acceptQueueSizePerThread));
    }
    acceptThread = new AcceptThread((TNonblockingServerTransport) serverTransport_,
                                    createSelectorThreadLoadBalancer(selectorThreads));
    stopped_ = false;
    for (SelectorThread thread : selectorThreads) {
      thread.start();
    }
    acceptThread.start();
    return true;
  } catch (IOException e) {
    LOGGER.error("Failed to start threads!", e);
    return false;
  }
}
 
Example #2
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 #3
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 #4
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 #5
Source File: ScribeSource.java    From mt-flume with Apache License 2.0 6 votes vote down vote up
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());
    args.protocolFactory(new TBinaryProtocol.Factory(false, false));

    server = new THsHaServer(args);

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

    server.serve();
  } catch (Exception e) {
    LOG.warn("Scribe failed", e);
  }
}
 
Example #6
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 #7
Source File: TThreadedSelectorServerWithFix.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Set up the AcceptThead
 *
 * @throws IOException
 */
public AcceptThread(TNonblockingServerTransport serverTransport,
                    SelectorThreadLoadBalancer threadChooser) throws IOException {
  this.serverTransport = serverTransport;
  this.threadChooser = threadChooser;
  this.acceptSelector = SelectorProvider.provider().openSelector();
  this.serverTransport.registerSelector(acceptSelector);
}
 
Example #8
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 #9
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 #10
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 #11
Source File: ThriftTestingSource.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
public ThriftTestingSource(String handlerName, int port) throws Exception {
  TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(new
    InetSocketAddress("0.0.0.0", port));
  ThriftSourceProtocol.Iface handler = null;
  if (handlerName.equals(HandlerType.OK.name())) {
    handler = new ThriftOKHandler();
  } else if (handlerName.equals(HandlerType.FAIL.name())) {
    handler = new ThriftFailHandler();
  } else if (handlerName.equals(HandlerType.ERROR.name())) {
    handler = new ThriftErrorHandler();
  } else if (handlerName.equals(HandlerType.SLOW.name())) {
    handler = new ThriftSlowHandler();
  } else if (handlerName.equals(HandlerType.TIMEOUT.name())) {
    handler = new ThriftTimeoutHandler();
  } else if (handlerName.equals(HandlerType.ALTERNATE.name())) {
    handler = new ThriftAlternateHandler();
  }

  server = new THsHaServer(new THsHaServer.Args
    (serverTransport).processor(
    new ThriftSourceProtocol.Processor(handler)).protocolFactory(
    new TCompactProtocol.Factory()));
  Executors.newSingleThreadExecutor().submit(new Runnable() {
    @Override
    public void run() {
      server.serve();
    }
  });
}
 
Example #12
Source File: TThreadedSelectorServerWithFix.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
public Args(TNonblockingServerTransport transport) {
  super(transport);
}
 
Example #13
Source File: HThreadedSelectorServerArgs.java    From hbase with Apache License 2.0 4 votes vote down vote up
public HThreadedSelectorServerArgs(
    TNonblockingServerTransport transport, Configuration conf) {
  super(transport);
  readConf(conf);
}
 
Example #14
Source File: TDisruptorServer.java    From disruptor_thrift_server with Apache License 2.0 4 votes vote down vote up
public Args(TNonblockingServerTransport transport)
{
    super(transport);
}
 
Example #15
Source File: TDisruptorServer.java    From disruptor_thrift_server with Apache License 2.0 4 votes vote down vote up
/**
 * Set up the thread that will handle the non-blocking accepts.
 */
public AcceptorThread(String name, TNonblockingServerTransport serverTransport) throws IOException {
    super(name);
    this.serverTransport = serverTransport;
    this.serverTransport.registerSelector(selector); // registers with OP_ACCEPT interests
}