blob: b9f4fca8b2cefe0d76254e6df3ab4b3a45e51565 [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 }
Aditya Agarwal1ea90522007-01-19 02:02:12 +000036
37 shared_ptr<TServerTransport> getServerTransport() {
38 return serverTransport_;
39 }
40
41 shared_ptr<TTransportFactory> getTransportFactory() {
42 return transportFactory_;
43 }
Mark Slee2f6404d2006-10-10 01:37:40 +000044
Mark Slee4af6ed72006-10-25 19:02:49 +000045 shared_ptr<TProtocolFactory> getProtocolFactory() {
46 return protocolFactory_;
47 }
48
Aditya Agarwal1ea90522007-01-19 02:02:12 +000049
Marc Slemko16698852006-08-04 03:16:10 +000050protected:
Mark Sleed788b2e2006-09-07 01:26:35 +000051 TServer(shared_ptr<TProcessor> processor,
52 shared_ptr<TServerTransport> serverTransport,
53 shared_ptr<TTransportFactory> transportFactory,
Mark Slee4af6ed72006-10-25 19:02:49 +000054 shared_ptr<TProtocolFactory> protocolFactory) :
Mark Sleed788b2e2006-09-07 01:26:35 +000055 processor_(processor),
56 serverTransport_(serverTransport),
57 transportFactory_(transportFactory),
Mark Slee4af6ed72006-10-25 19:02:49 +000058 protocolFactory_(protocolFactory) {}
Mark Sleed788b2e2006-09-07 01:26:35 +000059
60 TServer(shared_ptr<TProcessor> processor,
Mark Slee4af6ed72006-10-25 19:02:49 +000061 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 Agarwal1ea90522007-01-19 02:02:12 +000082
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 Sleed788b2e2006-09-07 01:26:35 +0000103
Marc Slemko16698852006-08-04 03:16:10 +0000104 shared_ptr<TProcessor> processor_;
Mark Sleed788b2e2006-09-07 01:26:35 +0000105 shared_ptr<TServerTransport> serverTransport_;
106 shared_ptr<TTransportFactory> transportFactory_;
Mark Slee4af6ed72006-10-25 19:02:49 +0000107 shared_ptr<TProtocolFactory> protocolFactory_;
Mark Sleee8540632006-05-30 09:24:40 +0000108};
Marc Slemko16698852006-08-04 03:16:10 +0000109
Marc Slemko6f038a72006-08-03 18:58:09 +0000110}}} // facebook::thrift::server
111
Mark Sleed788b2e2006-09-07 01:26:35 +0000112#endif // #ifndef _THRIFT_SERVER_TSERVER_H_