Skip to main content

CellServerCtx

Struct CellServerCtx 

Source
pub struct CellServerCtx {
    pub host_id: Uuid,
    pub registry: Arc<StoreRegistry>,
    pub handler_registry: Arc<HandlerRegistry>,
    /* private fields */
}
Expand description

Context providing capabilities to server modules.

This is the cell-based equivalent of MykoServerCtx, providing:

  • Entity store access (read-only, via queries)
  • Event publishing (Reduce → Relationships → Persist)
  • Server identity

Fields§

§host_id: Uuid

Unique identifier for this server instance

§registry: Arc<StoreRegistry>

Store registry for entity access

§handler_registry: Arc<HandlerRegistry>

Handler registry for item parsers

Implementations§

Source§

impl CellServerCtx

Source

pub fn new( host_id: Uuid, registry: Arc<StoreRegistry>, handler_registry: Arc<HandlerRegistry>, relationship_manager: Arc<RelationshipManager>, persisters: Arc<PersisterRouter>, search_index: Arc<SearchIndex>, peer_clients: Arc<DashMap<Arc<str>, Arc<MykoClient>>>, event_sink: Option<Sender<MEvent>>, history_replay: Option<Arc<dyn HistoryReplayProvider>>, ) -> CellServerCtx

Create a new server context.

Source

pub fn search_index(&self) -> &Arc<SearchIndex>

Get the search index.

Source

pub fn history_replay(&self) -> Option<&Arc<dyn HistoryReplayProvider>>

Get the history replay provider, if configured.

Source

pub fn register_peer_client<S>(&self, peer_id: S, client: Arc<MykoClient>)
where S: AsRef<str>,

Register or replace a live peer client for a server id.

Source

pub fn unregister_peer_client(&self, peer_id: &str)

Remove a live peer client for a server id.

Source

pub fn peer_client(&self, peer_id: &str) -> Option<Arc<MykoClient>>

Get a live peer client by server id, if present.

Source

pub fn peer_connection_status( &self, peer_id: &str, ) -> Option<SocketConnectionStatus>

Get a peer’s current connection status if the client is present.

Source

pub fn peer_clients_tick(&self) -> Cell<u64, CellImmutable>

Reactive tick that updates whenever peer client membership changes.

Source

pub fn peer_client_count(&self) -> usize

Number of currently tracked peer clients.

Source

pub fn persist_health(&self) -> Arc<PersistHealth>

Get the live persist health counters from the default persister.

Source

pub fn query_cache_len(&self) -> usize

Number of entries in the query cache (includes dead weak refs).

Source

pub fn view_cache_len(&self) -> usize

Number of entries in the view cache (includes dead weak refs).

Source

pub fn report_cache_len(&self) -> usize

Number of entries in the report cache (includes dead weak refs).

Source

pub fn report_cache_live_count(&self) -> usize

Count live (upgradeable) entries in the report cache.

Source

pub fn query_cache_live_count(&self) -> usize

Count live (upgradeable) entries in the query cache.

Source

pub fn view_cache_live_count(&self) -> usize

Count live (upgradeable) entries in the view cache.

Source

pub fn sweep_dead_cache_entries(&self) -> (usize, usize, usize)

Remove dead weak-ref entries from all caches. Returns (query_removed, view_removed, report_removed).

Source

pub fn parse_item( &self, entity_type: &str, json: &Value, ) -> Option<Arc<dyn AnyItem>>

Parse JSON to a typed entity using the registered item parser.

Returns None if the entity type is not registered or parsing fails.

Source

pub fn set<T>(&self, entity: &T) -> Result<(), PersistError>
where T: Eventable + 'static,

Publish an entity (SET) with default options.

Default behavior: Reduce + Relationships + Persist

Source

pub fn set_with_options<T>( &self, entity: &T, options: Option<EventOptions>, ) -> Result<(), PersistError>
where T: Eventable + 'static,

Publish an entity (SET) with options.

Options control:

  • prevent_relationship_updates: skip cascade processing
  • prevent_persist: skip durable backend
Source

pub fn del<T>(&self, entity: &T) -> Result<(), PersistError>
where T: Eventable + Clone + 'static,

Delete an entity (DEL) with default options.

Default behavior: Reduce + Relationships + Persist

Source

