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 | |
| 16 | namespace facebook { namespace thrift { namespace server { |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace facebook::thrift::concurrency; |
| 19 | using namespace facebook::thrift::transport; |
| 20 | using namespace boost; |
| 21 | |
| 22 | class TThreadPoolServer : public TServer { |
Mark Slee | b3cb629 | 2007-02-01 22:55:00 +0000 | [diff] [blame] | 23 | public: |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 24 | class Task; |
| 25 | |
| 26 | TThreadPoolServer(shared_ptr<TProcessor> processor, |
Martin Kraemer | 5091917 | 2007-01-26 01:41:03 +0000 | [diff] [blame] | 27 | shared_ptr<TServerTransport> serverTransport, |
| 28 | shared_ptr<TTransportFactory> transportFactory, |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 29 | shared_ptr<TProtocolFactory> protocolFactory, |
Martin Kraemer | 5091917 | 2007-01-26 01:41:03 +0000 | [diff] [blame] | 30 | shared_ptr<ThreadManager> threadManager); |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 31 | |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 32 | TThreadPoolServer(shared_ptr<TProcessor> processor, |
Martin Kraemer | 5091917 | 2007-01-26 01:41:03 +0000 | [diff] [blame] | 33 | shared_ptr<TServerTransport> serverTransport, |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 34 | shared_ptr<TTransportFactory> inputTransportFactory, |
| 35 | shared_ptr<TTransportFactory> outputTransportFactory, |
| 36 | shared_ptr<TProtocolFactory> inputProtocolFactory, |
| 37 | shared_ptr<TProtocolFactory> outputProtocolFactory, |
Martin Kraemer | 5091917 | 2007-01-26 01:41:03 +0000 | [diff] [blame] | 38 | shared_ptr<ThreadManager> threadManager); |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 39 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 40 | virtual ~TThreadPoolServer(); |
| 41 | |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 42 | virtual void serve(); |
Mark Slee | 6e3f637 | 2007-03-01 22:05:46 +0000 | [diff] [blame] | 43 | |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 44 | virtual void stop() { |
| 45 | stop_ = true; |
| 46 | serverTransport_->interrupt(); |
| 47 | } |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 48 | |
Mark Slee | b3cb629 | 2007-02-01 22:55:00 +0000 | [diff] [blame] | 49 | protected: |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 50 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 51 | shared_ptr<ThreadManager> threadManager_; |
Mark Slee | 6e3f637 | 2007-03-01 22:05:46 +0000 | [diff] [blame] | 52 | |
| 53 | volatile bool stop_; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 54 | |
| 55 | }; |
| 56 | |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 57 | }}} // facebook::thrift::server |
| 58 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 59 | #endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ |