blob: 7b66f1d4e8e40d6b8f9d8ad4bc85afa5361e3288 [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 Sleeb3cb6292007-02-01 22:55:00 +000020#ifndef _THRIFT_SERVER_TTHREADEDSERVER_H_
21#define _THRIFT_SERVER_TTHREADEDSERVER_H_ 1
22
Roger Meier49ff8b12012-04-13 09:12:31 +000023#include <thrift/concurrency/Monitor.h>
Jim King5ec805b2015-04-26 07:52:40 -040024#include <thrift/concurrency/PlatformThreadFactory.h>
Roger Meier49ff8b12012-04-13 09:12:31 +000025#include <thrift/concurrency/Thread.h>
Jim King21b68522015-04-26 18:30:26 -040026#include <thrift/server/TServerFramework.h>
Mark Sleeb3cb6292007-02-01 22:55:00 +000027
Konrad Grochowski16a23a62014-11-13 15:33:38 +010028namespace apache {
29namespace thrift {
30namespace server {
Mark Sleeb3cb6292007-02-01 22:55:00 +000031
Jim King21b68522015-04-26 18:30:26 -040032#define THRIFT_DEFAULT_THREAD_FACTORY
Mark Sleeb3cb6292007-02-01 22:55:00 +000033
Jim King21b68522015-04-26 18:30:26 -040034/**
35 * Manage clients using a thread pool.
36 */
37class TThreadedServer : public TServerFramework {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010038public:
Jim King21b68522015-04-26 18:30:26 -040039 TThreadedServer(const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory,
40 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
41 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory,
42 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory,
43 const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory =
44 boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>(
45 new apache::thrift::concurrency::PlatformThreadFactory));
Mark Sleeb3cb6292007-02-01 22:55:00 +000046
Jim King21b68522015-04-26 18:30:26 -040047 TThreadedServer(const boost::shared_ptr<apache::thrift::TProcessor>& processor,
48 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
49 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory,
50 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory,
51 const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory =
52 boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>(
53 new apache::thrift::concurrency::PlatformThreadFactory));
Bryan Duxbury7a9fb812011-09-01 18:31:53 +000054
Jim King21b68522015-04-26 18:30:26 -040055 TThreadedServer(const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory,
56 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
57 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
58 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
59 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
60 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory,
61 const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory =
62 boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>(
63 new apache::thrift::concurrency::PlatformThreadFactory));
Bryan Duxbury7a9fb812011-09-01 18:31:53 +000064
Jim King21b68522015-04-26 18:30:26 -040065 TThreadedServer(const boost::shared_ptr<apache::thrift::TProcessor>& processor,
66 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
67 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
68 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
69 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
70 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory,
71 const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory =
72 boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>(
73 new apache::thrift::concurrency::PlatformThreadFactory));
David Reiss45d56962009-03-14 23:35:16 +000074
Mark Sleeb3cb6292007-02-01 22:55:00 +000075 virtual ~TThreadedServer();
76
Jim King5ec805b2015-04-26 07:52:40 -040077 /**
Jim King5ec805b2015-04-26 07:52:40 -040078 * Post-conditions (return guarantees):
Jim King21b68522015-04-26 18:30:26 -040079 * There will be no clients connected.
Jim King5ec805b2015-04-26 07:52:40 -040080 */
Mark Sleeb3cb6292007-02-01 22:55:00 +000081 virtual void serve();
Jim King5ec805b2015-04-26 07:52:40 -040082
Konrad Grochowski16a23a62014-11-13 15:33:38 +010083protected:
Jim King21b68522015-04-26 18:30:26 -040084 virtual void onClientConnected(const boost::shared_ptr<TConnectedClient>& pClient) /* override */;
85 virtual void onClientDisconnected(TConnectedClient *pClient) /* override */;
Bryan Duxbury7a9fb812011-09-01 18:31:53 +000086
Jim King21b68522015-04-26 18:30:26 -040087 boost::shared_ptr<apache::thrift::concurrency::ThreadFactory> threadFactory_;
88 apache::thrift::concurrency::Monitor clientsMonitor_;
Jim King5ec805b2015-04-26 07:52:40 -040089 std::set<TConnectedClient*> clients_;
Mark Sleeb3cb6292007-02-01 22:55:00 +000090};
91
Konrad Grochowski16a23a62014-11-13 15:33:38 +010092}
93}
94} // apache::thrift::server
Mark Sleeb3cb6292007-02-01 22:55:00 +000095
96#endif // #ifndef _THRIFT_SERVER_TTHREADEDSERVER_H_