Package org.apache.thrift
Class TMultiplexedProcessor
- java.lang.Object
-
- org.apache.thrift.TMultiplexedProcessor
-
- All Implemented Interfaces:
TProcessor
public class TMultiplexedProcessor extends java.lang.Object implements TProcessor
TMultiplexedProcessoris aTProcessorallowing a singleTServerto provide multiple services.To do so, you instantiate the processor and then register additional processors with it, as shown in the following example:
TMultiplexedProcessor processor = new TMultiplexedProcessor(); processor.registerProcessor( "Calculator", new Calculator.Processor(new CalculatorHandler())); processor.registerProcessor( "WeatherReport", new WeatherReport.Processor(new WeatherReportHandler())); TServerTransport t = new TServerSocket(9090); TSimpleServer server = new TSimpleServer(processor, t); server.serve();
-
-
Constructor Summary
Constructors Constructor Description TMultiplexedProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidprocess(TProtocol iprot, TProtocol oprot)This implementation ofprocessperforms the following steps: Read the beginning of the message. Extract the service name from the message. Using the service name to locate the appropriate processor. Dispatch to the processor, with a decorated instance of TProtocol that allows readMessageBegin() to return the original TMessage.voidregisterDefault(TProcessor processor)Register a service to be called to process queries without service namevoidregisterProcessor(java.lang.String serviceName, TProcessor processor)'Register' a service with thisTMultiplexedProcessor.
-
-
-
Method Detail
-
registerProcessor
public void registerProcessor(java.lang.String serviceName, TProcessor processor)'Register' a service with thisTMultiplexedProcessor. This allows us to broker requests to individual services by using the service name to select them at request time.- Parameters:
serviceName- Name of a service, has to be identical to the name declared in the Thrift IDL, e.g. "WeatherReport".processor- Implementation of a service, usually referred to as "handlers", e.g. WeatherReportHandler implementing WeatherReport.Iface.
-
registerDefault
public void registerDefault(TProcessor processor)
Register a service to be called to process queries without service name- Parameters:
processor-
-
process
public void process(TProtocol iprot, TProtocol oprot) throws TException
This implementation ofprocessperforms the following steps:- Read the beginning of the message.
- Extract the service name from the message.
- Using the service name to locate the appropriate processor.
- Dispatch to the processor, with a decorated instance of TProtocol that allows readMessageBegin() to return the original TMessage.
- Specified by:
processin interfaceTProcessor- Throws:
TProtocolException- If the message type is not CALL or ONEWAY, if the service name was not found in the message, or if the service name was not found in the service map. You calledregisterProcessorduring initialization, right? :)TException
-
-