Trait thrift::server::TProcessor

source ·
pub trait TProcessor {
    // Required method
    fn process(
        &self,
        i: &mut dyn TInputProtocol,
        o: &mut dyn TOutputProtocol
    ) -> Result<()>;
}
Expand description

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::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(&self, i: &mut dyn TInputProtocol, o: &mut dyn TOutputProtocol) -> thrift::Result<()> {
        unimplemented!();
    }
}

// service functions for SimpleService
trait SimpleServiceSyncHandler {
    fn service_call(&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(&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 = TServer::new(..., processor);

Required Methods§

source

fn process( &self, i: &mut dyn TInputProtocol, o: &mut dyn 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§