oa_gateway_loopback

Struct Loopback

Source
pub struct Loopback {
    pub(crate) id: AdapterId,
    pub(crate) engine: Arc<Engine>,
    pub(crate) next_sub: AtomicU64,
}
Expand description

In-process handle onto the engine.

Holds its own Engine so tests can Self::subscribe and Self::publish without going through Adapter::run. Two handles must not share an AdapterId: Self::shutdown drops every subscription under that id.

Fields§

§id: AdapterId§engine: Arc<Engine>§next_sub: AtomicU64

Implementations§

Source§

impl Loopback

Source

pub fn new(engine: Arc<Engine>, id: impl Into<AdapterId>) -> Self

Binds this handle to engine under id.

Does not subscribe and does not start Adapter::run. The engine is stored here; run ignores the engine the host passes in.

Source

pub fn engine(&self) -> &Arc<Engine>

The engine this handle was built with.

Source

pub async fn subscribe( &self, route: RouteKey, ) -> Result<Receiver<Envelope>, EngineError>

Subscribes and returns a receiver of matching Envelopes.

Delivery::sub_id is stripped; this handle assigns lb-N ids internally. Dropping the receiver stops the forwarder, but the engine subscription stays until Self::shutdown. Further publishes then count as dropped.

§Errors

Returns EngineError::DuplicateSub if an internal id collides, which does not happen on a single handle.

Source

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

Publishes through the shared engine. Same fan-out and drop rules as Engine::publish.

Source

pub async fn shutdown(&self) -> usize

Drops every subscription this handle owns.

Returns how many were removed. Does not cancel Adapter::run; the host’s cancellation token does that.

Trait Implementations§

Source§

impl Adapter for Loopback

Source§

fn run<'async_trait>( self: Arc<Self>, _engine: Arc<Engine>, shutdown: CancellationToken, ) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_trait>>
where Self: 'async_trait,

Waits for shutdown, then drops this handle’s subscriptions.

There is no socket. Tests that only call Loopback::subscribe and Loopback::publish never need this.

Unlike OWP, STOMP, and DDS, this has no session to retry and nothing in it panics in normal operation — there is no I/O and no protocol state, only a wait on shutdown — so it carries no on_panic/reconnect config. That is deliberate, not a gap: panic supervision on a function that cannot fail would be config with nothing to affect.

§Errors

Does not fail. Ok after the token fires.

Source§

fn id(&self) -> &AdapterId

Stable id for this adapter instance. Read more

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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