concept processor in category apache thrift

appears as: processor, The processor, Processors, processor
Programmer's Guide to Apache Thrift

This is an excerpt from Manning's book Programmer's Guide to Apache Thrift.

Next we create an instance of our handler and use it to initialize a processor for our service. The processor is the server-side stub generated by the IDL compiler that turns network service requests into calls to the appropriate handler function 4.

Once a client does connect, we need to process RPC calls made over the connection. The inner while loop uses the processor process() method to process client RPC requests 6. The process() method takes care of everything required to process one RPC request. The process() method will read the client’s RPC message from the network, determine which handler method to call, unpack the parameters using the I/O stack, and call the handler. When the handler returns with a result, the processor serializes the result back to the client using the I/O stack. The inner loop breaks when the client disconnects, which causes the process() method to return 0 6.

Note that the TProcessor process() method takes three parameters, proc.process (proto, proto, and nullptr). In this example, we pass the protocol twice. The processor uses the first parameter for reading and the second for writing. We’ll look at in/out protocol stacks in detail in section 10.4, “Using factories.” The third parameter to the process() method is the Processor context, which we’re not supporting in our simple server. This parameter works in conjunction with an optional TProcessorEventHandler. Processor event handlers allow us to hook processor events (pre/post I/O stack read/write operations) without hacking the Apache Thrift source code. You can find a processor event handler example in chapter 8, “Implementing services.”

Figure 10.19. Servers create separate input and output protocol/transport stacks for use with processors.
  • Factories are used by servers to generate transports, protocols, processors, handlers, and threads in response to client requests.