blob: 29e9aaf0eaffef318926f2ee60303f53c2d12155 [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
Roger Meier49ff8b12012-04-13 09:12:31 +000023#include <thrift/concurrency/ThreadManager.h>
Jim King21b68522015-04-26 18:30:26 -040024#include <thrift/server/TServerFramework.h>
Marc Slemko35452342006-08-03 19:01:37 +000025
Konrad Grochowski16a23a62014-11-13 15:33:38 +010026namespace apache {
27namespace thrift {
28namespace server {
Marc Slemko16698852006-08-04 03:16:10 +000029
Jim King21b68522015-04-26 18:30:26 -040030/**
31 * Manage clients using a thread pool.
32 */
33class TThreadPoolServer : public TServerFramework {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010034public:
Jim King21b68522015-04-26 18:30:26 -040035 TThreadPoolServer(
36 const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory,
37 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
38 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory,
39 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory,
40 const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager);
Marc Slemko16698852006-08-04 03:16:10 +000041
Jim King21b68522015-04-26 18:30:26 -040042 TThreadPoolServer(
43 const boost::shared_ptr<apache::thrift::TProcessor>& processor,
44 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
45 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory,
46 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory,
47 const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager);
Bryan Duxbury7a9fb812011-09-01 18:31:53 +000048
Jim King21b68522015-04-26 18:30:26 -040049 TThreadPoolServer(
50 const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory,
51 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
52 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
53 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
54 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
55 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory,
56 const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager);
Bryan Duxbury7a9fb812011-09-01 18:31:53 +000057
Jim King21b68522015-04-26 18:30:26 -040058 TThreadPoolServer(
59 const boost::shared_ptr<apache::thrift::TProcessor>& processor,
60 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
61 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
62 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
63 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
64 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory,
65 const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager);
Aditya Agarwal9abb0d62007-01-24 22:53:54 +000066
Marc Slemko16698852006-08-04 03:16:10 +000067 virtual ~TThreadPoolServer();
68
Jim King5ec805b2015-04-26 07:52:40 -040069 /**
Jim King5ec805b2015-04-26 07:52:40 -040070 * Post-conditions (return guarantees):
Jim King21b68522015-04-26 18:30:26 -040071 * There will be no clients connected.
Jim King5ec805b2015-04-26 07:52:40 -040072 */
Mark Slee794993d2006-09-20 01:56:10 +000073 virtual void serve();
Marc Slemko3a3b53b2007-05-22 23:59:54 +000074
Mark Slee9b82d272007-05-23 05:16:07 +000075 virtual int64_t getTimeout() const;
Mark Slee9b82d272007-05-23 05:16:07 +000076 virtual void setTimeout(int64_t value);
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000077
Roger Meier5ed5e8b2013-05-06 00:21:04 +020078 virtual int64_t getTaskExpiration() const;
Roger Meier5ed5e8b2013-05-06 00:21:04 +020079 virtual void setTaskExpiration(int64_t value);
80
Konrad Grochowski16a23a62014-11-13 15:33:38 +010081protected:
Jim King21b68522015-04-26 18:30:26 -040082 virtual void onClientConnected(const boost::shared_ptr<TConnectedClient>& pClient) /* override */;
83 virtual void onClientDisconnected(TConnectedClient *pClient) /* override */;
84
85 boost::shared_ptr<apache::thrift::concurrency::ThreadManager> threadManager_;
Mark Slee6e3f6372007-03-01 22:05:46 +000086
87 volatile bool stop_;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000088
Mark Slee9b82d272007-05-23 05:16:07 +000089 volatile int64_t timeout_;
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000090
Roger Meier5ed5e8b2013-05-06 00:21:04 +020091 volatile int64_t taskExpiration_;
Marc Slemko16698852006-08-04 03:16:10 +000092};
Jim King21b68522015-04-26 18:30:26 -040093
Konrad Grochowski16a23a62014-11-13 15:33:38 +010094}
95}
96} // apache::thrift::server
Marc Slemko35452342006-08-03 19:01:37 +000097
Mark Sleed788b2e2006-09-07 01:26:35 +000098#endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_