]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/java/src/org/apache/thrift/protocol/TMultiplexedProtocol.java
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 package org
.apache
.thrift
.protocol
;
22 import org
.apache
.thrift
.TException
;
25 * <code>TMultiplexedProtocol</code> is a protocol-independent concrete decorator
26 * that allows a Thrift client to communicate with a multiplexing Thrift server,
27 * by prepending the service name to the function name during function calls.
29 * <p>NOTE: THIS IS NOT USED BY SERVERS. On the server, use {@link org.apache.thrift.TMultiplexedProcessor TMultiplexedProcessor} to handle requests
30 * from a multiplexing client.
32 * <p>This example uses a single socket transport to invoke two services:
36 * TSocket transport = new TSocket("localhost", 9090);
39 * TBinaryProtocol protocol = new TBinaryProtocol(transport);
41 * TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "Calculator");
42 * Calculator.Client service = new Calculator.Client(mp);
44 * TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, "WeatherReport");
45 * WeatherReport.Client service2 = new WeatherReport.Client(mp2);
47 * System.out.println(service.add(2,2));
48 * System.out.println(service2.getTemperature());
52 * @see org.apache.thrift.protocol.TProtocolDecorator
54 public class TMultiplexedProtocol
extends TProtocolDecorator
{
56 /** Used to delimit the service name from the function name */
57 public static final String SEPARATOR
= ":";
59 private final String SERVICE_NAME
;
62 * Wrap the specified protocol, allowing it to be used to communicate with a
63 * multiplexing server. The <code>serviceName</code> is required as it is
64 * prepended to the message header so that the multiplexing server can broker
65 * the function call to the proper service.
67 * @param protocol Your communication protocol of choice, e.g. <code>TBinaryProtocol</code>.
68 * @param serviceName The service name of the service communicating via this protocol.
70 public TMultiplexedProtocol(TProtocol protocol
, String serviceName
) {
72 SERVICE_NAME
= serviceName
;
76 * Prepends the service name to the function name, separated by TMultiplexedProtocol.SEPARATOR.
78 * @param tMessage The original message.
79 * @throws TException Passed through from wrapped <code>TProtocol</code> instance.
82 public void writeMessageBegin(TMessage tMessage
) throws TException
{
83 if (tMessage
.type
== TMessageType
.CALL
|| tMessage
.type
== TMessageType
.ONEWAY
) {
84 super.writeMessageBegin(new TMessage(
85 SERVICE_NAME
+ SEPARATOR
+ tMessage
.name
,
90 super.writeMessageBegin(tMessage
);