Skip to content

Commit

Permalink
refactor: make connections pub
Browse files Browse the repository at this point in the history
  • Loading branch information
strasdat committed Mar 8, 2024
1 parent de5e73d commit 9c9e47e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/core/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ pub mod request_connection;

type ConnectionRegister<T> = Vec<Arc<dyn GenericConnection<T> + Send + Sync>>;

pub(crate) enum ConnectionEnum<T> {
/// Connection
pub enum ConnectionEnum<T> {
/// Configuration of the connection
Config(ConnectionConfig<T>),
/// Active connection
Active(ActiveConnection<T>),
}

Expand Down
14 changes: 12 additions & 2 deletions src/core/connection/outbound_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ use crate::core::{outbound::GenericConnection, Activate};

use super::{ConnectionEnum, ConnectionRegister};

pub(crate) struct ConnectionConfig<T> {
/// Connection configuration
pub struct ConnectionConfig<T> {
/// List of connections
pub connection_register: ConnectionRegister<T>,
/// Launch pad for new connections
pub maybe_register_launch_pad: Option<tokio::sync::oneshot::Sender<ConnectionRegister<T>>>,
/// Landing pad for new connections
pub maybe_register_landing_pad: Option<tokio::sync::oneshot::Receiver<ConnectionRegister<T>>>,
}

Expand All @@ -22,6 +26,7 @@ impl<T> Drop for ConnectionConfig<T> {
}

impl<T> ConnectionConfig<T> {
///
pub fn new() -> Self {
let (connection_launch_pad, connection_landing_pad) = tokio::sync::oneshot::channel();
Self {
Expand All @@ -32,16 +37,21 @@ impl<T> ConnectionConfig<T> {
}
}

pub(crate) struct ActiveConnection<T> {
/// Active connection
pub struct ActiveConnection<T> {
/// List of connections
pub maybe_registers: Option<ConnectionRegister<T>>,
/// Landing pad for new connections
pub maybe_register_landing_pad: Option<tokio::sync::oneshot::Receiver<ConnectionRegister<T>>>,
}

impl<T: Clone + Send + Sync + std::fmt::Debug + 'static> ConnectionEnum<T> {
/// new connection
pub fn new() -> Self {
Self::Config(ConnectionConfig::new())
}

/// push connection
pub fn push(&mut self, connection: Arc<dyn GenericConnection<T> + Send + Sync>) {
match self {
Self::Config(config) => {
Expand Down
9 changes: 6 additions & 3 deletions src/core/outbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ pub struct OutboundChannel<T> {
pub name: String,
/// Name of the actor that sends the outbound messages.
pub actor_name: String,
pub(crate) connection_register: ConnectionEnum<T>,
/// register
pub connection_register: ConnectionEnum<T>,
}

impl<OutT: Default + Clone + Send + Sync + std::fmt::Debug + 'static> OutboundChannel<OutT> {
impl<OutT: Clone + Send + Sync + std::fmt::Debug + 'static> OutboundChannel<OutT> {
/// Create a new outbound for actor in provided context.
pub fn new(context: &mut Context, name: String, actor_name: &str) -> Self {
context.assert_unique_outbound_name(name.clone(), actor_name);
Expand Down Expand Up @@ -137,7 +138,9 @@ impl<Out, InT, M: InboundMessage> Debug for OutboundConnectionWithAdapter<Out, I
}
}

pub(crate) trait GenericConnection<T>: Send + Sync {
/// Generic connection trait
pub trait GenericConnection<T>: Send + Sync {
/// Send a message to the connected inbound channels to other actors.
fn send_impl(&self, msg: T);
}

Expand Down

0 comments on commit 9c9e47e

Please sign in to comment.