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 | |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 20 | #include <thrift/server/TSimpleServer.h> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 21 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 22 | namespace apache { |
| 23 | namespace thrift { |
| 24 | namespace server { |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 25 | |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 26 | using apache::thrift::protocol::TProtocol; |
| 27 | using apache::thrift::protocol::TProtocolFactory; |
| 28 | using apache::thrift::transport::TServerTransport; |
| 29 | using apache::thrift::transport::TTransport; |
| 30 | using apache::thrift::transport::TTransportException; |
| 31 | using apache::thrift::transport::TTransportFactory; |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 32 | using std::shared_ptr; |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 33 | using std::string; |
| 34 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 35 | TSimpleServer::TSimpleServer(const shared_ptr<TProcessorFactory>& processorFactory, |
| 36 | const shared_ptr<TServerTransport>& serverTransport, |
| 37 | const shared_ptr<TTransportFactory>& transportFactory, |
| 38 | const shared_ptr<TProtocolFactory>& protocolFactory) |
| 39 | : TServerFramework(processorFactory, serverTransport, transportFactory, protocolFactory) { |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 40 | TServerFramework::setConcurrentClientLimit(1); |
| 41 | } |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 42 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 43 | TSimpleServer::TSimpleServer(const shared_ptr<TProcessor>& processor, |
| 44 | const shared_ptr<TServerTransport>& serverTransport, |
| 45 | const shared_ptr<TTransportFactory>& transportFactory, |
| 46 | const shared_ptr<TProtocolFactory>& protocolFactory) |
| 47 | : TServerFramework(processor, serverTransport, transportFactory, protocolFactory) { |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 48 | TServerFramework::setConcurrentClientLimit(1); |
| 49 | } |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 50 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 51 | TSimpleServer::TSimpleServer(const shared_ptr<TProcessorFactory>& processorFactory, |
| 52 | const shared_ptr<TServerTransport>& serverTransport, |
| 53 | const shared_ptr<TTransportFactory>& inputTransportFactory, |
| 54 | const shared_ptr<TTransportFactory>& outputTransportFactory, |
| 55 | const shared_ptr<TProtocolFactory>& inputProtocolFactory, |
| 56 | const shared_ptr<TProtocolFactory>& outputProtocolFactory) |
| 57 | : TServerFramework(processorFactory, |
| 58 | serverTransport, |
| 59 | inputTransportFactory, |
| 60 | outputTransportFactory, |
| 61 | inputProtocolFactory, |
| 62 | outputProtocolFactory) { |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 63 | TServerFramework::setConcurrentClientLimit(1); |
| 64 | } |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 65 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 66 | TSimpleServer::TSimpleServer(const shared_ptr<TProcessor>& processor, |
| 67 | const shared_ptr<TServerTransport>& serverTransport, |
| 68 | const shared_ptr<TTransportFactory>& inputTransportFactory, |
| 69 | const shared_ptr<TTransportFactory>& outputTransportFactory, |
| 70 | const shared_ptr<TProtocolFactory>& inputProtocolFactory, |
| 71 | const shared_ptr<TProtocolFactory>& outputProtocolFactory) |
| 72 | : TServerFramework(processor, |
| 73 | serverTransport, |
| 74 | inputTransportFactory, |
| 75 | outputTransportFactory, |
| 76 | inputProtocolFactory, |
| 77 | outputProtocolFactory) { |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 78 | TServerFramework::setConcurrentClientLimit(1); |
| 79 | } |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 80 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 81 | TSimpleServer::~TSimpleServer() = default; |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 82 | |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 83 | /** |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 84 | * The main body of customized implementation for TSimpleServer is quite simple: |
| 85 | * When a client connects, use the serve() thread to drive it to completion thus |
| 86 | * blocking new connections. |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 87 | */ |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 88 | void TSimpleServer::onClientConnected(const shared_ptr<TConnectedClient>& pClient) { |
| 89 | pClient->run(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 90 | } |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 91 | |
Jim King | 21b6852 | 2015-04-26 18:30:26 -0400 | [diff] [blame] | 92 | /** |
| 93 | * TSimpleServer does not track clients so there is nothing to do here. |
| 94 | */ |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 95 | void TSimpleServer::onClientDisconnected(TConnectedClient*) { |
| 96 | } |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 97 | |
Jim King | 79c9911 | 2015-04-30 07:10:08 -0400 | [diff] [blame] | 98 | /** |
| 99 | * This makes little sense to the simple server because it is not capable |
| 100 | * of having more than one client at a time, so we hide it. |
| 101 | */ |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 102 | void TSimpleServer::setConcurrentClientLimit(int64_t) { |
| 103 | } |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | } // apache::thrift::server |