Class TMultiplexedProtocol

  • All Implemented Interfaces:
    TReadProtocol, TWriteProtocol

    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 Detail

      • SEPARATOR

        public static final java.lang.String SEPARATOR
        Used to delimit the service name from the function name
        See Also:
        Constant Field Values
    • Constructor Detail

      • 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.