Skip to main content

camel_core/lifecycle/adapters/
runtime_execution.rs

1use std::sync::Arc;
2
3use async_trait::async_trait;
4use tokio::sync::Mutex;
5
6use camel_api::CamelError;
7
8use crate::lifecycle::adapters::route_controller::RouteControllerInternal;
9use crate::lifecycle::application::RouteDefinition;
10use crate::lifecycle::ports::RuntimeExecutionPort;
11
12/// Runtime side-effect adapter backed by the technical route controller.
13#[derive(Clone)]
14pub struct RuntimeExecutionAdapter {
15    controller: Arc<Mutex<dyn RouteControllerInternal>>,
16}
17
18impl RuntimeExecutionAdapter {
19    pub fn new(controller: Arc<Mutex<dyn RouteControllerInternal>>) -> Self {
20        Self { controller }
21    }
22}
23
24#[async_trait]
25impl RuntimeExecutionPort for RuntimeExecutionAdapter {
26    async fn register_route(&self, definition: RouteDefinition) -> Result<(), CamelError> {
27        let mut controller = self.controller.lock().await;
28        controller.add_route(definition)
29    }
30
31    async fn start_route(&self, route_id: &str) -> Result<(), CamelError> {
32        let mut controller = self.controller.lock().await;
33        controller.start_route(route_id).await
34    }
35
36    async fn stop_route(&self, route_id: &str) -> Result<(), CamelError> {
37        let mut controller = self.controller.lock().await;
38        controller.stop_route(route_id).await
39    }
40
41    async fn suspend_route(&self, route_id: &str) -> Result<(), CamelError> {
42        let mut controller = self.controller.lock().await;
43        controller.suspend_route(route_id).await
44    }
45
46    async fn resume_route(&self, route_id: &str) -> Result<(), CamelError> {
47        let mut controller = self.controller.lock().await;
48        controller.resume_route(route_id).await
49    }
50
51    async fn reload_route(&self, route_id: &str) -> Result<(), CamelError> {
52        let mut controller = self.controller.lock().await;
53        controller.restart_route(route_id).await
54    }
55
56    async fn remove_route(&self, route_id: &str) -> Result<(), CamelError> {
57        let mut controller = self.controller.lock().await;
58        controller.remove_route(route_id)
59    }
60}