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: UuidUnique 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
impl CellServerCtx
Sourcepub 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
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.
Sourcepub fn search_index(&self) -> &Arc<SearchIndex>
pub fn search_index(&self) -> &Arc<SearchIndex>
Get the search index.
Sourcepub fn history_replay(&self) -> Option<&Arc<dyn HistoryReplayProvider>>
pub fn history_replay(&self) -> Option<&Arc<dyn HistoryReplayProvider>>
Get the history replay provider, if configured.
Sourcepub fn register_peer_client<S>(&self, peer_id: S, client: Arc<MykoClient>)
pub fn register_peer_client<S>(&self, peer_id: S, client: Arc<MykoClient>)
Register or replace a live peer client for a server id.
Sourcepub fn unregister_peer_client(&self, peer_id: &str)
pub fn unregister_peer_client(&self, peer_id: &str)
Remove a live peer client for a server id.
Sourcepub fn peer_client(&self, peer_id: &str) -> Option<Arc<MykoClient>>
pub fn peer_client(&self, peer_id: &str) -> Option<Arc<MykoClient>>
Get a live peer client by server id, if present.
Sourcepub fn peer_connection_status(
&self,
peer_id: &str,
) -> Option<SocketConnectionStatus>
pub fn peer_connection_status( &self, peer_id: &str, ) -> Option<SocketConnectionStatus>
Get a peer’s current connection status if the client is present.
Sourcepub fn peer_clients_tick(&self) -> Cell<u64, CellImmutable>
pub fn peer_clients_tick(&self) -> Cell<u64, CellImmutable>
Reactive tick that updates whenever peer client membership changes.
Sourcepub fn peer_client_count(&self) -> usize
pub fn peer_client_count(&self) -> usize
Number of currently tracked peer clients.
Sourcepub fn persist_health(&self) -> Arc<PersistHealth>
pub fn persist_health(&self) -> Arc<PersistHealth>
Get the live persist health counters from the default persister.
Sourcepub fn query_cache_len(&self) -> usize
pub fn query_cache_len(&self) -> usize
Number of entries in the query cache (includes dead weak refs).
Sourcepub fn view_cache_len(&self) -> usize
pub fn view_cache_len(&self) -> usize
Number of entries in the view cache (includes dead weak refs).
Sourcepub fn report_cache_len(&self) -> usize
pub fn report_cache_len(&self) -> usize
Number of entries in the report cache (includes dead weak refs).
Sourcepub fn report_cache_live_count(&self) -> usize
pub fn report_cache_live_count(&self) -> usize
Count live (upgradeable) entries in the report cache.
Sourcepub fn query_cache_live_count(&self) -> usize
pub fn query_cache_live_count(&self) -> usize
Count live (upgradeable) entries in the query cache.
Sourcepub fn view_cache_live_count(&self) -> usize
pub fn view_cache_live_count(&self) -> usize
Count live (upgradeable) entries in the view cache.
Sourcepub fn sweep_dead_cache_entries(&self) -> (usize, usize, usize)
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).
Sourcepub fn parse_item(
&self,
entity_type: &str,
json: &Value,
) -> Option<Arc<dyn AnyItem>>
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.
Sourcepub fn set<T>(&self, entity: &T) -> Result<(), PersistError>where
T: Eventable + 'static,
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
Sourcepub fn set_with_options<T>(
&self,
entity: &T,
options: Option<EventOptions>,
) -> Result<(), PersistError>where
T: Eventable + 'static,
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 processingprevent_persist: skip durable backend
Sourcepub fn del<T>(&self, entity: &T) -> Result<(), PersistError>
pub fn del<T>(&self, entity: &T) -> Result<(), PersistError>
Delete an entity (DEL) with default options.
Default behavior: Reduce + Relationships + Persist
Sourcepub fn del_with_options<T>(
&self,
entity: &T,
options: Option<EventOptions>,
) -> Result<(), PersistError>
pub fn del_with_options<T>( &self, entity: &T, options: Option<EventOptions>, ) -> Result<(), PersistError>
Delete an entity (DEL) with options.
Sourcepub fn batch_set<T>(&self, entities: &[T]) -> Result<(), PersistError>
pub fn batch_set<T>(&self, entities: &[T]) -> Result<(), PersistError>
Publish a batch of entities (SET) with default options.
Default behavior: Reduce + Relationships + Persist
Sourcepub fn batch_set_with_options<T>(
&self,
entities: &[T],
options: Option<EventOptions>,
) -> Result<(), PersistError>
pub fn batch_set_with_options<T>( &self, entities: &[T], options: Option<EventOptions>, ) -> Result<(), PersistError>
Publish a batch of entities (SET) with shared options.
This avoids manual MEvent construction and performs a grouped store insert.
Sourcepub fn batch_del<T>(&self, entities: &[T]) -> Result<(), PersistError>
pub fn batch_del<T>(&self, entities: &[T]) -> Result<(), PersistError>
Delete a batch of entities (DEL) with default options.
Default behavior: Reduce + Relationships + Persist
Sourcepub fn batch_del_with_options<T>(
&self,
entities: &[T],
options: Option<EventOptions>,
) -> Result<(), PersistError>
pub fn batch_del_with_options<T>( &self, entities: &[T], options: Option<EventOptions>, ) -> Result<(), PersistError>
Delete a batch of entities (DEL) with shared options.
This avoids manual MEvent construction and performs a grouped store remove.
Sourcepub fn set_dyn(&self, item: Arc<dyn AnyItem>) -> Result<(), PersistError>
pub fn set_dyn(&self, item: Arc<dyn AnyItem>) -> Result<(), PersistError>
Publish a dynamic item (SET) with default options.
Default behavior: Reduce + Relationships + Persist
Sourcepub fn set_dyn_with_options(
&self,
item: Arc<dyn AnyItem>,
options: Option<EventOptions>,
) -> Result<(), PersistError>
pub fn set_dyn_with_options( &self, item: Arc<dyn AnyItem>, options: Option<EventOptions>, ) -> Result<(), PersistError>
Publish a dynamic item (SET) with options.
Sourcepub fn batch_set_dyn_with_options(
&self,
items: &[Arc<dyn AnyItem>],
options: Option<EventOptions>,
) -> Result<(), PersistError>
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.
Sourcepub fn del_dyn(&self, item: Arc<dyn AnyItem>) -> Result<(), PersistError>
pub fn del_dyn(&self, item: Arc<dyn AnyItem>) -> Result<(), PersistError>
Delete a dynamic item (DEL) with default options.
Default behavior: Reduce + Relationships + Persist
Sourcepub fn del_dyn_with_options(
&self,
item: Arc<dyn AnyItem>,
options: Option<EventOptions>,
) -> Result<(), PersistError>
pub fn del_dyn_with_options( &self, item: Arc<dyn AnyItem>, options: Option<EventOptions>, ) -> Result<(), PersistError>
Delete a dynamic item (DEL) with options.
Sourcepub fn batch_del_dyn_with_options(
&self,
items: &[Arc<dyn AnyItem>],
options: Option<EventOptions>,
) -> Result<(), PersistError>
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.
Sourcepub fn del_by_id_with_options(
&self,
entity_type: &str,
id: &str,
options: Option<EventOptions>,
) -> Result<(), PersistError>
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.
Sourcepub fn del_by_id(&self, entity_type: &str, id: &str) -> Result<(), PersistError>
pub fn del_by_id(&self, entity_type: &str, id: &str) -> Result<(), PersistError>
Delete an entity by type/id with default options.
Sourcepub fn apply_event(&self, event: MEvent) -> Result<bool, PersistError>
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.
Sourcepub fn apply_event_batch(
&self,
events: Vec<MEvent>,
) -> Result<usize, PersistError>
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.
Sourcepub 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,
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.
Sourcepub 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,
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>
}Sourcepub 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,
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).
Sourcepub 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,
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.
Sourcepub 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,
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.
Sourcepub 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>>,
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.
Sourcepub fn entity_snapshots<T>(&self) -> Vec<Arc<T>>where
T: Eventable + WithTypedId + Send + Sync + 'static,
<T as WithTypedId>::Id: IdFor<T, MapKey = Arc<str>>,
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.
Sourcepub 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>>,
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.
Sourcepub 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,
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.
pub fn report<R>( &self, report: R, request: Arc<RequestContext>, ) -> Cell<Arc<<R as ReportHandler>::Output>, CellImmutable>
pub fn new_server_transaction(&self) -> Arc<RequestContext>
Trait Implementations§
Source§impl Clone for CellServerCtx
impl Clone for CellServerCtx
Source§fn clone(&self) -> CellServerCtx
fn clone(&self) -> CellServerCtx
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CellServerCtx
impl !RefUnwindSafe for CellServerCtx
impl Send for CellServerCtx
impl Sync for CellServerCtx
impl Unpin for CellServerCtx
impl UnsafeUnpin for CellServerCtx
impl !UnwindSafe for CellServerCtx
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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