| Gavin McDonald | 0b75e1a | 2010-10-28 02:12:01 +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 | */ |
| 19 | |
| 20 | #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ |
| 21 | #define _THRIFT_SERVER_TTHREADPOOLSERVER_H_ 1 |
| 22 | |
| 23 | #include <concurrency/ThreadManager.h> |
| 24 | #include <server/TServer.h> |
| 25 | #include <transport/TServerTransport.h> |
| 26 | |
| 27 | #include <boost/shared_ptr.hpp> |
| 28 | |
| 29 | namespace apache { namespace thrift { namespace server { |
| 30 | |
| 31 | using apache::thrift::concurrency::ThreadManager; |
| 32 | using apache::thrift::protocol::TProtocolFactory; |
| 33 | using apache::thrift::transport::TServerTransport; |
| 34 | using apache::thrift::transport::TTransportFactory; |
| 35 | |
| 36 | class TThreadPoolServer : public TServer { |
| 37 | public: |
| 38 | class Task; |
| 39 | |
| 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); |
| 45 | |
| 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, |
| 51 | boost::shared_ptr<TProtocolFactory> outputProtocolFactory, |
| 52 | boost::shared_ptr<ThreadManager> threadManager); |
| 53 | |
| 54 | virtual ~TThreadPoolServer(); |
| 55 | |
| 56 | virtual void serve(); |
| 57 | |
| 58 | virtual int64_t getTimeout() const; |
| 59 | |
| 60 | virtual void setTimeout(int64_t value); |
| 61 | |
| 62 | virtual void stop() { |
| 63 | stop_ = true; |
| 64 | serverTransport_->interrupt(); |
| 65 | } |
| 66 | |
| 67 | protected: |
| 68 | |
| 69 | boost::shared_ptr<ThreadManager> threadManager_; |
| 70 | |
| 71 | volatile bool stop_; |
| 72 | |
| 73 | volatile int64_t timeout_; |
| 74 | |
| 75 | }; |
| 76 | |
| 77 | }}} // apache::thrift::server |
| 78 | |
| 79 | #endif // #ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_ |