oa_gateway_core

Struct Engine

Source
pub struct Engine {
    state: RwLock<State>,
    stats: EngineStats,
}
Expand description

Shared, protocol-neutral pub/sub router.

The engine never parses a payload and never names a protocol. It matches RouteKey values and try_sends Deliverys. Adapters own their sockets, their channels, and any schema work.

Fields§

§state: RwLock<State>§stats: EngineStats

Implementations§

Source§

impl Engine

Source

pub fn new() -> Self

Creates an empty engine with zero subscriptions and zero counters.

Source

pub fn stats(&self) -> &EngineStats

Process-lifetime counters. Survives Self::drop_adapter.

Source

pub async fn subscribe( &self, adapter_id: impl Into<AdapterId>, sub_id: impl Into<SubId>, route: RouteKey, tx: Sender<Delivery>, ) -> Result<SubscriberKey, EngineError>

Registers a subscriber. The adapter owns tx and reads Deliverys.

A RouteKey with type_hint: None is a wildcard: every type on that topic. A typed key matches only that hint. The same sub_id may be reused on a different adapter.

§Errors

Returns EngineError::DuplicateSub if this adapter already registered sub_id.

Source

pub async fn unsubscribe( &self, adapter_id: impl Into<AdapterId>, sub_id: impl Into<SubId>, ) -> Result<(), EngineError>

Removes one subscription. Further publishes will not reach it.

§Errors

Returns EngineError::UnknownSub if this adapter has no subscription with that sub_id.

Source

pub async fn drop_adapter(&self, adapter_id: impl Into<AdapterId>) -> usize

Removes every subscription owned by adapter_id.

Returns how many were removed, or 0 if the adapter had none. Call this on shutdown and when a session restarts, or stale subscriptions keep matching and silently discarding messages.

Source

pub async fn publish(&self, envelope: Envelope) -> PublishOutcome

Fans out envelope to matching subscribers. Never inspects the payload.

Matching is exact-plus-wildcard: a publish with type_hint: Some("Ping") reaches both typed(topic, "Ping") and topic(topic) subscribers. A publish with no type hint reaches wildcards only.

Each send is try_send. A full or closed channel counts as dropped and does not block other subscribers.

Source

pub async fn subscription_count(&self) -> usize

Number of registered subscriptions across every adapter.

Used to wait until a newly spawned adapter has subscribed before publishing test traffic. Not a readiness API for production.

Trait Implementations§

Source§

impl Default for Engine

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !Freeze for Engine

§

impl !RefUnwindSafe for Engine

§

impl Send for Engine

§

impl Sync for Engine

§

impl Unpin for Engine

§

impl !UnwindSafe for Engine

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.