blob: b8b64f2224d49ffed374bbaa9106df12454e93a3 [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
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;
26
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,
38 boost::shared_ptr<TProtocolFactory> outputProtocolFactory,
39 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
45 virtual long long timeout() const;
46 virtual void timeout(long long value);
Mark Slee6e3f6372007-03-01 22:05:46 +000047
Mark Sleea5a783f2007-03-02 19:41:08 +000048 virtual void stop() {
49 stop_ = true;
50 serverTransport_->interrupt();
51 }
Marc Slemko16698852006-08-04 03:16:10 +000052
Mark Sleeb3cb6292007-02-01 22:55:00 +000053 protected:
Marc Slemko16698852006-08-04 03:16:10 +000054
Mark Slee5ea15f92007-03-05 22:55:59 +000055 boost::shared_ptr<ThreadManager> threadManager_;
Mark Slee6e3f6372007-03-01 22:05:46 +000056
57 volatile bool stop_;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000058
59 volatile long long timeout_;
Marc Slemko16698852006-08-04 03:16:10 +000060
61};
62
Marc Slemko35452342006-08-03 19:01:37 +000063}}} // facebook::thrift::server
64
Mark Sleed788b2e2006-09-07 01:26:35 +000065#endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_