Skip to main content

phago_distributed/rpc/
mod.rs

1//! RPC protocol definitions using tarpc.
2//!
3//! This module implements the tarpc-based RPC layer for
4//! inter-node communication including:
5//! - Service definitions for colony operations
6//! - Client and server implementations
7//! - Connection pooling and retry logic
8//!
9//! # Architecture
10//!
11//! The RPC layer consists of three main components:
12//!
13//! - **Protocol**: Trait definitions for `ShardService` and `CoordinatorService`
14//! - **Server**: Server implementations that wrap local components
15//! - **Client**: Client utilities including connection pooling
16//!
17//! # Example: Starting a Shard Server
18//!
19//! ```rust,ignore
20//! use phago_distributed::rpc::server::ShardServer;
21//! use phago_distributed::shard::ShardedColony;
22//!
23//! let shard = Arc::new(RwLock::new(ShardedColony::new(...)));
24//! let server = ShardServer::new(shard);
25//! server.serve("127.0.0.1:8080".parse().unwrap()).await?;
26//! ```
27//!
28//! # Example: Connecting as a Client
29//!
30//! ```rust,ignore
31//! use phago_distributed::rpc::client::{connect_to_shard, ShardClientPool};
32//!
33//! // Direct connection
34//! let client = connect_to_shard("127.0.0.1:8080".parse().unwrap()).await?;
35//!
36//! // Or use the connection pool
37//! let pool = ShardClientPool::new();
38//! pool.register_shard(ShardId::new(0), "127.0.0.1:8080".parse().unwrap());
39//! let client = pool.get_client(ShardId::new(0)).await?;
40//! ```
41
42pub mod client;
43pub mod messages;
44pub mod protocol;
45pub mod server;
46
47// Protocol exports
48pub use protocol::{
49    CoordinatorService, CoordinatorServiceClient, RpcError, RpcResult, ShardService,
50    ShardServiceClient, TickStatus,
51};
52
53// Message exports
54pub use messages::{
55    BatchUpdate, BatchUpdateResult, CrossShardEdgeNotification, CrossShardSignal, HeartbeatMessage,
56    HeartbeatResponse, NodeTransferRequest, NodeTransferResponse, QueryGatherResponse,
57    QueryScatterRequest, ShardCommand, StartTickMessage, UpdateOperation,
58};
59
60// Client exports
61pub use client::{
62    connect_to_coordinator, connect_to_coordinator_with_config, connect_to_coordinator_with_retry,
63    connect_to_shard, connect_to_shard_with_config, connect_to_shard_with_retry, ClientConfig,
64    CoordinatorClient, ShardClientPool,
65};
66
67// Server exports
68pub use server::{CoordinatorServer, ShardServer};