ScopedServerInterfaceThread::ScopedServerInterfaceThread(
    shared_ptr<AsyncProcessorFactory> apf,
    const string& host,
    uint16_t port) {
  auto tm = ThreadManager::newSimpleThreadManager(1, 5, false, 50);
  tm->threadFactory(make_shared<PosixThreadFactory>());
  tm->start();
  auto ts = make_shared<ThriftServer>();
  ts->setAddress(host, port);
  ts->setProcessorFactory(move(apf));
  ts->setNWorkerThreads(1);
  ts->setThreadManager(tm);
  ts_ = move(ts);
  sst_.start(ts_);
}
Ejemplo n.º 2
0
void ExtensionRunnerCore::startServer(TProcessorRef processor) {
  auto transport = TServerTransportRef(new TServerSocket(path_));
  // Before starting and after stopping the manager, remove stale sockets.
  removeStalePaths(path_);

  auto transport_fac = TTransportFactoryRef(new TBufferedTransportFactory());
  auto protocol_fac = TProtocolFactoryRef(new TBinaryProtocolFactory());

  // The minimum number of worker threads is 1.
  size_t threads = (FLAGS_worker_threads > 0) ? FLAGS_worker_threads : 1;
  auto thread_manager_ = ThreadManager::newSimpleThreadManager(threads, 0);
  auto thread_fac = ThriftThreadFactory(new PosixThreadFactory());
  thread_manager_->threadFactory(thread_fac);
  thread_manager_->start();

  // Start the Thrift server's run loop.
  server_ = TThreadPoolServerRef(new TThreadPoolServer(
      processor, transport, transport_fac, protocol_fac, thread_manager_));
  server_->serve();
}