surrealcs_kernel/messages/client/router.rs
1//! the message structs that are strictly just for the client (we should aim to completely remove these)
2use nanoservices_utils::errors::NanoServiceError;
3use tokio::sync::mpsc;
4use tokio::sync::oneshot;
5
6use crate::messages::client::message::TransactionMessage;
7
8/// The messsage wrapper to enable returning a response to the sender.
9///
10/// # Fields
11/// * `message`: The message to be sent to the router
12/// * `tx`: the sender to send the response back to the initial sender from the router actor
13pub struct WrappedRouterMessage {
14 pub message: RouterMessage,
15 pub tx: oneshot::Sender<RouterMessage>,
16}
17
18/// The message to be sent to the router.
19///
20/// # Variants
21/// * `MakeConnection`: to make a connection using the string as the URL
22/// * `ConnectionCreated`: a clarification of the connection created with the index of the allocator
23/// * `GetConnection`: to get a random connection
24/// * `ReturnConnection`: returns a random collection from the `GetConnection` request
25/// * `CloseConnection`: to close the connection that belongs to the index
26/// * `ConnectionClosed`: a confirmation that the connection is closed
27/// * `Error`: an error
28/// * `ShutdownConnectionPool`: shuts down the connection pool
29#[derive(Debug)]
30pub enum RouterMessage {
31 MakeConnection(String),
32 ConnectionCreated(usize),
33 GetConnection,
34 ReturnConnection((mpsc::Sender<TransactionMessage>, usize)),
35 CloseConnection(usize),
36 ConnectionClosed,
37 Error(NanoServiceError),
38 CloseConnectionPool,
39 ConnectionPoolClosed,
40 ShutDown,
41}