|
|
|||
File indexing completed on 2026-04-17 08:35:02
0001 /* 0002 * Licensed to the Apache Software Foundation (ASF) under one 0003 * or more contributor license agreements. See the NOTICE file 0004 * distributed with this work for additional information 0005 * regarding copyright ownership. The ASF licenses this file 0006 * to you under the Apache License, Version 2.0 (the 0007 * "License"); you may not use this file except in compliance 0008 * with the License. You may obtain a copy of the License at 0009 * 0010 * http://www.apache.org/licenses/LICENSE-2.0 0011 * 0012 * Unless required by applicable law or agreed to in writing, 0013 * software distributed under the License is distributed on an 0014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 0015 * KIND, either express or implied. See the License for the 0016 * specific language governing permissions and limitations 0017 * under the License. 0018 */ 0019 0020 #ifndef THRIFT_TMULTIPLEXEDPROTOCOL_H_ 0021 #define THRIFT_TMULTIPLEXEDPROTOCOL_H_ 1 0022 0023 #include <thrift/protocol/TProtocolDecorator.h> 0024 0025 namespace apache { 0026 namespace thrift { 0027 namespace protocol { 0028 using std::shared_ptr; 0029 0030 /** 0031 * <code>TMultiplexedProtocol</code> is a protocol-independent concrete decorator 0032 * that allows a Thrift client to communicate with a multiplexing Thrift server, 0033 * by prepending the service name to the function name during function calls. 0034 * 0035 * \note THIS IS NOT USED BY SERVERS. On the server, use 0036 * {@link apache::thrift::TMultiplexedProcessor TMultiplexedProcessor} to handle requests 0037 * from a multiplexing client. 0038 * 0039 * This example uses a single socket transport to invoke two services: 0040 * 0041 * <blockquote><code> 0042 * shared_ptr<TSocket> transport(new TSocket("localhost", 9090)); 0043 * transport->open(); 0044 * 0045 * shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport)); 0046 * 0047 * shared_ptr<TMultiplexedProtocol> mp1(new TMultiplexedProtocol(protocol, "Calculator")); 0048 * shared_ptr<CalculatorClient> service1(new CalculatorClient(mp1)); 0049 * 0050 * shared_ptr<TMultiplexedProtocol> mp2(new TMultiplexedProtocol(protocol, "WeatherReport")); 0051 * shared_ptr<WeatherReportClient> service2(new WeatherReportClient(mp2)); 0052 * 0053 * service1->add(2,2); 0054 * int temp = service2->getTemperature(); 0055 * </code></blockquote> 0056 * 0057 * @see apache::thrift::protocol::TProtocolDecorator 0058 */ 0059 class TMultiplexedProtocol : public TProtocolDecorator { 0060 public: 0061 /** 0062 * Wrap the specified protocol, allowing it to be used to communicate with a 0063 * multiplexing server. The <code>serviceName</code> is required as it is 0064 * prepended to the message header so that the multiplexing server can broker 0065 * the function call to the proper service. 0066 * 0067 * \param _protocol Your communication protocol of choice, e.g. <code>TBinaryProtocol</code>. 0068 * \param _serviceName The service name of the service communicating via this protocol. 0069 */ 0070 TMultiplexedProtocol(shared_ptr<TProtocol> _protocol, const std::string& _serviceName) 0071 : TProtocolDecorator(_protocol), serviceName(_serviceName), separator(":") {} 0072 ~TMultiplexedProtocol() override = default; 0073 0074 /** 0075 * Prepends the service name to the function name, separated by TMultiplexedProtocol::SEPARATOR. 0076 * 0077 * \param [in] _name The name of the method to be called in the service. 0078 * \param [in] _type The type of message 0079 * \param [in] _name The sequential id of the message 0080 * 0081 * \throws TException Passed through from wrapped <code>TProtocol</code> instance. 0082 */ 0083 uint32_t writeMessageBegin_virt(const std::string& _name, 0084 const TMessageType _type, 0085 const int32_t _seqid) override; 0086 0087 private: 0088 const std::string serviceName; 0089 const std::string separator; 0090 }; 0091 } 0092 } 0093 } 0094 0095 #endif // THRIFT_TMULTIPLEXEDPROTOCOL_H_
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|