pub trait SyncServlet {
type ProtocolType: ProtocolModel;
type DataModelType: DataModel<Self::ProtocolType>;
// Required methods
fn init(
&mut self,
args: &[&str],
proto_model: &mut Self::ProtocolType,
) -> ServletFuncResult;
fn exec(&mut self, data_model: Self::DataModelType) -> ServletFuncResult;
fn cleanup(&mut self) -> ServletFuncResult;
}
Expand description
The trait for a synchronous servlet.
A sync servlet is a servlet occupies the worker thread during execution. This is the most common form of servlet. However, when there are some blocking operations needs to be done by the servlet, this model is really ineffecient because it blocks the worker thread completely and reduces the system throughput.
Required Associated Types§
Sourcetype ProtocolType: ProtocolModel
type ProtocolType: ProtocolModel
The type used to represent the protocol.
This protocol type is ususally build by the macro protodef!
.
type DataModelType: DataModel<Self::ProtocolType>
Required Methods§
Sourcefn init(
&mut self,
args: &[&str],
proto_model: &mut Self::ProtocolType,
) -> ServletFuncResult
fn init( &mut self, args: &[&str], proto_model: &mut Self::ProtocolType, ) -> ServletFuncResult
The initialization function.
This should be called by the Plumber framework before the application gets started. All the pipe declaration should be done in this function.
args
: The servlet init argument listproto_model
: The protocol model object for this servlet
Return the result of the servlet
Sourcefn exec(&mut self, data_model: Self::DataModelType) -> ServletFuncResult
fn exec(&mut self, data_model: Self::DataModelType) -> ServletFuncResult
The sync execute function.
This should be called by Plumber framework when the framework decide to activate the servlet due to some input event. This function will be called from any worker thread.
data_model
: The data model object which can be used to access the typed data
Return The servlet function result.
Sourcefn cleanup(&mut self) -> ServletFuncResult
fn cleanup(&mut self) -> ServletFuncResult
The cleanup function
This should be called by Plumber framework when the Plumber application gets either killed or upgraded (and new version of the binary is loaded).
Return the servlet function result.