blob: 267dbad6c409e28dca5e5bcf06ac6ff0e23c365c [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,
Jim King79c99112015-04-30 07:10:08 -040040 const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager =
41 apache::thrift::concurrency::ThreadManager::newSimpleThreadManager());
Marc Slemko16698852006-08-04 03:16:10 +000042
Jim King21b68522015-04-26 18:30:26 -040043 TThreadPoolServer(
44 const boost::shared_ptr<apache::thrift::TProcessor>& processor,
45 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
46 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory,
47 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory,
Jim King79c99112015-04-30 07:10:08 -040048 const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager =
49 apache::thrift::concurrency::ThreadManager::newSimpleThreadManager());
Bryan Duxbury7a9fb812011-09-01 18:31:53 +000050
Jim King21b68522015-04-26 18:30:26 -040051 TThreadPoolServer(
52 const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory,
53 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
54 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
55 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
56 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
57 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory,
Jim King79c99112015-04-30 07:10:08 -040058 const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager =
59 apache::thrift::concurrency::ThreadManager::newSimpleThreadManager());
Bryan Duxbury7a9fb812011-09-01 18:31:53 +000060
Jim King21b68522015-04-26 18:30:26 -040061 TThreadPoolServer(
62 const boost::shared_ptr<apache::thrift::TProcessor>& processor,
63 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
64 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
65 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
66 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
67 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory,
Jim King79c99112015-04-30 07:10:08 -040068 const boost::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager =
69 apache::thrift::concurrency::ThreadManager::newSimpleThreadManager());
Aditya Agarwal9abb0d62007-01-24 22:53:54 +000070
Marc Slemko16698852006-08-04 03:16:10 +000071 virtual ~TThreadPoolServer();
72
Jim King5ec805b2015-04-26 07:52:40 -040073 /**
Jim King5ec805b2015-04-26 07:52:40 -040074 * Post-conditions (return guarantees):
Jim King21b68522015-04-26 18:30:26 -040075 * There will be no clients connected.
Jim King5ec805b2015-04-26 07:52:40 -040076 */
Mark Slee794993d2006-09-20 01:56:10 +000077 virtual void serve();
Marc Slemko3a3b53b2007-05-22 23:59:54 +000078
Mark Slee9b82d272007-05-23 05:16:07 +000079 virtual int64_t getTimeout() const;
Mark Slee9b82d272007-05-23 05:16:07 +000080 virtual void setTimeout(int64_t value);
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000081
Roger Meier5ed5e8b2013-05-06 00:21:04 +020082 virtual int64_t getTaskExpiration() const;
Roger Meier5ed5e8b2013-05-06 00:21:04 +020083 virtual void setTaskExpiration(int64_t value);
84
Jim King79c99112015-04-30 07:10:08 -040085 virtual boost::shared_ptr<apache::thrift::concurrency::ThreadManager> getThreadManager() const;
86
Konrad Grochowski16a23a62014-11-13 15:33:38 +010087protected:
Jim King21b68522015-04-26 18:30:26 -040088 virtual void onClientConnected(const boost::shared_ptr<TConnectedClient>& pClient) /* override */;
89 virtual void onClientDisconnected(TConnectedClient *pClient) /* override */;
90
91 boost::shared_ptr<apache::thrift::concurrency::ThreadManager> threadManager_;
Mark Slee6e3f6372007-03-01 22:05:46 +000092
93 volatile bool stop_;
Marc Slemko3a3b53b2007-05-22 23:59:54 +000094
Mark Slee9b82d272007-05-23 05:16:07 +000095 volatile int64_t timeout_;
Mark Sleeb4d3e7b2007-11-28 01:51:43 +000096
Roger Meier5ed5e8b2013-05-06 00:21:04 +020097 volatile int64_t taskExpiration_;
Marc Slemko16698852006-08-04 03:16:10 +000098};
Jim King21b68522015-04-26 18:30:26 -040099
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100100}
101}
102} // apache::thrift::server
Marc Slemko35452342006-08-03 19:01:37 +0000103
Mark Sleed788b2e2006-09-07 01:26:35 +0000104#endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_