| 406 | } |
| 407 | |
| 408 | Status ThriftServer::Start() { |
| 409 | DCHECK(!started_); |
| 410 | std::shared_ptr<TProtocolFactory> protocol_factory(new TBinaryProtocolFactory()); |
| 411 | std::shared_ptr<ThreadFactory> thread_factory( |
| 412 | new ThriftThreadFactory("thrift-server", name_)); |
| 413 | |
| 414 | // Note - if you change the transport types here, you must check that the |
| 415 | // logic in createContext is still accurate. |
| 416 | std::shared_ptr<TServerSocket> server_socket; |
| 417 | std::shared_ptr<TTransportFactory> transport_factory; |
| 418 | RETURN_IF_ERROR(CreateSocket(&server_socket)); |
| 419 | RETURN_IF_ERROR(auth_provider_->GetServerTransportFactory( |
| 420 | transport_type_, metrics_name_, metrics_, &transport_factory)); |
| 421 | |
| 422 | server_.reset(new TAcceptQueueServer(processor_, server_socket, transport_factory, |
| 423 | protocol_factory, thread_factory, name_, max_concurrent_connections_, |
| 424 | queue_timeout_ms_, idle_poll_period_ms_, is_external_facing_)); |
| 425 | if (metrics_ != NULL) { |
| 426 | (static_cast<TAcceptQueueServer*>(server_.get())) |
| 427 | ->InitMetrics(metrics_, metrics_name_); |
| 428 | } |
| 429 | std::shared_ptr<ThriftServer::ThriftServerEventProcessor> event_processor( |
| 430 | new ThriftServer::ThriftServerEventProcessor(this)); |
| 431 | server_->setServerEventHandler(event_processor); |
| 432 | |
| 433 | RETURN_IF_ERROR(event_processor->StartAndWaitForServer()); |
| 434 | |
| 435 | // If port_ was 0, figure out which port the server is listening on after starting. |
| 436 | port_ = server_socket->getPort(); |
| 437 | LOG(INFO) << "ThriftServer '" << name_ << "' started on port: " << port_ |
| 438 | << (ssl_enabled() ? "s" : ""); |
| 439 | DCHECK(started_); |
| 440 | return Status::OK(); |
| 441 | } |
| 442 | |
| 443 | void ThriftServer::Join() { |
| 444 | DCHECK(server_thread_ != NULL); |