blob: b860ae252c2da70eb41e087f125b28fd24974281 [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
Bryan Duxbury7a9fb812011-09-01 18:31:53 +000040 template<typename ProcessorFactory>
41 TThreadPoolServer(
42 const boost::shared_ptr<ProcessorFactory>& processorFactory,
43 const boost::shared_ptr<TServerTransport>& serverTransport,
44 const boost::shared_ptr<TTransportFactory>& transportFactory,
45 const boost::shared_ptr<TProtocolFactory>& protocolFactory,
46 const boost::shared_ptr<ThreadManager>& threadManager,
47 THRIFT_OVERLOAD_IF(ProcessorFactory, TProtocolFactory)) :
48 TServer(processorFactory, serverTransport, transportFactory,
49 protocolFactory),
50 threadManager_(threadManager),
51 stop_(false),
52 timeout_(0) {}
Marc Slemko16698852006-08-04 03:16:10 +000053
Bryan Duxbury7a9fb812011-09-01 18:31:53 +000054 template<typename Processor>
55 TThreadPoolServer(
56 const boost::shared_ptr<Processor>& processor,
57 const boost::shared_ptr<TServerTransport>& serverTransport,
58 const boost::shared_ptr<TTransportFactory>& transportFactory,
59 const boost::shared_ptr<TProtocolFactory>& protocolFactory,
60 const boost::shared_ptr<ThreadManager>& threadManager,
61 THRIFT_OVERLOAD_IF(Processor, TProcessor)) :
62 TServer(processor, serverTransport, transportFactory, protocolFactory),
63 threadManager_(threadManager),
64 stop_(false),
65 timeout_(0) {}
66
67 template<typename ProcessorFactory>
68 TThreadPoolServer(
69 const boost::shared_ptr<ProcessorFactory>& processorFactory,
70 const boost::shared_ptr<TServerTransport>& serverTransport,
71 const boost::shared_ptr<TTransportFactory>& inputTransportFactory,
72 const boost::shared_ptr<TTransportFactory>& outputTransportFactory,
73 const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory,
74 const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory,
75 const boost::shared_ptr<ThreadManager>& threadManager,
76 THRIFT_OVERLOAD_IF(ProcessorFactory, TProcessorFactory)) :
77 TServer(processorFactory, serverTransport,
78 inputTransportFactory, outputTransportFactory,
79 inputProtocolFactory, outputProtocolFactory),
80 threadManager_(threadManager),
81 stop_(false),
82 timeout_(0) {}
83
84 template<typename Processor>
85 TThreadPoolServer(
86 const boost::shared_ptr<Processor>& processor,
87 const boost::shared_ptr<TServerTransport>& serverTransport,
88 const boost::shared_ptr<TTransportFactory>& inputTransportFactory,
89 const boost::shared_ptr<TTransportFactory>& outputTransportFactory,
90 const boost::shared_ptr<TProtocolFactory>& inputProtocolFactory,
91 const boost::shared_ptr<TProtocolFactory>& outputProtocolFactory,
92 const boost::shared_ptr<ThreadManager>& threadManager,
93 THRIFT_OVERLOAD_IF(Processor, TProcessor)) :
94 TServer(processor, serverTransport,
95 inputTransportFactory, outputTransportFactory,
96 inputProtocolFactory, outputProtocolFactory),
97 threadManager_(threadManager),
98 stop_(false),
99 timeout_(0) {}
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000100
Marc Slemko16698852006-08-04 03:16:10 +0000101 virtual ~TThreadPoolServer();
102
Mark Slee794993d2006-09-20 01:56:10 +0000103 virtual void serve();
Marc Slemko3a3b53b2007-05-22 23:59:54 +0000104
Mark Slee9b82d272007-05-23 05:16:07 +0000105 virtual int64_t getTimeout() const;
106
107 virtual void setTimeout(int64_t value);
Mark Sleeb4d3e7b2007-11-28 01:51:43 +0000108
Mark Sleea5a783f2007-03-02 19:41:08 +0000109 virtual void stop() {
110 stop_ = true;
111 serverTransport_->interrupt();
112 }
Marc Slemko16698852006-08-04 03:16:10 +0000113
Mark Sleeb3cb6292007-02-01 22:55:00 +0000114 protected:
Marc Slemko16698852006-08-04 03:16:10 +0000115
Mark Slee5ea15f92007-03-05 22:55:59 +0000116 boost::shared_ptr<ThreadManager> threadManager_;
Mark Slee6e3f6372007-03-01 22:05:46 +0000117
118 volatile bool stop_;
Marc Slemko3a3b53b2007-05-22 23:59:54 +0000119
Mark Slee9b82d272007-05-23 05:16:07 +0000120 volatile int64_t timeout_;
Mark Sleeb4d3e7b2007-11-28 01:51:43 +0000121
Marc Slemko16698852006-08-04 03:16:10 +0000122};
123
T Jake Lucianib5e62212009-01-31 22:36:20 +0000124}}} // apache::thrift::server
Marc Slemko35452342006-08-03 19:01:37 +0000125
Mark Sleed788b2e2006-09-07 01:26:35 +0000126#endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_