Skip to main content

NamespaceEventGate

Struct NamespaceEventGate 

Source
pub struct NamespaceEventGate { /* private fields */ }
Expand description

Per-connection gate deciding whether an event belongs to the authorized namespace, and what workflow type its workflow carries.

Verdicts are cached per workflow in a bounded LRU. The cache is sound because a workflow’s owner namespace is recorded atomically with its WorkflowStarted batch and never changes, and the publisher broadcasts only after durable commit — so by the time any event for a workflow is observed here, its ownership verdict is durable and final, and an evicted entry that is later re-read always reproduces the same verdict.

The cache bound is derived from the configured websocket.event_broadcast_capacity rather than introducing a new knob: the engine-global broadcast channel retains at most that many events, so any burst this connection can observe without lagging out references at most that many distinct workflows. Sizing the LRU to the broadcast capacity keeps every workflow of the largest possible in-flight window cached; anything beyond it is cold traffic where an eviction costs one re-read of immutable durable state.

Implementations§

Source§

impl NamespaceEventGate

Source

pub fn new( resolver: NamespaceResolver, namespace: String, verdict_capacity: NonZeroUsize, ) -> Self

Build a gate for one authorized namespace with a bounded verdict cache.

Source

pub fn allow(&mut self, workflow_id: WorkflowId)

Pre-seed an allow verdict for a workflow whose ownership the namespace guard already verified (the per-workflow subscription target), so the hot path never re-reads history for it. The workflow type is captured lazily from the stream or a later attribution read; per-workflow subscriptions carry no type selector, so none is needed up front.

Source

pub async fn admit(&mut self, event: &Event) -> Result<GateVerdict, ServerError>

Decide whether event may be delivered to this connection.

GateVerdict::Filtered means the event’s workflow is foreign or unknown to the authorized namespace. GateVerdict::Permitted carries the workflow’s recorded type so selector filtering can run on the same cached read that proved ownership.

A delivered WorkflowStarted event refreshes the cached type inline (continue-as-new chains record each run’s type on its own WorkflowStarted), so the cached type follows the stream’s own order without extra reads. The initial durable read instead resolves the head-of-history type at read time, which on a continue-as-new chain can run ahead of an older delivered event for at most one event-loop turn before the inline refresh self-heals it.

§Errors

Returns ServerError when the durable ownership source cannot be read; callers must terminate the stream loudly rather than guessing.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn into_maybe_undefined(self) -> MaybeUndefined<T>

Converts this value into a three-state builder argument.
Source§

impl<T> IntoOption<T> for T

Source§

fn into_option(self) -> Option<T>

Converts this value into an optional builder argument.
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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