]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/haxe/src/org/apache/thrift/protocol/TMultiplexedProtocol.hx
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / haxe / src / org / apache / thrift / protocol / TMultiplexedProtocol.hx
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 package org.apache.thrift.protocol;
21
22 import org.apache.thrift.transport.TTransport;
23
24
25 /**
26 * TMultiplexedProtocol is a protocol-independent concrete decorator that allows a Thrift
27 * client to communicate with a multiplexing Thrift server, by prepending the service name
28 * to the function name during function calls.
29 *
30 * NOTE: THIS IS NOT TO BE USED BY SERVERS.
31 * On the server, use TMultiplexedProcessor to handle requests from a multiplexing client.
32 *
33 * This example uses a single socket transport to invoke two services:
34 *
35 * TSocket transport = new TSocket("localhost", 9090);
36 * transport.open();
37 *
38 * TBinaryProtocol protocol = new TBinaryProtocol(transport);
39 *
40 * TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "Calculator");
41 * Calculator.Client service = new Calculator.Client(mp);
42 *
43 * TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, "WeatherReport");
44 * WeatherReport.Client service2 = new WeatherReport.Client(mp2);
45 *
46 * System.out.println(service.add(2,2));
47 * System.out.println(service2.getTemperature());
48 *
49 */
50 class TMultiplexedProtocol extends TProtocolDecorator {
51
52 /** Used to delimit the service name from the function name */
53 public static inline var SEPARATOR : String = ":";
54
55 private var service : String;
56
57 /**
58 * Wrap the specified protocol, allowing it to be used to communicate with a
59 * multiplexing server. The <code>serviceName</code> is required as it is
60 * prepended to the message header so that the multiplexing server can broker
61 * the function call to the proper service.
62 *
63 * Args:
64 * protocol Your communication protocol of choice, e.g. TBinaryProtocol
65 * serviceName The service name of the service communicating via this protocol.
66 */
67 public function new( protocol : TProtocol, serviceName : String) {
68 super( protocol);
69 service = serviceName;
70 }
71
72 /**
73 * Prepends the service name to the function name, separated by TMultiplexedProtocol.SEPARATOR.
74 * Args:
75 * tMessage The original message.
76 */
77 public override function writeMessageBegin( message : TMessage) : Void {
78 switch( message.type)
79 {
80 case TMessageType.CALL:
81 super.writeMessageBegin(new TMessage(
82 service + SEPARATOR + message.name,
83 message.type,
84 message.seqid));
85
86 case TMessageType.ONEWAY:
87 super.writeMessageBegin(new TMessage(
88 service + SEPARATOR + message.name,
89 message.type,
90 message.seqid));
91
92 default:
93 super.writeMessageBegin(message);
94 }
95 }
96 }
97