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