blob: 7ff07d9d780a159f18a4c8b6b5834794c20ab4a2 [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
T Jake Lucianib5e62212009-01-31 22:36:20 +000017namespace apache { namespace thrift { namespace server {
Mark Sleeb3cb6292007-02-01 22:55:00 +000018
T Jake Lucianib5e62212009-01-31 22:36:20 +000019using apache::thrift::TProcessor;
20using apache::thrift::transport::TServerTransport;
21using apache::thrift::transport::TTransportFactory;
22using apache::thrift::concurrency::Monitor;
23using apache::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
David Reiss45d56962009-03-14 23:35:16 +000035 TThreadedServer(boost::shared_ptr<TProcessor> processor,
36 boost::shared_ptr<TServerTransport> serverTransport,
37 boost::shared_ptr<TTransportFactory> transportFactory,
38 boost::shared_ptr<TProtocolFactory> protocolFactory,
39 boost::shared_ptr<ThreadFactory> threadFactory);
40
Mark Sleeb3cb6292007-02-01 22:55:00 +000041 virtual ~TThreadedServer();
42
43 virtual void serve();
44
Mark Slee1d4ce802007-03-07 05:16:16 +000045 void stop() {
46 stop_ = true;
47 serverTransport_->interrupt();
48 }
49
Mark Sleeb3cb6292007-02-01 22:55:00 +000050 protected:
Mark Slee5ea15f92007-03-05 22:55:59 +000051 boost::shared_ptr<ThreadFactory> threadFactory_;
Mark Slee1d4ce802007-03-07 05:16:16 +000052 volatile bool stop_;
53
54 Monitor tasksMonitor_;
55 std::set<Task*> tasks_;
Mark Sleeb3cb6292007-02-01 22:55:00 +000056
57};
58
T Jake Lucianib5e62212009-01-31 22:36:20 +000059}}} // apache::thrift::server
Mark Sleeb3cb6292007-02-01 22:55:00 +000060
61#endif // #ifndef _THRIFT_SERVER_TTHREADEDSERVER_H_