pub fn del_with_options<T>( &self, entity: &T, options: Option<EventOptions>, ) -> Result<(), PersistError>
where T: Eventable + Clone + 'static,

Delete an entity (DEL) with options.

Source

pub fn batch_set<T>(&self, entities: &[T]) -> Result<(), PersistError>
where T: Eventable + Clone + 'static,

Publish a batch of entities (SET) with default options.

Default behavior: Reduce + Relationships + Persist

Source

pub fn batch_set_with_options<T>( &self, entities: &[T], options: Option<EventOptions>, ) -> Result<(), PersistError>
where T: Eventable + Clone + 'static,

Publish a batch of entities (SET) with shared options.

This avoids manual MEvent construction and performs a grouped store insert.

Source

pub fn batch_del<T>(&self, entities: &[T]) -> Result<(), PersistError>
where T: Eventable + Clone + 'static,

Delete a batch of entities (DEL) with default options.

Default behavior: Reduce + Relationships + Persist

Source

pub fn batch_del_with_options<T>( &self, entities: &[T], options: Option<EventOptions>, ) -> Result<(), PersistError>
where T: Eventable + Clone + 'static,

Delete a batch of entities (DEL) with shared options.

This avoids manual MEvent construction and performs a grouped store remove.

Source

pub fn set_dyn(&self, item: Arc<dyn AnyItem>) -> Result<(), PersistError>

Publish a dynamic item (SET) with default options.

Default behavior: Reduce + Relationships + Persist

Source

pub fn set_dyn_with_options( &self, item: Arc<dyn AnyItem>, options: Option<EventOptions>, ) -> Result<(), PersistError>

Publish a dynamic item (SET) with options.

Source

pub fn batch_set_dyn_with_options( &self, items: &[Arc<dyn AnyItem>], options: Option<EventOptions>, ) -> Result<(), PersistError>

Publish a batch of dynamic items (SET) with shared options.

Source

pub fn del_dyn(&self, item: Arc<dyn AnyItem>) -> Result<(), PersistError>

Delete a dynamic item (DEL) with default options.

Default behavior: Reduce + Relationships + Persist

Source

pub fn del_dyn_with_options( &self, item: Arc<dyn AnyItem>, options: Option<EventOptions>, ) -> Result<(), PersistError>

Delete a dynamic item (DEL) with options.

Source

pub fn batch_del_dyn_with_options( &self, items: &[Arc<dyn AnyItem>], options: Option<EventOptions>, ) -> Result<(), PersistError>

Publish a batch of dynamic items (DEL) with shared options.

Source

pub fn del_by_id_with_options( &self, entity_type: &str, id: &str, options: Option<EventOptions>, ) -> Result<(), PersistError>

Delete an entity by type/id and publish DEL even if the item is not present locally.

This is useful for explicit tombstoning of entities (e.g. disconnected peers) where we must ensure a DEL event is produced to durable backend.

Note: relationship cascades require the full item and are therefore skipped here.

Source

pub fn del_by_id(&self, entity_type: &str, id: &str) -> Result<(), PersistError>

Delete an entity by type/id with default options.

Source

pub fn apply_event(&self, event: MEvent) -> Result<bool, PersistError>

Apply a single wire event (parse -> reduce -> relationships -> persist).

Returns true when the event was parsed and applied, false otherwise.

Source

pub fn apply_event_batch( &self, events: Vec<MEvent>, ) -> Result<usize, PersistError>

Apply a batch of wire events with a single parse pass and grouped store updates.

This reduces overhead versus calling set_dyn/del_dyn for each event individually. Returns the number of successfully parsed/applied events.

Source

pub fn query_map<Q>( &self, query: Q, request: Arc<RequestContext>, ) -> CellMap<Arc<str>, Arc<<Q as QueryItemType>::Item>, CellImmutable>
where Q: QueryFactory + QueryHandler + QueryParams + Clone + Send + Sync + 'static, <Q as QueryItemType>::Item: Eventable + WithId + DeserializeOwned + Clone + Debug + Send + Sync + 'static,

Run a reactive query and return a typed map keyed by canonical string ids.

Use query_map_untyped() when framework internals need erased AnyItem.

Source

