Skip to main content

camel_api/
route_controller.rs

1//! Route lifecycle management types.
2//!
3//! This module provides the [`RouteController`] trait for managing route lifecycle
4//! (start, stop, suspend, resume) and the [`RouteStatus`] and [`RouteAction`] enums
5//! for tracking and controlling route state.
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 of this trait provide the ability to start, stop, suspend,
47/// resume, and query the status of routes within a Camel context.
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    /// Get the current status of a route by its ID.
86    ///
87    /// Returns `None` if the route does not exist.
88    fn route_status(&self, route_id: &str) -> Option<RouteStatus>;
89
90    /// Start all routes in the context.
91    ///
92    /// # Errors
93    ///
94    /// Returns a `CamelError` if any route cannot be started.
95    async fn start_all_routes(&mut self) -> Result<(), CamelError>;
96
97    /// Stop all routes in the context.
98    ///
99    /// # Errors
100    ///
101    /// Returns a `CamelError` if any route cannot be stopped.
102    async fn stop_all_routes(&mut self) -> Result<(), CamelError>;
103}