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 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 23 | #include <concurrency/ThreadManager.h> |
| 24 | #include <server/TServer.h> |
| 25 | #include <transport/TServerTransport.h> |
| 26 | |
| 27 | #include <boost/shared_ptr.hpp> |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 28 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 29 | namespace apache { namespace thrift { namespace server { |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 30 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 31 | using apache::thrift::concurrency::ThreadManager; |
| 32 | using apache::thrift::protocol::TProtocolFactory; |
| 33 | using apache::thrift::transport::TServerTransport; |
| 34 | using apache::thrift::transport::TTransportFactory; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 35 | |
| 36 | class TThreadPoolServer : public TServer { |
Mark Slee | b3cb629 | 2007-02-01 22:55:00 +0000 | [diff] [blame] | 37 | public: |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 38 | class Task; |
Mark Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 39 | |
Bryan Duxbury | 7a9fb81 | 2011-09-01 18:31:53 +0000 | [diff] [blame] | 40 | template<typename ProcessorFactory> |
| 41 | TThreadPoolServer( |
| 42 | const boost::shared_ptr<ProcessorFactory>& processorFactory, |
| 43 | const boost::shared_ptr<TServerTransport>& serverTransport, |
| 44 | const boost::shared_ptr<TTransportFactory>& transportFactory, |
| 45 | const boost::shared_ptr<TProtocolFactory>& protocolFactory, |
| 46 | const boost::shared_ptr<ThreadManager>& threadManager, |
| 47 | THRIFT_OVERLOAD_IF(ProcessorFactory, TProtocolFactory)) : |
| 48 | TServer(processorFactory, serverTransport, transportFactory, |
| 49 | protocolFactory), |
| 50 | threadManager_(threadManager), |
| 51 | stop_(false), |
| 52 | timeout_(0) {} |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 53 | |
Bryan Duxbury | 7a9fb81 | 2011-09-01 18:31:53 +0000 | [diff] [blame] | 54 | template<typename Processor> |
| 55 | TThreadPoolServer( |
| 56 | const boost::shared_ptr<Processor>& processor, |
| 57 | const boost::shared_ptr<TServerTransport>& serverTransport, |
| 58 | const boost::shared_ptr<TTransportFactory>& transportFactory, |
| 59 | const boost::shared_ptr<TProtocolFactory>& protocolFactory, |
| 60 | const boost::shared_ptr<ThreadManager>& threadManager, |
| 61 | THRIFT_OVERLOAD_IF(Processor, TProcessor)) : |
| 62 | TServer(processor, serverTransport, transportFactory, protocolFactory), |
| 63 | threadManager_(threadManager), |
| 64 | stop_(false), |
| 65 | timeout_(0) {} |
| 66 | |
| 67 | template<typename ProcessorFactory> |
| 68 | TThreadPoolServer( |
| 69 | const boost::shared_ptr<ProcessorFactory>& processorFactory, |
| 70 | const boost::shared_ptr<TServerTransport>& serverTransport, |
| 71 | const boost::shared_ptr<TTransportFactory>& inputTransportFactory, |
| 72 | const boost::shared_ptr<TTransportFactory>& outputTransportFactory, |
| 73 | const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory, |
| 74 | const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory, |
| 75 | const boost::shared_ptr<ThreadManager>& threadManager, |
| 76 | THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)) : |
| 77 | TServer(processorFactory, serverTransport, |
| 78 | inputTransportFactory, outputTransportFactory, |
| 79 | inputProtocolFactory, outputProtocolFactory), |
| 80 | threadManager_(threadManager), |
| 81 | stop_(false), |
| 82 | timeout_(0) {} |
| 83 | |
| 84 | template<typename Processor> |
| 85 | TThreadPoolServer( |
| 86 | const boost::shared_ptr<Processor>& processor, |
| 87 | const boost::shared_ptr<TServerTransport>& serverTransport, |
| 88 | const boost::shared_ptr<TTransportFactory>& inputTransportFactory, |
| 89 | const boost::shared_ptr<TTransportFactory>& outputTransportFactory, |
| 90 | const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory, |
| 91 | const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory, |
| 92 | const boost::shared_ptr<ThreadManager>& threadManager, |
| 93 | THRIFT_OVERLOAD_IF(Processor, TProcessor)) : |
| 94 | TServer(processor, serverTransport, |
| 95 | inputTransportFactory, outputTransportFactory, |
| 96 | inputProtocolFactory, outputProtocolFactory), |
| 97 | threadManager_(threadManager), |
| 98 | stop_(false), |
| 99 | timeout_(0) {} |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 100 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 101 | virtual ~TThreadPoolServer(); |
| 102 | |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 103 | virtual void serve(); |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 104 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 105 | virtual int64_t getTimeout() const; |
| 106 | |
| 107 | virtual void setTimeout(int64_t value); |
Mark Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 108 | |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 109 | virtual void stop() { |
| 110 | stop_ = true; |
| 111 | serverTransport_->interrupt(); |
| 112 | } |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 113 | |
Mark Slee | b3cb629 | 2007-02-01 22:55:00 +0000 | [diff] [blame] | 114 | protected: |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 115 | |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 116 | boost::shared_ptr<ThreadManager> threadManager_; |
Mark Slee | 6e3f637 | 2007-03-01 22:05:46 +0000 | [diff] [blame] | 117 | |
| 118 | volatile bool stop_; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 119 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 120 | volatile int64_t timeout_; |
Mark Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 121 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 124 | }}} // apache::thrift::server |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 125 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 126 | #endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ |