surrealcs_kernel/messages/client/
router.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! the message structs that are strictly just for the client (we should aim to completely remove these)
use nanoservices_utils::errors::NanoServiceError;
use tokio::sync::mpsc;
use tokio::sync::oneshot;

use crate::messages::client::message::TransactionMessage;

/// The messsage wrapper to enable returning a response to the sender.
///
/// # Fields
/// * `message`: The message to be sent to the router
/// * `tx`: the sender to send the response back to the initial sender from the router actor
pub struct WrappedRouterMessage {
	pub message: RouterMessage,
	pub tx: oneshot::Sender<RouterMessage>,
}

/// The message to be sent to the router.
///
/// # Variants
/// * `MakeConnection`: to make a connection using the string as the URL
/// * `ConnectionCreated`: a clarification of the connection created with the index of the allocator
/// * `GetConnection`: to get a random connection
/// * `ReturnConnection`: returns a random collection from the `GetConnection` request
/// * `CloseConnection`: to close the connection that belongs to the index
/// * `ConnectionClosed`: a confirmation that the connection is closed
/// * `Error`: an error
/// * `ShutdownConnectionPool`: shuts down the connection pool
#[derive(Debug)]
pub enum RouterMessage {
	MakeConnection(String),
	ConnectionCreated(usize),
	GetConnection,
	ReturnConnection((mpsc::Sender<TransactionMessage>, usize)),
	CloseConnection(usize),
	ConnectionClosed,
	Error(NanoServiceError),
	CloseConnectionPool,
	ConnectionPoolClosed,
	ShutDown,
}