Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 08:35:03

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements. See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership. The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License. You may obtain a copy of the License at
0009  *
0010  *   http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing,
0013  * software distributed under the License is distributed on an
0014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015  * KIND, either express or implied. See the License for the
0016  * specific language governing permissions and limitations
0017  * under the License.
0018  */
0019 
0020 #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_
0021 #define _THRIFT_SERVER_TTHREADPOOLSERVER_H_ 1
0022 
0023 #include <atomic>
0024 #include <thrift/concurrency/ThreadManager.h>
0025 #include <thrift/server/TServerFramework.h>
0026 
0027 namespace apache {
0028 namespace thrift {
0029 namespace server {
0030 
0031 /**
0032  * Manage clients using a thread pool.
0033  */
0034 class TThreadPoolServer : public TServerFramework {
0035 public:
0036   TThreadPoolServer(
0037       const std::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory,
0038       const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
0039       const std::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory,
0040       const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory,
0041       const std::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager
0042       = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager());
0043 
0044   TThreadPoolServer(
0045       const std::shared_ptr<apache::thrift::TProcessor>& processor,
0046       const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
0047       const std::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory,
0048       const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory,
0049       const std::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager
0050       = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager());
0051 
0052   TThreadPoolServer(
0053       const std::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory,
0054       const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
0055       const std::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
0056       const std::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
0057       const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
0058       const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory,
0059       const std::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager
0060       = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager());
0061 
0062   TThreadPoolServer(
0063       const std::shared_ptr<apache::thrift::TProcessor>& processor,
0064       const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
0065       const std::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
0066       const std::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
0067       const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
0068       const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory,
0069       const std::shared_ptr<apache::thrift::concurrency::ThreadManager>& threadManager
0070       = apache::thrift::concurrency::ThreadManager::newSimpleThreadManager());
0071 
0072   ~TThreadPoolServer() override;
0073 
0074   /**
0075    * Post-conditions (return guarantees):
0076    *   There will be no clients connected.
0077    */
0078   void serve() override;
0079 
0080   virtual int64_t getTimeout() const;
0081   virtual void setTimeout(int64_t value);
0082 
0083   virtual int64_t getTaskExpiration() const;
0084   virtual void setTaskExpiration(int64_t value);
0085 
0086   virtual std::shared_ptr<apache::thrift::concurrency::ThreadManager> getThreadManager() const;
0087 
0088 protected:
0089   void onClientConnected(const std::shared_ptr<TConnectedClient>& pClient) override /* override */;
0090   void onClientDisconnected(TConnectedClient* pClient) override /* override */;
0091 
0092   std::shared_ptr<apache::thrift::concurrency::ThreadManager> threadManager_;
0093   std::atomic<int64_t> timeout_;
0094   std::atomic<int64_t> taskExpiration_;
0095 };
0096 
0097 }
0098 }
0099 } // apache::thrift::server
0100 
0101 #endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_