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 | } |
Aditya Agarwal | 1ea9052 | 2007-01-19 02:02:12 +0000 | [diff] [blame] | 36 | |
| 37 | shared_ptr<TServerTransport> getServerTransport() { |
| 38 | return serverTransport_; |
| 39 | } |
| 40 | |
| 41 | shared_ptr<TTransportFactory> getTransportFactory() { |
| 42 | return transportFactory_; |
| 43 | } |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 44 | |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 45 | shared_ptr<TProtocolFactory> getProtocolFactory() { |
| 46 | return protocolFactory_; |
| 47 | } |
| 48 | |
Aditya Agarwal | 1ea9052 | 2007-01-19 02:02:12 +0000 | [diff] [blame] | 49 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 50 | protected: |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 51 | TServer(shared_ptr<TProcessor> processor, |
| 52 | shared_ptr<TServerTransport> serverTransport, |
| 53 | shared_ptr<TTransportFactory> transportFactory, |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 54 | shared_ptr<TProtocolFactory> protocolFactory) : |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 55 | processor_(processor), |
| 56 | serverTransport_(serverTransport), |
| 57 | transportFactory_(transportFactory), |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 58 | protocolFactory_(protocolFactory) {} |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 59 | |
| 60 | TServer(shared_ptr<TProcessor> processor, |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 61 | shared_ptr<TServerTransport> serverTransport, |
| 62 | shared_ptr<TTransportFactory> transportFactory) : |
| 63 | processor_(processor), |
| 64 | serverTransport_(serverTransport), |
| 65 | transportFactory_(transportFactory) { |
| 66 | protocolFactory_ = boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()); |
| 67 | } |
| 68 | |
| 69 | TServer(shared_ptr<TProcessor> processor, |
| 70 | shared_ptr<TServerTransport> serverTransport) : |
| 71 | processor_(processor), |
| 72 | serverTransport_(serverTransport) { |
| 73 | transportFactory_ = boost::shared_ptr<TTransportFactory>(new TTransportFactory()); |
| 74 | protocolFactory_ = boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()); |
| 75 | } |
| 76 | |
| 77 | TServer(shared_ptr<TProcessor> processor) : |
| 78 | processor_(processor) { |
| 79 | transportFactory_ = boost::shared_ptr<TTransportFactory>(new TTransportFactory()); |
| 80 | protocolFactory_ = boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()); |
| 81 | } |
Aditya Agarwal | 1ea9052 | 2007-01-19 02:02:12 +0000 | [diff] [blame] | 82 | |
| 83 | TServer(shared_ptr<TProcessor> processor, |
| 84 | shared_ptr<TTransportFactory> transportFactory) : |
| 85 | processor_(processor), |
| 86 | transportFactory_(transportFactory) { |
| 87 | protocolFactory_ = boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory()); |
| 88 | } |
| 89 | |
| 90 | TServer(shared_ptr<TProcessor> processor, |
| 91 | shared_ptr<TProtocolFactory> protocolFactory) : |
| 92 | processor_(processor) { |
| 93 | transportFactory_ = boost::shared_ptr<TTransportFactory>(new TTransportFactory()); |
| 94 | protocolFactory_ = protocolFactory; |
| 95 | } |
| 96 | |
| 97 | TServer(shared_ptr<TProcessor> processor, |
| 98 | shared_ptr<TProtocolFactory> protocolFactory, |
| 99 | shared_ptr<TTransportFactory> transportFactory): |
| 100 | processor_(processor), |
| 101 | transportFactory_(transportFactory), |
| 102 | protocolFactory_(protocolFactory) {} |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 103 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 104 | shared_ptr<TProcessor> processor_; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 105 | shared_ptr<TServerTransport> serverTransport_; |
| 106 | shared_ptr<TTransportFactory> transportFactory_; |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 107 | shared_ptr<TProtocolFactory> protocolFactory_; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 108 | }; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 109 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 110 | }}} // facebook::thrift::server |
| 111 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 112 | #endif // #ifndef _THRIFT_SERVER_TSERVER_H_ |