David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 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 Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 19 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 20 | #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ |
| 21 | #define _THRIFT_SERVER_TTHREADPOOLSERVER_H_ 1 |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 22 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 23 | #include <concurrency/ThreadManager.h> |
| 24 | #include <server/TServer.h> |
| 25 | #include <transport/TServerTransport.h> |
| 26 | |
| 27 | #include <boost/shared_ptr.hpp> |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 28 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 29 | namespace apache { namespace thrift { namespace server { |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 30 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 31 | using apache::thrift::concurrency::ThreadManager; |
| 32 | using apache::thrift::protocol::TProtocolFactory; |
| 33 | using apache::thrift::transport::TServerTransport; |
| 34 | using apache::thrift::transport::TTransportFactory; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 35 | |
| 36 | class TThreadPoolServer : public TServer { |
Mark Slee | b3cb629 | 2007-02-01 22:55:00 +0000 | [diff] [blame] | 37 | public: |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 38 | class Task; |
Mark Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 39 | |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 40 | 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 Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 45 | |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 46 | 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 Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 51 | boost::shared_ptr<TProtocolFactory> outputProtocolFactory, |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 52 | boost::shared_ptr<ThreadManager> threadManager); |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 53 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 54 | virtual ~TThreadPoolServer(); |
| 55 | |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 56 | virtual void serve(); |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 57 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 58 | virtual int64_t getTimeout() const; |
| 59 | |
| 60 | virtual void setTimeout(int64_t value); |
Mark Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 61 | |
Mark Slee | a5a783f | 2007-03-02 19:41:08 +0000 | [diff] [blame] | 62 | virtual void stop() { |
| 63 | stop_ = true; |
| 64 | serverTransport_->interrupt(); |
| 65 | } |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 66 | |
Mark Slee | b3cb629 | 2007-02-01 22:55:00 +0000 | [diff] [blame] | 67 | protected: |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 68 | |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 69 | boost::shared_ptr<ThreadManager> threadManager_; |
Mark Slee | 6e3f637 | 2007-03-01 22:05:46 +0000 | [diff] [blame] | 70 | |
| 71 | volatile bool stop_; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 72 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 73 | volatile int64_t timeout_; |
Mark Slee | b4d3e7b | 2007-11-28 01:51:43 +0000 | [diff] [blame] | 74 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 77 | }}} // apache::thrift::server |
Marc Slemko | 3545234 | 2006-08-03 19:01:37 +0000 | [diff] [blame] | 78 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 79 | #endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ |