Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1 | #ifndef _THRIFT_SERVER_TSERVER_H_ |
| 2 | #define _THRIFT_SERVER_TSERVER_H_ 1 |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 3 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 4 | #include <TProcessor.h> |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 5 | #include <transport/TServerTransport.h> |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 6 | #include <protocol/TBinaryProtocol.h> |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 7 | #include <concurrency/Thread.h> |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 8 | |
| 9 | #include <boost/shared_ptr.hpp> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 10 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 11 | namespace facebook { namespace thrift { namespace server { |
| 12 | |
| 13 | using namespace facebook::thrift; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 14 | using namespace facebook::thrift::transport; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 15 | using namespace boost; |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 16 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 17 | /** |
| 18 | * Thrift server. |
| 19 | * |
| 20 | * @author Mark Slee <mcslee@facebook.com> |
| 21 | */ |
Aditya Agarwal | d622e96 | 2006-10-11 02:42:49 +0000 | [diff] [blame] | 22 | class TServer : public concurrency::Runnable { |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 23 | public: |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 24 | virtual ~TServer() {} |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 25 | |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 26 | virtual void serve() = 0; |
Aditya Agarwal | d622e96 | 2006-10-11 02:42:49 +0000 | [diff] [blame] | 27 | |
| 28 | // Allows running the server as a Runnable thread |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 29 | virtual void run() { |
| 30 | serve(); |
| 31 | } |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 32 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 33 | shared_ptr<TProcessor> getProcessor() { |
| 34 | return processor_; |
| 35 | } |
| 36 | |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 37 | shared_ptr<TProtocolFactory> getProtocolFactory() { |
| 38 | return protocolFactory_; |
| 39 | } |
| 40 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 41 | protected: |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 42 | TServer(shared_ptr<TProcessor> processor, |
| 43 | shared_ptr<TServerTransport> serverTransport, |
| 44 | shared_ptr<TTransportFactory> transportFactory, |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 45 | shared_ptr<TProtocolFactory> protocolFactory) : |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 46 | processor_(processor), |
| 47 | serverTransport_(serverTransport), |
| 48 | transportFactory_(transportFactory), |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 49 | protocolFactory_(protocolFactory) {} |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 50 | |
| 51 | TServer(shared_ptr<TProcessor> processor, |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 52 | shared_ptr<TServerTransport> serverTransport, |
| 53 | shared_ptr<TTransportFactory> transportFactory) : |
| 54 | processor_(processor), |
| 55 | serverTransport_(serverTransport), |
| 56 | transportFactory_(transportFactory) { |
| 57 | protocolFactory_ = boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()); |
| 58 | } |
| 59 | |
| 60 | TServer(shared_ptr<TProcessor> processor, |
| 61 | shared_ptr<TServerTransport> serverTransport) : |
| 62 | processor_(processor), |
| 63 | serverTransport_(serverTransport) { |
| 64 | transportFactory_ = boost::shared_ptr<TTransportFactory>(new TTransportFactory()); |
| 65 | protocolFactory_ = boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()); |
| 66 | } |
| 67 | |
| 68 | TServer(shared_ptr<TProcessor> processor) : |
| 69 | processor_(processor) { |
| 70 | transportFactory_ = boost::shared_ptr<TTransportFactory>(new TTransportFactory()); |
| 71 | protocolFactory_ = boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()); |
| 72 | } |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 73 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 74 | shared_ptr<TProcessor> processor_; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 75 | shared_ptr<TServerTransport> serverTransport_; |
| 76 | shared_ptr<TTransportFactory> transportFactory_; |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 77 | shared_ptr<TProtocolFactory> protocolFactory_; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 78 | }; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 79 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 80 | }}} // facebook::thrift::server |
| 81 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 82 | #endif // #ifndef _THRIFT_SERVER_TSERVER_H_ |