blob: 7b7e9064743dd757156f2fd9f2473c979e02587d [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 Sleed788b2e2006-09-07 01:26:35 +000020#ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_
21#define _THRIFT_SERVER_TTHREADPOOLSERVER_H_ 1
Marc Slemko35452342006-08-03 19:01:37 +000022
Marc Slemko16698852006-08-04 03:16:10 +000023#include <concurrency/ThreadManager.h>
24#include <server/TServer.h>
25#include <transport/TServerTransport.h>
26
27#include <boost/shared_ptr.hpp>
Marc Slemko35452342006-08-03 19:01:37 +000028
T Jake Lucianib5e62212009-01-31 22:36:20 +000029namespace apache { namespace thrift { namespace server {
Marc Slemko16698852006-08-04 03:16:10 +000030
T Jake Lucianib5e62212009-01-31 22:36:20 +000031using apache::thrift::concurrency::ThreadManager;
32using apache::thrift::protocol::TProtocolFactory;
33using apache::thrift::transport::TServerTransport;
34using apache::thrift::transport::TTransportFactory;
Marc Slemko16698852006-08-04 03:16:10 +000035
36class TThreadPoolServer : public TServer {
Mark Sleeb3cb6292007-02-01 22:55:00 +000037 public:
Marc Slemko16698852006-08-04 03:16:10 +000038 class Task;
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000039
Mark Slee5ea15f92007-03-05 22:55:59 +000040 TThreadPoolServer(boost::shared_ptr<TProcessor> processor,
41 boost::shared_ptr<TServerTransport> serverTransport,
42 boost::shared_ptr<TTransportFactory> transportFactory,
43 boost::shared_ptr<TProtocolFactory> protocolFactory,
44 boost::shared_ptr<ThreadManager> threadManager);
Marc Slemko16698852006-08-04 03:16:10 +000045
Mark Slee5ea15f92007-03-05 22:55:59 +000046 TThreadPoolServer(boost::shared_ptr<TProcessor> processor,
47 boost::shared_ptr<TServerTransport> serverTransport,
48 boost::shared_ptr<TTransportFactory> inputTransportFactory,
49 boost::shared_ptr<TTransportFactory> outputTransportFactory,
50 boost::shared_ptr<TProtocolFactory> inputProtocolFactory,
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000051 boost::shared_ptr<TProtocolFactory> outputProtocolFactory,
Mark Slee5ea15f92007-03-05 22:55:59 +000052 boost::shared_ptr<ThreadManager> threadManager);
Aditya Agarwal9abb0d62007-01-24 22:53:54 +000053
Marc Slemko16698852006-08-04 03:16:10 +000054 virtual ~TThreadPoolServer();
55
Mark Slee794993d2006-09-20 01:56:10 +000056 virtual void serve();
Marc Slemko3a3b53b2007-05-22 23:59:54 +000057
Mark Slee9b82d272007-05-23 05:16:07 +000058 virtual int64_t getTimeout() const;
59
60 virtual void setTimeout(int64_t value);
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000061
Mark Sleea5a783f2007-03-02 19:41:08 +000062 virtual void stop() {
63 stop_ = true;
64 serverTransport_->interrupt();
65 }
Marc Slemko16698852006-08-04 03:16:10 +000066
Mark Sleeb3cb6292007-02-01 22:55:00 +000067 protected:
Marc Slemko16698852006-08-04 03:16:10 +000068
Mark Slee5ea15f92007-03-05 22:55:59 +000069 boost::shared_ptr<ThreadManager> threadManager_;
Mark Slee6e3f6372007-03-01 22:05:46 +000070
71 volatile bool stop_;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000072
Mark Slee9b82d272007-05-23 05:16:07 +000073 volatile int64_t timeout_;
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000074
Marc Slemko16698852006-08-04 03:16:10 +000075};
76
T Jake Lucianib5e62212009-01-31 22:36:20 +000077}}} // apache::thrift::server
Marc Slemko35452342006-08-03 19:01:37 +000078
Mark Sleed788b2e2006-09-07 01:26:35 +000079#endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_