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 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 20 | #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ |
| 21 | #define _THRIFT_SERVER_TTHREADPOOLSERVER_H_ 1 |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 22 | |
cyy | 7f8aef7 | 2019-01-06 10:05:50 +0800 | [diff] [blame^] | 23 | #include <atomic> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 24 | #include <thrift/concurrency/ThreadManager.h> |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 25 | #include <thrift/server/TServerFramework.h> |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 26 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 27 | namespace apache { |
| 28 | namespace thrift { |
| 29 | namespace server { |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 30 | |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 31 | /** |
| 32 | * Manage clients using a thread pool. |
| 33 | */ |
| 34 | class TThreadPoolServer : public TServerFramework { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 35 | public: |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 36 | TThreadPoolServer( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 37 | const std::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory, |
| 38 | const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, |
| 39 | const std::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory, |
| 40 | const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory, |
| 41 | const std::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 42 | = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 43 | |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 44 | TThreadPoolServer( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 45 | const std::shared_ptr<apache::thrift::TProcessor>& processor, |
| 46 | const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, |
| 47 | const std::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory, |
| 48 | const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory, |
| 49 | const std::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 50 | = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); |
Bryan Duxbury | 7a9fb81 | 2011-09-01 18:31:53 +0000 | [diff] [blame] | 51 | |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 52 | TThreadPoolServer( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 53 | const std::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory, |
| 54 | const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, |
| 55 | const std::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory, |
| 56 | const std::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory, |
| 57 | const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory, |
| 58 | const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory, |
| 59 | const std::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 60 | = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); |
Bryan Duxbury | 7a9fb81 | 2011-09-01 18:31:53 +0000 | [diff] [blame] | 61 | |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 62 | TThreadPoolServer( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 63 | const std::shared_ptr<apache::thrift::TProcessor>& processor, |
| 64 | const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport, |
| 65 | const std::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory, |
| 66 | const std::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory, |
| 67 | const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory, |
| 68 | const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory, |
| 69 | const std::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 70 | = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager()); |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 71 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 72 | virtual ~TThreadPoolServer(); |
| 73 | |
Jim King | 5ec805b | 2015-04-26 07:52:40 -0400 | [diff] [blame] | 74 | /** |
Jim King | 5ec805b | 2015-04-26 07:52:40 -0400 | [diff] [blame] | 75 | * Post-conditions (return guarantees): |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 76 | * There will be no clients connected. |
Jim King | 5ec805b | 2015-04-26 07:52:40 -0400 | [diff] [blame] | 77 | */ |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 78 | virtual void serve(); |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 79 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 80 | virtual int64_t getTimeout() const; |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 81 | virtual void setTimeout(int64_t value); |
Mark Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 82 | |
Roger Meier | 5ed5e8b | 2013-05-06 00:21:04 +0200 | [diff] [blame] | 83 | virtual int64_t getTaskExpiration() const; |
Roger Meier | 5ed5e8b | 2013-05-06 00:21:04 +0200 | [diff] [blame] | 84 | virtual void setTaskExpiration(int64_t value); |
| 85 | |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 86 | virtual std::shared_ptr<apache::thrift::concurrency::ThreadManager> getThreadManager() const; |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 87 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 88 | protected: |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 89 | virtual void onClientConnected(const std::shared_ptr<TConnectedClient>& pClient) /* override */; |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 90 | virtual void onClientDisconnected(TConnectedClient* pClient) /* override */; |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 91 | |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 92 | std::shared_ptr<apache::thrift::concurrency::ThreadManager> threadManager_; |
cyy | 7f8aef7 | 2019-01-06 10:05:50 +0800 | [diff] [blame^] | 93 | std::atomic<int64_t> timeout_; |
| 94 | std::atomic<int64_t> taskExpiration_; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 95 | }; |
Jim King | 5871d2c | 2016-04-05 13:00:24 -0400 | [diff] [blame] | 96 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | } // apache::thrift::server |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 100 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 101 | #endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ |