blob: f27e8f709d38a721e99568b2547a72b71d87e69b [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
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000016namespace facebook { namespace thrift { namespace server {
Marc Slemko16698852006-08-04 03:16:10 +000017
Mark Slee5ea15f92007-03-05 22:55:59 +000018using facebook::thrift::concurrency::ThreadManager;
19using facebook::thrift::protocol::TProtocolFactory;
20using facebook::thrift::transport::TServerTransport;
21using facebook::thrift::transport::TTransportFactory;
Marc Slemko16698852006-08-04 03:16:10 +000022
23class TThreadPoolServer : public TServer {
Mark Sleeb3cb6292007-02-01 22:55:00 +000024 public:
Marc Slemko16698852006-08-04 03:16:10 +000025 class Task;
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000026
Mark Slee5ea15f92007-03-05 22:55:59 +000027 TThreadPoolServer(boost::shared_ptr<TProcessor> processor,
28 boost::shared_ptr<TServerTransport> serverTransport,
29 boost::shared_ptr<TTransportFactory> transportFactory,
30 boost::shared_ptr<TProtocolFactory> protocolFactory,
31 boost::shared_ptr<ThreadManager> threadManager);
Marc Slemko16698852006-08-04 03:16:10 +000032
Mark Slee5ea15f92007-03-05 22:55:59 +000033 TThreadPoolServer(boost::shared_ptr<TProcessor> processor,
34 boost::shared_ptr<TServerTransport> serverTransport,
35 boost::shared_ptr<TTransportFactory> inputTransportFactory,
36 boost::shared_ptr<TTransportFactory> outputTransportFactory,
37 boost::shared_ptr<TProtocolFactory> inputProtocolFactory,
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000038 boost::shared_ptr<TProtocolFactory> outputProtocolFactory,
Mark Slee5ea15f92007-03-05 22:55:59 +000039 boost::shared_ptr<ThreadManager> threadManager);
Aditya Agarwal9abb0d62007-01-24 22:53:54 +000040
Marc Slemko16698852006-08-04 03:16:10 +000041 virtual ~TThreadPoolServer();
42
Mark Slee794993d2006-09-20 01:56:10 +000043 virtual void serve();
Marc Slemko3a3b53b2007-05-22 23:59:54 +000044
Mark Slee9b82d272007-05-23 05:16:07 +000045 virtual int64_t getTimeout() const;
46
47 virtual void setTimeout(int64_t value);
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000048
Mark Sleea5a783f2007-03-02 19:41:08 +000049 virtual void stop() {
50 stop_ = true;
51 serverTransport_->interrupt();
52 }
Marc Slemko16698852006-08-04 03:16:10 +000053
Mark Sleeb3cb6292007-02-01 22:55:00 +000054 protected:
Marc Slemko16698852006-08-04 03:16:10 +000055
Mark Slee5ea15f92007-03-05 22:55:59 +000056 boost::shared_ptr<ThreadManager> threadManager_;
Mark Slee6e3f6372007-03-01 22:05:46 +000057
58 volatile bool stop_;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000059
Mark Slee9b82d272007-05-23 05:16:07 +000060 volatile int64_t timeout_;
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000061
Marc Slemko16698852006-08-04 03:16:10 +000062};
63
Marc Slemko35452342006-08-03 19:01:37 +000064}}} // facebook::thrift::server
65
Mark Sleed788b2e2006-09-07 01:26:35 +000066#endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_