pub struct AppNode<Op> {
pub app_id: String,
pub instance_id: String,
/* private fields */
}Expand description
The central node handle used by application code.
Generic over the operation type Op — the application supplies its own
operation enum and AppNode handles serialization, loopback broadcast, and
error logging consistently across all operation store backends.
Construct via the named constructors rather than directly:
let node = AppNode::<Op>::grpc("http://[::1]:50051".into(), "my-app-id", "my-instance")?;Fields§
§app_id: String§instance_id: StringImplementations§
Source§impl<Op: Clone + Serialize + Send + 'static> AppNode<Op>
impl<Op: Clone + Serialize + Send + 'static> AppNode<Op>
Sourcepub async fn local(
pool: SqlitePool,
app_id: impl Into<String>,
instance_id: impl Into<String>,
) -> Result<Self, Error>
pub async fn local( pool: SqlitePool, app_id: impl Into<String>, instance_id: impl Into<String>, ) -> Result<Self, Error>
Create a local-only AppNode backed by a SQLite store.
Operations are persisted locally and never forwarded to a remote node.
Sourcepub async fn grpc_with_local(
pool: SqlitePool,
grpc_addr: String,
app_id: impl Into<String>,
instance_id: impl Into<String>,
) -> Result<Self, ConnectError>
pub async fn grpc_with_local( pool: SqlitePool, grpc_addr: String, app_id: impl Into<String>, instance_id: impl Into<String>, ) -> Result<Self, ConnectError>
Create an AppNode that persists to a local SQLite store and forwards
to lores-node via gRPC, using the local row id as an idempotency key.
If gRPC delivery fails the operation is retained locally for a future drain attempt.
Sourcepub fn grpc(
grpc_addr: String,
app_id: impl Into<String>,
instance_id: impl Into<String>,
) -> Result<Self, ConnectError>
pub fn grpc( grpc_addr: String, app_id: impl Into<String>, instance_id: impl Into<String>, ) -> Result<Self, ConnectError>
Create an AppNode connected to an external lores-node via gRPC.
Uses a lazy connection — no network call until the first publish.
Sourcepub fn subscribe(&self) -> Receiver<AppNodeOperation<Op>>
pub fn subscribe(&self) -> Receiver<AppNodeOperation<Op>>
Subscribe to operations published through this node (loopback).
Sourcepub fn subscribe_errors(&self) -> Receiver<Option<NodeError>>
pub fn subscribe_errors(&self) -> Receiver<Option<NodeError>>
Watch the current node error state.
The receiver immediately reflects the current value, so callers that subscribe after an error was set will see it right away.
pub fn subscribe_node_events(&self) -> Receiver<NodeEvent>
Sourcepub async fn node_info(
&self,
node_id: impl Into<String>,
) -> Result<NodeInfo, GetNodeError>
pub async fn node_info( &self, node_id: impl Into<String>, ) -> Result<NodeInfo, GetNodeError>
Fetch information about a node in the same region.
Sourcepub async fn replay(&self) -> Result<(), StoreError>where
Op: for<'de> Deserialize<'de>,
pub async fn replay(&self) -> Result<(), StoreError>where
Op: for<'de> Deserialize<'de>,
Replay all locally-stored operations, broadcasting each through the event channel.
Sourcepub async fn publish(&self, operation: &Op) -> Result<(), StoreError>
pub async fn publish(&self, operation: &Op) -> Result<(), StoreError>
Serialize and publish an operation, then broadcast it locally.
Sourcepub async fn run(&self)where
Op: for<'de> Deserialize<'de>,
pub async fn run(&self)where
Op: for<'de> Deserialize<'de>,
Drive the remote subscription in a loop, broadcasting incoming operations and errors to all subscribers.
Retries on all transient failures with exponential backoff (1 s → 60 s).
The backoff resets whenever the error variant changes (e.g. GrpcUnavailable
→ RegionNotBound). Call it with tokio::spawn from your application’s main.
Trait Implementations§
Auto Trait Implementations§
impl<Op> !RefUnwindSafe for AppNode<Op>
impl<Op> !UnwindSafe for AppNode<Op>
impl<Op> Freeze for AppNode<Op>where
OperationConsumer<Op>: Freeze,
impl<Op> Send for AppNode<Op>where
OperationConsumer<Op>: Send,
impl<Op> Sync for AppNode<Op>where
OperationConsumer<Op>: Sync,
impl<Op> Unpin for AppNode<Op>where
OperationConsumer<Op>: Unpin,
impl<Op> UnsafeUnpin for AppNode<Op>where
OperationConsumer<Op>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request