pub struct StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G = NoGuard>where
ID: AgentId,
Op: Debug + Clone + Send + Sync + 'static,
StateType: Debug + Send + Sync + 'static,
SL: StateLogic<Op, ID, StateType>,
Sess: Session<Op, ID>,
SP: SnapshotProvider<ID, StateType, Op>,
G: OpGuard<Op, ID, StateType>,{ /* private fields */ }Expand description
Assembles a StateController from its four components.
All components are required, so they are constructor arguments and
build cannot fail:
let (tx, controller) = StateControllerBuilder::new(logic, session, snapshotter, initial_state)
.command_buffer(64)
.build();
tokio::spawn(controller.run());Implementations§
Source§impl<Op, ID, StateType, SL, Sess, SP> StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, NoGuard>
impl<Op, ID, StateType, SL, Sess, SP> StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, NoGuard>
Source§impl<Op, ID, StateType, SL, Sess, SP, G> StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G>
impl<Op, ID, StateType, SL, Sess, SP, G> StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G>
Sourcepub fn guard<G2>(
self,
op_guard: Arc<G2>,
) -> StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G2>where
G2: OpGuard<Op, ID, StateType>,
pub fn guard<G2>(
self,
op_guard: Arc<G2>,
) -> StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G2>where
G2: OpGuard<Op, ID, StateType>,
Sets the OpGuard screening agent ops ahead of StateLogic.
Runs per op with the state read-only. A refused op never reaches the
rules, its reply (if any) goes back to the source as a system op and the
refusal counts in ControllerStats::ops_refused. System submissions
and time steps are never screened. The default is NoGuard.
.guard(Arc::new(GuardFn(screen)))Sourcepub fn snapshot_context_on_join(self, context: Option<SnapshotContext>) -> Self
pub fn snapshot_context_on_join(self, context: Option<SnapshotContext>) -> Self
Sets the SnapshotContext used for the snapshot a joining agent receives.
Defaults to Full. Set a perspective here when clients should join into a
named view rather than the whole state:
.snapshot_context_on_join(Some(SnapshotContext::ForPerspective("player".into())))Sourcepub fn command_buffer(self, size: usize) -> Self
pub fn command_buffer(self, size: usize) -> Self
Sets the command channel depth (default DEFAULT_COMMAND_BUFFER).
Sourcepub fn with_stats(self, stats: Arc<ControllerStats>) -> Self
pub fn with_stats(self, stats: Arc<ControllerStats>) -> Self
Writes counters into one the application already holds, instead of the fresh one built by default.
For a process that wants a single reading across several controllers, or one that has to hold the handle before the controller is constructed.
Sourcepub fn stats(&self) -> Arc<ControllerStats> ⓘ
pub fn stats(&self) -> Arc<ControllerStats> ⓘ
The live counters this controller will write into.
Take it before build and keep the Arc: it is readable at any moment
from any thread, including while the controller is mid-tick, which a
command-based query could not manage. See ControllerStats.
Sourcepub fn build(
self,
) -> (CommandSender<Op, ID, StateType>, StateController<Op, ID, StateType, SL, Sess, SP, G>)
pub fn build( self, ) -> (CommandSender<Op, ID, StateType>, StateController<Op, ID, StateType, SL, Sess, SP, G>)
Builds the controller and the sender used to command it.
Source§impl<Op, ID, StateType, SL, Sess> StateControllerBuilder<Op, ID, StateType, SL, Sess, NoSnapshots>
impl<Op, ID, StateType, SL, Sess> StateControllerBuilder<Op, ID, StateType, SL, Sess, NoSnapshots>
Sourcepub fn without_snapshots(
op_handler: Arc<SL>,
session: Arc<Sess>,
initial_state: StateType,
) -> Self
pub fn without_snapshots( op_handler: Arc<SL>, session: Arc<Sess>, initial_state: StateType, ) -> Self
Starts a builder for an application where joining carries no catch-up.
For a chat relay, an event log or a client that rebuilds from the op
stream, which would otherwise each write a SnapshotProvider returning
Ok(None). Everything else about the controller is unchanged, including
SendSnapshots, which becomes a request that sends nothing.
let (tx, controller) = StateControllerBuilder::without_snapshots(logic, session, state).build();