Add OrchestratableService and -Factory traits
This change adds an OrchestratableService and associated factory traits.
These services provide additional method requirements on top of the
Service trait that are needed for the Orchestrator to move and share
services amongst threads.
@@ -71,6 +71,35 @@ impl std::fmt::Display for ServiceDefinition {
}
}
+/// A service that may be orchestratable.
+///
+/// This service has several stronger requirements, mainly required moving and sharing a service
+/// instance among threads.
+pub trait OrchestratableService: Service {
+ fn clone_box(&self) -> Box<dyn OrchestratableService>;
+
+ fn as_service(&self) -> &dyn Service;
+}
+
+impl Clone for Box<dyn OrchestratableService> {
+ fn clone(&self) -> Self {
+ self.clone_box()
+ }
+}
+
+/// A service factory that produces orchestratable services.
+pub trait OrchestratableServiceFactory: ServiceFactory {
+ /// Create a Service instance with the given ID, of the given type, the given circuit_id,
+ /// with the given arguments.
+ fn create_orchestratable_service(
+ &self,
+ service_id: String,
+ service_type: &str,
+ circuit_id: &str,
+ args: HashMap<String, String>,
+ ) -> Result<Box<dyn OrchestratableService>, FactoryCreateError>;
+}
+
/// Stores a service and other structures that are used to manage it
struct ManagedService {
pub service: Box<dyn Service>,
