Skip to main content

RoomRegistry

Struct RoomRegistry 

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

Process-shared registry of live rooms. Cheap to clone (it is an Arc bag) so it can live in ServerState and be reached from handlers and append_message.

Implementations§

Source§

impl RoomRegistry

Source

pub fn new() -> Self

A registry with production lifecycle tunables.

Source

pub fn with_config(config: RoomConfig) -> Self

A registry with custom lifecycle tunables (used by tests for short windows).

Source

pub fn get_or_create(&self, room_id: &str) -> RoomHandle

Get the handle for room_id, spawning the room’s actor if it is not yet live. Idempotent: repeated calls for the same id return clones of the same handle (same broadcast sender + member counter) until the room hibernates.

Source

pub fn join( &self, room_id: &str, member_id: impl Into<String>, ) -> RoomMembership

Join room_id as member_id, get-or-creating the room AND incrementing its member count atomically under the registry lock. This is the race-safe entry point that any concurrent caller (the WS gateway) must use instead of get_or_create() followed by RoomHandle::join.

Because [try_evict] rechecks the member count under this same lock, the increment can never be observed as zero in the gap between get-or-create and join. So a join racing an eviction has exactly two outcomes: the join takes the lock first (eviction then sees members > 0 and aborts, keeping the existing room), or eviction takes it first (removes the entry and exits; this call then transparently spawns a fresh room). Neither outcome yields an orphaned handle whose actor is dead and whose registry entry is gone.

Source

pub fn publish_event(&self, room_id: &str, value: Value)

Publish an Events frame to room_id. No-op if the room is not live (no members are subscribed, so there is nothing to deliver and no reason to spin up an actor).

Source

pub fn publish_presence(&self, room_id: &str, member_id: &str, value: Value)

Publish a presence delta for member_id to room_id: stores it in the room’s ephemeral map (so the heartbeat TTL applies) and broadcasts on the Presence channel. No-op if the room is not live.

Source

pub fn broadcast_event( &self, room_id: &str, name: impl Into<String>, payload: Value, )

Broadcast a typed named event to room_id (Rivet’s broadcast(event, payload)). No-op if the room is not live — the registry-level twin of publish_event, for callers holding only the registry.

Source

pub fn send_event( &self, room_id: &str, conn: ConnId, name: impl Into<String>, payload: Value, )

Deliver a typed named event to one connection in room_id (Rivet’s conn.send(event, payload)). No-op if the room is not live or the connection has closed.

Source

pub fn room_count(&self) -> usize

Number of live (non-hibernated) rooms. Primarily for tests/diagnostics.

Trait Implementations§

Source§

impl Clone for RoomRegistry

Source§

fn clone(&self) -> RoomRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for RoomRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> 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<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