Mesh

Trait Mesh 

Source
pub trait Mesh: Send + Sync {
    // Required methods
    fn start<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stop<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn add_agent<'life0, 'async_trait>(
        &'life0 self,
        agent: Box<dyn Agent + 'static>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn send<'life0, 'life1, 'async_trait>(
        &'life0 self,
        message: Message,
        target: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Trait for agent coordination and message routing.

A mesh manages a collection of agents and handles communication between them. The primary implementation is [ceylon_local::LocalMesh] for single-process scenarios.

§Lifecycle

  1. Create a mesh with new()
  2. Add agents with add_agent()
  3. Start the mesh with start() - calls on_start for all agents
  4. Send messages with send()
  5. Stop the mesh with stop() - calls on_stop for all agents

§Example

use ceylon_local::LocalMesh;
use ceylon_core::Mesh;

let mesh = LocalMesh::new("my-mesh");
// mesh.add_agent(Box::new(my_agent)).await?;
mesh.start().await?;
// ... use the mesh ...
mesh.stop().await?;

Required Methods§

Source

fn start<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start the mesh and all registered agents.

Calls on_start for each agent.

Source

fn stop<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stop the mesh and all agents.

Calls on_stop for each agent.

Source

fn add_agent<'life0, 'async_trait>( &'life0 self, agent: Box<dyn Agent + 'static>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add an agent to the mesh.

The agent will be started when start() is called, or immediately if the mesh is already running.

Source

fn send<'life0, 'life1, 'async_trait>( &'life0 self, message: Message, target: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Send a message to a specific agent by name.

Implementors§