blob: cdacfd7851def141cc0aa703a2ba952da99b61d2 [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/**
33 * Manage clients using a thread pool.
34 */
35class TThreadedServer : public TServerFramework {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010036public:
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020037 TThreadedServer(
38 const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory,
39 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
40 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory,
41 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory,
42 const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory
43 = boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>(
44 new apache::thrift::concurrency::PlatformThreadFactory));
Mark Sleeb3cb6292007-02-01 22:55:00 +000045
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020046 TThreadedServer(
47 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
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020055 TThreadedServer(
56 const boost::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory,
57 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
58 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
59 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
60 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
61 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory,
62 const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory
63 = boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>(
64 new apache::thrift::concurrency::PlatformThreadFactory));
Bryan Duxbury7a9fb812011-09-01 18:31:53 +000065
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020066 TThreadedServer(
67 const boost::shared_ptr<apache::thrift::TProcessor>& processor,
68 const boost::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
69 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
70 const boost::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
71 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
72 const boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory,
73 const boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>& threadFactory
74 = boost::shared_ptr<apache::thrift::concurrency::ThreadFactory>(
75 new apache::thrift::concurrency::PlatformThreadFactory));
David Reiss45d56962009-03-14 23:35:16 +000076
Mark Sleeb3cb6292007-02-01 22:55:00 +000077 virtual ~TThreadedServer();
78
Jim King5ec805b2015-04-26 07:52:40 -040079 /**
Jim King5ec805b2015-04-26 07:52:40 -040080 * Post-conditions (return guarantees):
Jim King21b68522015-04-26 18:30:26 -040081 * There will be no clients connected.
Jim King5ec805b2015-04-26 07:52:40 -040082 */
Mark Sleeb3cb6292007-02-01 22:55:00 +000083 virtual void serve();
Jim King5ec805b2015-04-26 07:52:40 -040084
Konrad Grochowski16a23a62014-11-13 15:33:38 +010085protected:
Jim King21b68522015-04-26 18:30:26 -040086 virtual void onClientConnected(const boost::shared_ptr<TConnectedClient>& pClient) /* override */;
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020087 virtual void onClientDisconnected(TConnectedClient* pClient) /* override */;
Bryan Duxbury7a9fb812011-09-01 18:31:53 +000088
Jim King21b68522015-04-26 18:30:26 -040089 boost::shared_ptr<apache::thrift::concurrency::ThreadFactory> threadFactory_;
90 apache::thrift::concurrency::Monitor clientsMonitor_;
Mark Sleeb3cb6292007-02-01 22:55:00 +000091};
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_