camel_api/route_controller.rs
1//! Route lifecycle management types.
2//!
3//! This module provides the [`RouteController`] trait for managing route lifecycle
4//! operations (start, stop, suspend, resume) plus [`RouteStatus`] and [`RouteAction`]
5//! enums used by runtime-facing APIs.
6
7use crate::CamelError;
8use async_trait::async_trait;
9
10/// Represents the current lifecycle status of a route.
11#[derive(Debug, Clone, PartialEq, Eq)]
12#[non_exhaustive]
13pub enum RouteStatus {
14 /// Route is stopped and not running.
15 Stopped,
16 /// Route is in the process of starting.
17 Starting,
18 /// Route is running and processing messages.
19 Started,
20 /// Route is in the process of stopping.
21 Stopping,
22 /// Route is suspended (temporarily paused).
23 Suspended,
24 /// Route has failed with an error message.
25 Failed(String),
26}
27
28/// Represents actions that can be performed on a route.
29#[derive(Debug, Clone)]
30#[non_exhaustive]
31pub enum RouteAction {
32 /// Start the route.
33 Start,
34 /// Stop the route.
35 Stop,
36 /// Suspend the route (pause without full shutdown).
37 Suspend,
38 /// Resume a suspended route.
39 Resume,
40 /// Restart the route (stop then start).
41 Restart,
42 /// Get the current status of the route.
43 Status,
44}
45
46/// Trait for managing route lifecycle operations.
47///
48/// Implementations provide imperative execution operations only; canonical
49/// lifecycle state is exposed via runtime query APIs.
50#[async_trait]
51pub trait RouteController: Send + Sync {
52 /// Start a specific route by its ID.
53 ///
54 /// # Errors
55 ///
56 /// Returns a `CamelError` if the route cannot be started.
57 async fn start_route(&mut self, route_id: &str) -> Result<(), CamelError>;
58
59 /// Stop a specific route by its ID.
60 ///
61 /// # Errors
62 ///
63 /// Returns a `CamelError` if the route cannot be stopped.
64 async fn stop_route(&mut self, route_id: &str) -> Result<(), CamelError>;
65
66 /// Restart a specific route by its ID.
67 ///
68 /// # Errors
69 ///
70 /// Returns a `CamelError` if the route cannot be restarted.
71 async fn restart_route(&mut self, route_id: &str) -> Result<(), CamelError>;
72
73 /// Suspend a specific route by its ID.
74 ///
75 /// # Errors
76 ///
77 /// Returns a `CamelError` if the route cannot be suspended.
78 async fn suspend_route(&mut self, route_id: &str) -> Result<(), CamelError>;
79
80 /// Resume a suspended route by its ID.
81 ///
82 /// # Errors
83 ///
84 /// Returns a `CamelError` if the route cannot be resumed.
85 async fn resume_route(&mut self, route_id: &str) -> Result<(), CamelError>;
86
87 /// Start all routes in the context.
88 ///
89 /// # Errors
90 ///
91 /// Returns a `CamelError` if any route cannot be started.
92 async fn start_all_routes(&mut self) -> Result<(), CamelError>;
93
94 /// Stop all routes in the context.
95 ///
96 /// # Errors
97 ///
98 /// Returns a `CamelError` if any route cannot be stopped.
99 async fn stop_all_routes(&mut self) -> Result<(), CamelError>;
100}