David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 19 | |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 20 | #include <thrift/server/TThreadPoolServer.h> |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 21 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 22 | namespace apache { |
| 23 | namespace thrift { |
| 24 | namespace server { |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 25 | |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 26 | using apache::thrift::concurrency::ThreadManager; |
| 27 | using apache::thrift::protocol::TProtocol; |
| 28 | using apache::thrift::protocol::TProtocolFactory; |
| 29 | using apache::thrift::transport::TServerTransport; |
| 30 | using apache::thrift::transport::TTransport; |
| 31 | using apache::thrift::transport::TTransportException; |
| 32 | using apache::thrift::transport::TTransportFactory; |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 33 | using stdcxx::shared_ptr; |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 34 | using std::string; |
| 35 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 36 | TThreadPoolServer::TThreadPoolServer(const shared_ptr<TProcessorFactory>& processorFactory, |
| 37 | const shared_ptr<TServerTransport>& serverTransport, |
| 38 | const shared_ptr<TTransportFactory>& transportFactory, |
| 39 | const shared_ptr<TProtocolFactory>& protocolFactory, |
| 40 | const shared_ptr<ThreadManager>& threadManager) |
| 41 | : TServerFramework(processorFactory, serverTransport, transportFactory, protocolFactory), |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 42 | threadManager_(threadManager), |
| 43 | timeout_(0), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 44 | taskExpiration_(0) { |
| 45 | } |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 46 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 47 | TThreadPoolServer::TThreadPoolServer(const shared_ptr<TProcessor>& processor, |
| 48 | const shared_ptr<TServerTransport>& serverTransport, |
| 49 | const shared_ptr<TTransportFactory>& transportFactory, |
| 50 | const shared_ptr<TProtocolFactory>& protocolFactory, |
| 51 | const shared_ptr<ThreadManager>& threadManager) |
| 52 | : TServerFramework(processor, serverTransport, transportFactory, protocolFactory), |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 53 | threadManager_(threadManager), |
| 54 | timeout_(0), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 55 | taskExpiration_(0) { |
| 56 | } |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 57 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 58 | TThreadPoolServer::TThreadPoolServer(const shared_ptr<TProcessorFactory>& processorFactory, |
| 59 | const shared_ptr<TServerTransport>& serverTransport, |
| 60 | const shared_ptr<TTransportFactory>& inputTransportFactory, |
| 61 | const shared_ptr<TTransportFactory>& outputTransportFactory, |
| 62 | const shared_ptr<TProtocolFactory>& inputProtocolFactory, |
| 63 | const shared_ptr<TProtocolFactory>& outputProtocolFactory, |
| 64 | const shared_ptr<ThreadManager>& threadManager) |
| 65 | : TServerFramework(processorFactory, |
| 66 | serverTransport, |
| 67 | inputTransportFactory, |
| 68 | outputTransportFactory, |
| 69 | inputProtocolFactory, |
| 70 | outputProtocolFactory), |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 71 | threadManager_(threadManager), |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 72 | timeout_(0), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 73 | taskExpiration_(0) { |
| 74 | } |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 75 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 76 | TThreadPoolServer::TThreadPoolServer(const shared_ptr<TProcessor>& processor, |
| 77 | const shared_ptr<TServerTransport>& serverTransport, |
| 78 | const shared_ptr<TTransportFactory>& inputTransportFactory, |
| 79 | const shared_ptr<TTransportFactory>& outputTransportFactory, |
| 80 | const shared_ptr<TProtocolFactory>& inputProtocolFactory, |
| 81 | const shared_ptr<TProtocolFactory>& outputProtocolFactory, |
| 82 | const shared_ptr<ThreadManager>& threadManager) |
| 83 | : TServerFramework(processor, |
| 84 | serverTransport, |
| 85 | inputTransportFactory, |
| 86 | outputTransportFactory, |
| 87 | inputProtocolFactory, |
| 88 | outputProtocolFactory), |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 89 | threadManager_(threadManager), |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 90 | timeout_(0), |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 91 | taskExpiration_(0) { |
| 92 | } |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 93 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 94 | TThreadPoolServer::~TThreadPoolServer() { |
| 95 | } |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 96 | |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 97 | void TThreadPoolServer::serve() { |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 98 | TServerFramework::serve(); |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 99 | threadManager_->stop(); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 100 | } |
| 101 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 102 | int64_t TThreadPoolServer::getTimeout() const { |
| 103 | return timeout_; |
| 104 | } |
| 105 | |
| 106 | void TThreadPoolServer::setTimeout(int64_t value) { |
| 107 | timeout_ = value; |
| 108 | } |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 109 | |
Roger Meier | 5ed5e8b | 2013-05-06 00:21:04 +0200 | [diff] [blame] | 110 | int64_t TThreadPoolServer::getTaskExpiration() const { |
| 111 | return taskExpiration_; |
| 112 | } |
| 113 | |
| 114 | void TThreadPoolServer::setTaskExpiration(int64_t value) { |
| 115 | taskExpiration_ = value; |
| 116 | } |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 117 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 118 | stdcxx::shared_ptr<apache::thrift::concurrency::ThreadManager> |
Jim King | 5871d2c | 2016-04-05 13:00:24 -0400 | [diff] [blame] | 119 | TThreadPoolServer::getThreadManager() const { |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 120 | return threadManager_; |
| 121 | } |
| 122 | |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 123 | void TThreadPoolServer::onClientConnected(const shared_ptr<TConnectedClient>& pClient) { |
Jim King | 5871d2c | 2016-04-05 13:00:24 -0400 | [diff] [blame] | 124 | threadManager_->add(pClient, getTimeout(), getTaskExpiration()); |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 127 | void TThreadPoolServer::onClientDisconnected(TConnectedClient*) { |
| 128 | } |
Jim King | 5871d2c | 2016-04-05 13:00:24 -0400 | [diff] [blame] | 129 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | } // apache::thrift::server |