Trait thrift::server::TProcessor
[−]
[src]
pub trait TProcessor { fn process(&mut self,
i: &mut TInputProtocol,
o: &mut TOutputProtocol)
-> Result<()>; }
Handles incoming Thrift messages and dispatches them to the user-defined handler functions.
An implementation is auto-generated for each Thrift service. When used by a
server (for example, a TSimpleServer
), it will demux incoming service
calls and invoke the corresponding user-defined handler function.
Examples
Create and start a server using the auto-generated TProcessor
for
a Thrift service SimpleService
.
use thrift; use thrift::protocol::{TInputProtocol, TOutputProtocol}; use thrift::server::TProcessor; // // auto-generated // // processor for `SimpleService` struct SimpleServiceSyncProcessor; impl SimpleServiceSyncProcessor { fn new<H: SimpleServiceSyncHandler>(processor: H) -> SimpleServiceSyncProcessor { unimplemented!(); } } // `TProcessor` implementation for `SimpleService` impl TProcessor for SimpleServiceSyncProcessor { fn process(&mut self, i: &mut TInputProtocol, o: &mut TOutputProtocol) -> thrift::Result<()> { unimplemented!(); } } // service functions for SimpleService trait SimpleServiceSyncHandler { fn service_call(&mut self) -> thrift::Result<()>; } // // user-code follows // // define a handler that will be invoked when `service_call` is received struct SimpleServiceHandlerImpl; impl SimpleServiceSyncHandler for SimpleServiceHandlerImpl { fn service_call(&mut self) -> thrift::Result<()> { unimplemented!(); } } // instantiate the processor let processor = SimpleServiceSyncProcessor::new(SimpleServiceHandlerImpl {}); // at this point you can pass the processor to the server // let server = TSimpleServer::new(..., processor);
Required Methods
fn process(&mut self,
i: &mut TInputProtocol,
o: &mut TOutputProtocol)
-> Result<()>
i: &mut TInputProtocol,
o: &mut TOutputProtocol)
-> Result<()>
Process a Thrift service call.
Reads arguments from i
, executes the user's handler code, and writes
the response to o
.
Returns ()
if the handler was executed; Err
otherwise.
Implementors
impl TProcessor for TMultiplexedProcessor