Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook |
| 2 | // Distributed under the Thrift Software License |
| 3 | // |
| 4 | // See accompanying file LICENSE or visit the Thrift site at: |
| 5 | // http://developers.facebook.com/thrift/ |
| 6 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 7 | #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ |
| 8 | #define _THRIFT_SERVER_TTHREADPOOLSERVER_H_ 1 |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 9 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 10 | #include <concurrency/ThreadManager.h> |
| 11 | #include <server/TServer.h> |
| 12 | #include <transport/TServerTransport.h> |
| 13 | |
| 14 | #include <boost/shared_ptr.hpp> |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 15 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 16 | namespace apache { namespace thrift { namespace server { |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 17 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 18 | using apache::thrift::concurrency::ThreadManager; |
| 19 | using apache::thrift::protocol::TProtocolFactory; |
| 20 | using apache::thrift::transport::TServerTransport; |
| 21 | using apache::thrift::transport::TTransportFactory; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 22 | |
| 23 | class TThreadPoolServer : public TServer { |
Mark Slee | b3cb629 | 2007-02-01 22:55:00 +0000 | [diff] [blame] | 24 | public: |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 25 | class Task; |
Mark Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 26 | |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 27 | TThreadPoolServer(boost::shared_ptr<TProcessor> processor, |
| 28 | boost::shared_ptr<TServerTransport> serverTransport, |
| 29 | boost::shared_ptr<TTransportFactory> transportFactory, |
| 30 | boost::shared_ptr<TProtocolFactory> protocolFactory, |
| 31 | boost::shared_ptr<ThreadManager> threadManager); |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 32 | |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 33 | TThreadPoolServer(boost::shared_ptr<TProcessor> processor, |
| 34 | boost::shared_ptr<TServerTransport> serverTransport, |
| 35 | boost::shared_ptr<TTransportFactory> inputTransportFactory, |
| 36 | boost::shared_ptr<TTransportFactory> outputTransportFactory, |
| 37 | boost::shared_ptr<TProtocolFactory> inputProtocolFactory, |
Mark Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 38 | boost::shared_ptr<TProtocolFactory> outputProtocolFactory, |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 39 | boost::shared_ptr<ThreadManager> threadManager); |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 40 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 41 | virtual ~TThreadPoolServer(); |
| 42 | |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 43 | virtual void serve(); |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 44 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 45 | virtual int64_t getTimeout() const; |
| 46 | |
| 47 | virtual void setTimeout(int64_t value); |
Mark Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 48 | |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 49 | virtual void stop() { |
| 50 | stop_ = true; |
| 51 | serverTransport_->interrupt(); |
| 52 | } |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 53 | |
Mark Slee | b3cb629 | 2007-02-01 22:55:00 +0000 | [diff] [blame] | 54 | protected: |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 55 | |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 56 | boost::shared_ptr<ThreadManager> threadManager_; |
Mark Slee | 6e3f637 | 2007-03-01 22:05:46 +0000 | [diff] [blame] | 57 | |
| 58 | volatile bool stop_; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 59 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 60 | volatile int64_t timeout_; |
Mark Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 61 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 64 | }}} // apache::thrift::server |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 65 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 66 | #endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ |