blob: 4b20432dc98f223ad1a15bf3a0a14d7653ab49da [file] [log] [blame]
Mark Sleed788b2e2006-09-07 01:26:35 +00001#ifndef _THRIFT_SERVER_TSERVER_H_
2#define _THRIFT_SERVER_TSERVER_H_ 1
Mark Sleee8540632006-05-30 09:24:40 +00003
Marc Slemko16698852006-08-04 03:16:10 +00004#include <TProcessor.h>
Mark Sleed788b2e2006-09-07 01:26:35 +00005#include <transport/TServerTransport.h>
Mark Slee4af6ed72006-10-25 19:02:49 +00006#include <protocol/TBinaryProtocol.h>
Marc Slemko3ea00332006-08-17 01:11:13 +00007#include <concurrency/Thread.h>
Marc Slemko16698852006-08-04 03:16:10 +00008
9#include <boost/shared_ptr.hpp>
Mark Sleee8540632006-05-30 09:24:40 +000010
Marc Slemko6f038a72006-08-03 18:58:09 +000011namespace facebook { namespace thrift { namespace server {
12
13using namespace facebook::thrift;
Mark Sleed788b2e2006-09-07 01:26:35 +000014using namespace facebook::thrift::transport;
Marc Slemko16698852006-08-04 03:16:10 +000015using namespace boost;
Marc Slemko6f038a72006-08-03 18:58:09 +000016
Mark Sleee8540632006-05-30 09:24:40 +000017/**
18 * Thrift server.
19 *
20 * @author Mark Slee <mcslee@facebook.com>
21 */
Aditya Agarwald622e962006-10-11 02:42:49 +000022class TServer : public concurrency::Runnable {
Marc Slemko16698852006-08-04 03:16:10 +000023public:
Mark Sleee8540632006-05-30 09:24:40 +000024 virtual ~TServer() {}
Mark Slee4af6ed72006-10-25 19:02:49 +000025
Mark Slee794993d2006-09-20 01:56:10 +000026 virtual void serve() = 0;
Aditya Agarwald622e962006-10-11 02:42:49 +000027
28 // Allows running the server as a Runnable thread
Mark Slee4af6ed72006-10-25 19:02:49 +000029 virtual void run() {
30 serve();
31 }
Marc Slemko16698852006-08-04 03:16:10 +000032
Mark Slee2f6404d2006-10-10 01:37:40 +000033 shared_ptr<TProcessor> getProcessor() {
34 return processor_;
35 }
36
Mark Slee4af6ed72006-10-25 19:02:49 +000037 shared_ptr<TProtocolFactory> getProtocolFactory() {
38 return protocolFactory_;
39 }
40
Marc Slemko16698852006-08-04 03:16:10 +000041protected:
Mark Sleed788b2e2006-09-07 01:26:35 +000042 TServer(shared_ptr<TProcessor> processor,
43 shared_ptr<TServerTransport> serverTransport,
44 shared_ptr<TTransportFactory> transportFactory,
Mark Slee4af6ed72006-10-25 19:02:49 +000045 shared_ptr<TProtocolFactory> protocolFactory) :
Mark Sleed788b2e2006-09-07 01:26:35 +000046 processor_(processor),
47 serverTransport_(serverTransport),
48 transportFactory_(transportFactory),
Mark Slee4af6ed72006-10-25 19:02:49 +000049 protocolFactory_(protocolFactory) {}
Mark Sleed788b2e2006-09-07 01:26:35 +000050
51 TServer(shared_ptr<TProcessor> processor,
Mark Slee4af6ed72006-10-25 19:02:49 +000052 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 Sleed788b2e2006-09-07 01:26:35 +000073
Marc Slemko16698852006-08-04 03:16:10 +000074 shared_ptr<TProcessor> processor_;
Mark Sleed788b2e2006-09-07 01:26:35 +000075 shared_ptr<TServerTransport> serverTransport_;
76 shared_ptr<TTransportFactory> transportFactory_;
Mark Slee4af6ed72006-10-25 19:02:49 +000077 shared_ptr<TProtocolFactory> protocolFactory_;
Mark Sleee8540632006-05-30 09:24:40 +000078};
Marc Slemko16698852006-08-04 03:16:10 +000079
Marc Slemko6f038a72006-08-03 18:58:09 +000080}}} // facebook::thrift::server
81
Mark Sleed788b2e2006-09-07 01:26:35 +000082#endif // #ifndef _THRIFT_SERVER_TSERVER_H_