pub fn query_map_untyped<Q>( &self, query: Q, request: Arc<RequestContext>, ) -> CellMap<Arc<str>, Arc<dyn AnyItem>, CellImmutable>
where Q: QueryFactory + QueryHandler + QueryParams + Clone + Send + Sync + 'static, <Q as QueryItemType>::Item: DeserializeOwned + Clone + Debug + Send + Sync + 'static,

Run a reactive query.

Returns a type-erased map that updates whenever the query results change. The query’s test_entity is applied with proper server context.

§Example
use std::sync::Arc;
use myko::entities::server::GetPeerServers;
use myko::request::RequestContext;
use myko::server::CellServerCtx;

fn demo(ctx: &CellServerCtx, req: Arc<RequestContext>) {
    let _peer_servers = ctx.query_map_untyped(GetPeerServers {}, req);
    // _peer_servers is CellMap<Arc<str>, Arc<dyn AnyItem>, CellImmutable>
}
Source

pub fn view_map_untyped<V>( &self, view: V, request: Arc<RequestContext>, ) -> CellMap<Arc<str>, Arc<dyn AnyItem>, CellImmutable>
where V: ViewFactory + Clone + Send + Sync + 'static, <V as ViewItemType>::Item: DeserializeOwned + Clone + Debug + Send + Sync + 'static,

Build a reactive view cell map (type-erased for framework internals).

Source

pub fn view_map<V>( &self, view: V, request: Arc<RequestContext>, ) -> CellMap<Arc<str>, Arc<dyn AnyItem>, CellImmutable>
where V: ViewFactory + Clone + Send + Sync + 'static, <V as ViewItemType>::Item: DeserializeOwned + Clone + Debug + Send + Sync + 'static,

Back-compat alias for type-erased view map.

Source

pub fn view<V>( &self, view: V, request: Arc<RequestContext>, ) -> CellMap<Arc<str>, Arc<<V as ViewItemType>::Item>, CellImmutable>
where V: ViewFactory + Clone + Send + Sync + 'static, <V as ViewItemType>::Item: DeserializeOwned + Clone + Debug + Send + Sync + 'static,

Build a typed reactive view cell map.

Source

pub fn entity_snapshot<T>(&self, id: &<T as WithTypedId>::Id) -> Option<Arc<T>>
where T: Eventable + WithTypedId + Send + Sync + 'static, <T as WithTypedId>::Id: IdFor<T, MapKey = Arc<str>>,

Get a one-shot typed entity snapshot by id.

Source

pub fn entity_snapshots<T>(&self) -> Vec<Arc<T>>
where T: Eventable + WithTypedId + Send + Sync + 'static, <T as WithTypedId>::Id: IdFor<T, MapKey = Arc<str>>,

Get one-shot typed entity snapshots for an item type.

Source

pub fn entity_snapshots_by_id<T>( &self, ids: impl IntoIterator<Item = <T as WithTypedId>::Id>, ) -> Vec<Arc<T>>
where T: Eventable + WithTypedId + Send + Sync + 'static, <T as WithTypedId>::Id: IdFor<T, MapKey = Arc<str>>,

Get one-shot typed entity snapshots for the provided ids.

Source

pub fn query_snapshot<Q>( &self, query: Q, request: Arc<RequestContext>, ) -> Vec<Arc<<Q as QueryItemType>::Item>>
where Q: QueryHandler + QueryParams + Clone + Send + Sync + 'static, <Q as QueryItemType>::Item: DeserializeOwned + Clone + Debug + Send + Sync + 'static,

Run a one-shot (non-reactive) query.

Iterates the store directly and returns matching entities without creating any reactive cells or subscriptions. Use this for command handlers and other contexts where you need a point-in-time snapshot, not a live query.

Source

pub fn report<R>( &self, report: R, request: Arc<RequestContext>, ) -> Cell<Arc<<R as ReportHandler>::Output>, CellImmutable>
where R: ReportHandler + ReportId + CacheKey + Clone + Serialize + 'static,

Source

pub fn new_server_transaction(&self) -> Arc<RequestContext>

Trait Implementations§

Source§

impl Clone for CellServerCtx

Source§

fn clone(&self) -> CellServerCtx

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 Debug for CellServerCtx

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. 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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> JoinKeyFrom<T> for T
where T: Clone,

Source§

fn join_key_from(value: &T) -> T

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

Source§

type Output = T

Should always be Self
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<T> Fruit for T
where T: Send + Downcast,

Source§

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

Source§

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