org.apache.thrift.protocol
Class TMultiplexedProtocol
java.lang.Object
org.apache.thrift.protocol.TProtocol
org.apache.thrift.protocol.TProtocolDecorator
org.apache.thrift.protocol.TMultiplexedProtocol
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());
- See Also:
TProtocolDecorator
Field Summary |
static java.lang.String |
SEPARATOR
Used to delimit the service name from the function name |
Constructor Summary |
TMultiplexedProtocol(TProtocol protocol,
java.lang.String serviceName)
Wrap the specified protocol, allowing it to be used to communicate with a
multiplexing server. |
Method Summary |
void |
writeMessageBegin(TMessage tMessage)
Prepends the service name to the function name, separated by TMultiplexedProtocol.SEPARATOR. |
Methods inherited from class org.apache.thrift.protocol.TProtocolDecorator |
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, writeStructEnd |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SEPARATOR
public static final java.lang.String SEPARATOR
- Used to delimit the service name from the function name
- See Also:
- Constant Field Values
TMultiplexedProtocol
public TMultiplexedProtocol(TProtocol protocol,
java.lang.String serviceName)
- Wrap the specified protocol, allowing it to be used to communicate with a
multiplexing server. The
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.
- Parameters:
protocol
- Your communication protocol of choice, e.g. TBinaryProtocol
.serviceName
- The service name of the service communicating via this protocol.
writeMessageBegin
public void writeMessageBegin(TMessage tMessage)
throws TException
- Prepends the service name to the function name, separated by TMultiplexedProtocol.SEPARATOR.
- Overrides:
writeMessageBegin
in class TProtocolDecorator
- Parameters:
tMessage
- The original message.
- Throws:
TException
- Passed through from wrapped TProtocol
instance.