blob: 4d0811aaac9b25b41471ce0ea5893aa95289f80d [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Mark Slee9f0c6512007-02-28 23:58:26 +000019
Mark Sleeb3cb6292007-02-01 22:55:00 +000020#ifndef _THRIFT_SERVER_TTHREADEDSERVER_H_
21#define _THRIFT_SERVER_TTHREADEDSERVER_H_ 1
22
23#include <server/TServer.h>
24#include <transport/TServerTransport.h>
Mark Slee1d4ce802007-03-07 05:16:16 +000025#include <concurrency/Monitor.h>
Mark Sleeb3cb6292007-02-01 22:55:00 +000026#include <concurrency/Thread.h>
27
28#include <boost/shared_ptr.hpp>
29
T Jake Lucianib5e62212009-01-31 22:36:20 +000030namespace apache { namespace thrift { namespace server {
Mark Sleeb3cb6292007-02-01 22:55:00 +000031
T Jake Lucianib5e62212009-01-31 22:36:20 +000032using apache::thrift::TProcessor;
33using apache::thrift::transport::TServerTransport;
34using apache::thrift::transport::TTransportFactory;
35using apache::thrift::concurrency::Monitor;
36using apache::thrift::concurrency::ThreadFactory;
Mark Sleeb3cb6292007-02-01 22:55:00 +000037
38class TThreadedServer : public TServer {
39
40 public:
41 class Task;
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000042
Mark Slee5ea15f92007-03-05 22:55:59 +000043 TThreadedServer(boost::shared_ptr<TProcessor> processor,
44 boost::shared_ptr<TServerTransport> serverTransport,
45 boost::shared_ptr<TTransportFactory> transportFactory,
46 boost::shared_ptr<TProtocolFactory> protocolFactory);
Mark Sleeb3cb6292007-02-01 22:55:00 +000047
David Reiss45d56962009-03-14 23:35:16 +000048 TThreadedServer(boost::shared_ptr<TProcessor> processor,
49 boost::shared_ptr<TServerTransport> serverTransport,
50 boost::shared_ptr<TTransportFactory> transportFactory,
51 boost::shared_ptr<TProtocolFactory> protocolFactory,
52 boost::shared_ptr<ThreadFactory> threadFactory);
53
Mark Sleeb3cb6292007-02-01 22:55:00 +000054 virtual ~TThreadedServer();
55
56 virtual void serve();
57
Mark Slee1d4ce802007-03-07 05:16:16 +000058 void stop() {
59 stop_ = true;
60 serverTransport_->interrupt();
61 }
62
Mark Sleeb3cb6292007-02-01 22:55:00 +000063 protected:
Mark Slee5ea15f92007-03-05 22:55:59 +000064 boost::shared_ptr<ThreadFactory> threadFactory_;
Mark Slee1d4ce802007-03-07 05:16:16 +000065 volatile bool stop_;
66
67 Monitor tasksMonitor_;
68 std::set<Task*> tasks_;
Mark Sleeb3cb6292007-02-01 22:55:00 +000069
70};
71
T Jake Lucianib5e62212009-01-31 22:36:20 +000072}}} // apache::thrift::server
Mark Sleeb3cb6292007-02-01 22:55:00 +000073
74#endif // #ifndef _THRIFT_SERVER_TTHREADEDSERVER_H_