public class TMultiplexedProtocol extends TProtocolDecorator
TMultiplexedProtocol is a protocol-independent concrete decorator
that allows a Thrift client to communicate with a multiplexing Thrift server,
by prepending the service name to the function name during function calls.
NOTE: THIS IS NOT USED BY SERVERS. On the server, use TMultiplexedProcessor to handle requests
from a multiplexing client.
This example uses a single socket transport to invoke two services:
TSocket transport = new TSocket("localhost", 9090);
transport.open();
TBinaryProtocol protocol = new TBinaryProtocol(transport);
TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "Calculator");
Calculator.Client service = new Calculator.Client(mp);
TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, "WeatherReport");
WeatherReport.Client service2 = new WeatherReport.Client(mp2);
System.out.println(service.add(2,2));
System.out.println(service2.getTemperature());
TProtocolDecorator| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
SEPARATOR
Used to delimit the service name from the function name
|
| Constructor and Description |
|---|
TMultiplexedProtocol(TProtocol protocol,
java.lang.String serviceName)
Wrap the specified protocol, allowing it to be used to communicate with a
multiplexing server.
|
| Modifier and Type | Method and Description |
|---|---|
void |
writeMessageBegin(TMessage tMessage)
Prepends the service name to the function name, separated by TMultiplexedProtocol.SEPARATOR.
|
readBinary, readBool, readByte, readDouble, readFieldBegin, readFieldEnd, readI16, readI32, readI64, readListBegin, readListEnd, readMapBegin, readMapEnd, readMessageBegin, readMessageEnd, readSetBegin, readSetEnd, readString, readStructBegin, readStructEnd, writeBinary, writeBool, writeByte, writeDouble, writeFieldBegin, writeFieldEnd, writeFieldStop, writeI16, writeI32, writeI64, writeListBegin, writeListEnd, writeMapBegin, writeMapEnd, writeMessageEnd, writeSetBegin, writeSetEnd, writeString, writeStructBegin, writeStructEndgetScheme, getTransport, resetpublic static final java.lang.String SEPARATOR
public TMultiplexedProtocol(TProtocol protocol, java.lang.String serviceName)
serviceName is required as it is
prepended to the message header so that the multiplexing server can broker
the function call to the proper service.protocol - Your communication protocol of choice, e.g. TBinaryProtocol.serviceName - The service name of the service communicating via this protocol.public void writeMessageBegin(TMessage tMessage) throws TException
writeMessageBegin in class TProtocolDecoratortMessage - The original message.TException - Passed through from wrapped TProtocol instance.