blob: bdb0e47cb5cd02d61f0f91c9223c9cbbbf811555 [file] [log] [blame]
Mark Slee9f0c6512007-02-28 23:58:26 +00001// 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 Sleed788b2e2006-09-07 01:26:35 +00007#ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_
8#define _THRIFT_SERVER_TTHREADPOOLSERVER_H_ 1
Marc Slemko35452342006-08-03 19:01:37 +00009
Marc Slemko16698852006-08-04 03:16:10 +000010#include <concurrency/ThreadManager.h>
11#include <server/TServer.h>
12#include <transport/TServerTransport.h>
13
14#include <boost/shared_ptr.hpp>
Marc Slemko35452342006-08-03 19:01:37 +000015
16namespace facebook { namespace thrift { namespace server {
Marc Slemko16698852006-08-04 03:16:10 +000017
18using namespace facebook::thrift::concurrency;
19using namespace facebook::thrift::transport;
20using namespace boost;
21
22class TThreadPoolServer : public TServer {
Mark Sleeb3cb6292007-02-01 22:55:00 +000023 public:
Marc Slemko16698852006-08-04 03:16:10 +000024 class Task;
25
26 TThreadPoolServer(shared_ptr<TProcessor> processor,
Martin Kraemer50919172007-01-26 01:41:03 +000027 shared_ptr<TServerTransport> serverTransport,
28 shared_ptr<TTransportFactory> transportFactory,
Mark Slee4af6ed72006-10-25 19:02:49 +000029 shared_ptr<TProtocolFactory> protocolFactory,
Martin Kraemer50919172007-01-26 01:41:03 +000030 shared_ptr<ThreadManager> threadManager);
Marc Slemko16698852006-08-04 03:16:10 +000031
Aditya Agarwal9abb0d62007-01-24 22:53:54 +000032 TThreadPoolServer(shared_ptr<TProcessor> processor,
Martin Kraemer50919172007-01-26 01:41:03 +000033 shared_ptr<TServerTransport> serverTransport,
Aditya Agarwal9abb0d62007-01-24 22:53:54 +000034 shared_ptr<TTransportFactory> inputTransportFactory,
35 shared_ptr<TTransportFactory> outputTransportFactory,
36 shared_ptr<TProtocolFactory> inputProtocolFactory,
37 shared_ptr<TProtocolFactory> outputProtocolFactory,
Martin Kraemer50919172007-01-26 01:41:03 +000038 shared_ptr<ThreadManager> threadManager);
Aditya Agarwal9abb0d62007-01-24 22:53:54 +000039
Marc Slemko16698852006-08-04 03:16:10 +000040 virtual ~TThreadPoolServer();
41
Mark Slee794993d2006-09-20 01:56:10 +000042 virtual void serve();
Mark Slee6e3f6372007-03-01 22:05:46 +000043
Mark Sleea5a783f2007-03-02 19:41:08 +000044 virtual void stop() {
45 stop_ = true;
46 serverTransport_->interrupt();
47 }
Marc Slemko16698852006-08-04 03:16:10 +000048
Mark Sleeb3cb6292007-02-01 22:55:00 +000049 protected:
Marc Slemko16698852006-08-04 03:16:10 +000050
Marc Slemko16698852006-08-04 03:16:10 +000051 shared_ptr<ThreadManager> threadManager_;
Mark Slee6e3f6372007-03-01 22:05:46 +000052
53 volatile bool stop_;
Marc Slemko16698852006-08-04 03:16:10 +000054
55};
56
Marc Slemko35452342006-08-03 19:01:37 +000057}}} // facebook::thrift::server
58
Mark Sleed788b2e2006-09-07 01:26:35 +000059#endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_