blob: 28d354911cefab32de4c8af114c65c6d53c0d5fe [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 Sleeb3cb6292007-02-01 22:55:00 +00007#ifndef _THRIFT_SERVER_TTHREADEDSERVER_H_
8#define _THRIFT_SERVER_TTHREADEDSERVER_H_ 1
9
10#include <server/TServer.h>
11#include <transport/TServerTransport.h>
Mark Slee1d4ce802007-03-07 05:16:16 +000012#include <concurrency/Monitor.h>
Mark Sleeb3cb6292007-02-01 22:55:00 +000013#include <concurrency/Thread.h>
14
15#include <boost/shared_ptr.hpp>
16
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000017namespace facebook { namespace thrift { namespace server {
Mark Sleeb3cb6292007-02-01 22:55:00 +000018
Mark Slee5ea15f92007-03-05 22:55:59 +000019using facebook::thrift::TProcessor;
20using facebook::thrift::transport::TServerTransport;
21using facebook::thrift::transport::TTransportFactory;
Mark Slee1d4ce802007-03-07 05:16:16 +000022using facebook::thrift::concurrency::Monitor;
Mark Slee5ea15f92007-03-05 22:55:59 +000023using facebook::thrift::concurrency::ThreadFactory;
Mark Sleeb3cb6292007-02-01 22:55:00 +000024
25class TThreadedServer : public TServer {
26
27 public:
28 class Task;
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000029
Mark Slee5ea15f92007-03-05 22:55:59 +000030 TThreadedServer(boost::shared_ptr<TProcessor> processor,
31 boost::shared_ptr<TServerTransport> serverTransport,
32 boost::shared_ptr<TTransportFactory> transportFactory,
33 boost::shared_ptr<TProtocolFactory> protocolFactory);
Mark Sleeb3cb6292007-02-01 22:55:00 +000034
35 virtual ~TThreadedServer();
36
37 virtual void serve();
38
Mark Slee1d4ce802007-03-07 05:16:16 +000039 void stop() {
40 stop_ = true;
41 serverTransport_->interrupt();
42 }
43
Mark Sleeb3cb6292007-02-01 22:55:00 +000044 protected:
Mark Slee5ea15f92007-03-05 22:55:59 +000045 boost::shared_ptr<ThreadFactory> threadFactory_;
Mark Slee1d4ce802007-03-07 05:16:16 +000046 volatile bool stop_;
47
48 Monitor tasksMonitor_;
49 std::set<Task*> tasks_;
Mark Sleeb3cb6292007-02-01 22:55:00 +000050
51};
52
53}}} // facebook::thrift::server
54
55#endif // #ifndef _THRIFT_SERVER_TTHREADEDSERVER_H_