Skip to main content

SubscriptionRelay

Struct SubscriptionRelay 

Source
pub struct SubscriptionRelay<CD: ContextData, Q: RemoteQuerySubscriber> { /* private fields */ }
Expand description

Manages predicate registration on remote peer reactor subscriptions.

The SubscriptionRelay provides a resilient, event-driven approach to managing which predicates are registered with remote durable peers. It automatically handles:

  • Registering predicates on peer reactor subscriptions when peers connect
  • Re-registering predicates when peers disconnect and reconnect
  • Retrying failed predicate registration attempts
  • Clean teardown when predicates are removed
  • Storing ContextData for each predicate to enable proper authorization

This design separates predicate management concerns from the main Node implementation, making it easier to test and reason about predicate lifecycle management.

§Public API (for Node integration)

  • subscribe_predicate() - Call when local subscriptions are created (parallel to reactor.subscribe)
  • unsubscribe_predicate() - Call when local subscriptions are removed (parallel to reactor.unsubscribe)
  • notify_peer_connected() - Call when durable peers connect (triggers automatic predicate registration)
  • notify_peer_disconnected() - Call when durable peers disconnect (orphans predicate registrations)
  • get_status() - Query current state of a predicate registration

§Internal/Testing API

  • setup_remote_subscriptions() - Internal method for triggering predicate registration with specific peers (called automatically by notify_peer_connected, but exposed for testing)

The relay will automatically handle predicate registration/teardown asynchronously.

Implementations§

Source§

impl<CD: ContextData, Q: RemoteQuerySubscriber> SubscriptionRelay<CD, Q>

Source

pub fn new() -> Self

Source

pub fn set_node(&self, node: Arc<dyn TNode<CD>>) -> Result<(), ()>

Inject the node (typically a WeakNode for production)

This should be called once during initialization. Returns an error if the node has already been set.

Source

pub fn subscribe_query( &self, query_id: QueryId, collection_id: CollectionId, selection: Selection, context_data: CD, version: u32, livequery: Q, )

Notify the relay that a new predicate needs to be registered on remote peer subscriptions

This should be called whenever a local subscription is established. The relay will track this predicate and automatically attempt to register it with available durable peers.

Source

pub fn update_query( &self, query_id: QueryId, selection: Selection, version: u32, ) -> Result<(), Error>

Source

pub fn unsubscribe_predicate(&self, query_id: QueryId)

Notify the relay that a predicate should be removed from remote peer subscriptions

This will clean up all tracking state and send unsubscribe requests to any remote peers that have this predicate registered.

Source

pub fn notify_peer_disconnected(&self, peer_id: EntityId)

Handle peer disconnection - mark all predicates for that peer as needing re-registration

This should be called when a durable peer disconnects. All predicates registered with that peer will be marked as pending and will be automatically re-registered when the peer reconnects or another suitable peer becomes available.

Source

pub fn notify_peer_connected(&self, peer_id: EntityId)

Handle peer connection - trigger predicate registration on the new peer subscription

This should be called when a new durable peer connects. The relay will automatically attempt to register any pending predicates on the newly connected peer’s subscription.

Source

pub fn get_status(&self, query_id: QueryId) -> Option<Status>

Get the current state of a predicate registration

Source

pub fn get_contexts_for_peer(&self, peer_id: &EntityId) -> HashSet<CD>

Get all unique contexts for predicates established or requested with a specific peer TODO: update the data structure to do this via a direct lookup rather than having to scan the entire map

Trait Implementations§

Source§

impl<CD: Clone + ContextData, Q: Clone + RemoteQuerySubscriber> Clone for SubscriptionRelay<CD, Q>

Source§

fn clone(&self) -> SubscriptionRelay<CD, Q>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<CD: ContextData, Q: RemoteQuerySubscriber> Default for SubscriptionRelay<CD, Q>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<CD, Q> Freeze for SubscriptionRelay<CD, Q>

§

impl<CD, Q> !RefUnwindSafe for SubscriptionRelay<CD, Q>

§

impl<CD, Q> Send for SubscriptionRelay<CD, Q>

§

impl<CD, Q> Sync for SubscriptionRelay<CD, Q>

§

impl<CD, Q> Unpin for SubscriptionRelay<CD, Q>

§

impl<CD, Q> UnsafeUnpin for SubscriptionRelay<CD, Q>

§

impl<CD, Q> !UnwindSafe for SubscriptionRelay<CD, Q>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Iterable<T> for T

Source§

type Iter<'a> = Once<&'a T> where T: 'a

Source§

fn iterable(&self) -> <T as Iterable<T>>::Iter<'_>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<M> Meta for M
where M: Default,

Source§

impl<T> ObserverBounds for T