Struct syndicate::actor::Activation
source · pub struct Activation<'activation> {
pub facet: FacetRef,
pub state: &'activation mut RunningActor,
/* private fields */
}Expand description
The main API for programming Syndicated Actor objects.
Through Activations, programs can access the state of their
animating RunningActor and their active Facet.
Usually, an Activation will be supplied to code that needs one; but when non-Actor code
(such as a linked task) needs to enter an Actor’s execution
context, use FacetRef::activate to construct one.
Many actions that an entity can perform are methods directly on
Activation, but methods on the RunningActor and FacetRef
values contained in an Activation are also sometimes useful.
This is what other implementations call a “Turn”, renamed here to
avoid conflicts with crate::schemas::protocol::Turn.
Fields§
§facet: FacetRef§state: &'activation mut RunningActorA reference to the current state of the active Actor.
Implementations§
source§impl<'activation> Activation<'activation>
impl<'activation> Activation<'activation>
pub fn trace_collector(&self) -> Option<TraceCollector>
sourcepub fn create_account(&self, name: Name) -> Arc<Account>
pub fn create_account(&self, name: Name) -> Arc<Account>
Constructs a new Account with the given name, inheriting
its trace_collector from the current Activation’s cause.
sourcepub fn facet_ids(&mut self) -> Vec<FacetId> ⓘ
pub fn facet_ids(&mut self) -> Vec<FacetId> ⓘ
Retrieves the chain of facet IDs, in order, from the currently-active Facet up to
and including the root facet of the active actor. Useful for debugging.
sourcepub fn assert<M: 'static + Send + Debug>(
&mut self,
r: &Arc<Ref<M>>,
a: M
) -> Handle
pub fn assert<M: 'static + Send + Debug>( &mut self, r: &Arc<Ref<M>>, a: M ) -> Handle
Core API: assert a at recipient r.
Returns the Handle for the new assertion.
sourcepub fn retract(&mut self, handle: Handle)
pub fn retract(&mut self, handle: Handle)
Core API: retract a previously-established assertion.
sourcepub fn update<M: 'static + Send + Debug>(
&mut self,
handle: &mut Option<Handle>,
r: &Arc<Ref<M>>,
a: Option<M>
)
pub fn update<M: 'static + Send + Debug>( &mut self, handle: &mut Option<Handle>, r: &Arc<Ref<M>>, a: Option<M> )
Core API: assert, retract, or replace an assertion.
sourcepub fn message<M: 'static + Send + Debug>(&mut self, r: &Arc<Ref<M>>, m: M)
pub fn message<M: 'static + Send + Debug>(&mut self, r: &Arc<Ref<M>>, m: M)
Core API: send message m to recipient r.
sourcepub fn sync<M: 'static + Send>(&mut self, r: &Arc<Ref<M>>, peer: Arc<Ref<Synced>>)
pub fn sync<M: 'static + Send>(&mut self, r: &Arc<Ref<M>>, peer: Arc<Ref<Synced>>)
Core API: begins a synchronisation with r.
Once the synchronisation request reaches r’s actor, it will
send a response to peer, which acts as a continuation for
the synchronisation request.
sourcepub fn on_stop_notify<M: 'static + Send>(&mut self, r: &Arc<Ref<M>>)
pub fn on_stop_notify<M: 'static + Send>(&mut self, r: &Arc<Ref<M>>)
Registers the entity r in the list of stop actions for the active facet. If the facet
terminates cleanly, r’s stop will be called in the context of the
facet’s parent.
Note. If the actor crashes, stop actions will not be called.
Use RunningActor::add_exit_hook to install a callback that will be called at the
end of the lifetime of the actor rather than the facet. (Also, exit hooks are called
no matter whether actor termination was normal or abnormal.)
sourcepub fn on_stop<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>(
&mut self,
action: F
)
pub fn on_stop<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>( &mut self, action: F )
Registers action in the list of stop actions for the active facet. If the facet
terminates cleanly, action will be called in the context of the facet’s parent. See
also notes against on_stop_notify.
sourcepub fn account(&self) -> &Arc<Account>
pub fn account(&self) -> &Arc<Account>
Retrieve the Account against which actions are recorded.
sourcepub fn commit(&mut self) -> ActorResult
pub fn commit(&mut self) -> ActorResult
Delivers all pending actions in this activation and resets it, ready for more. Succeeds iff all pre-commit actions succeed.
Commit procedure
If an activation’s f function returns successfully, the
activation commits according to the following procedure:
-
While the dataflow graph needs repairing or outstanding pre-commit actions exist:
- repair the dataflow graph
- run all pre-commit actions Note that graph repair or a pre-commit action may fail, causing the commit to abort, or may further damage the dataflow graph or schedule another pre-commit action, causing another go around the loop.
-
The commit becomes final. All queued events are sent; all internal accounting actions are performed.
sourcepub fn inert_entity<M>(&mut self) -> Arc<Ref<M>>
pub fn inert_entity<M>(&mut self) -> Arc<Ref<M>>
Construct an entity with behaviour InertEntity within the active facet.
sourcepub fn create<M, E: Entity<M> + Send + 'static>(&mut self, e: E) -> Arc<Ref<M>>
pub fn create<M, E: Entity<M> + Send + 'static>(&mut self, e: E) -> Arc<Ref<M>>
Construct an entity with behaviour e within the active facet.
sourcepub fn create_inert<M>(&mut self) -> Arc<Ref<M>>
pub fn create_inert<M>(&mut self) -> Arc<Ref<M>>
Construct an entity (within the active facet) whose behaviour will be specified later
via become_entity.
sourcepub fn linked_task<F: 'static + Send + Future<Output = Result<LinkedTaskTermination, Error>>>(
&mut self,
name: Name,
boot: F
)
pub fn linked_task<F: 'static + Send + Future<Output = Result<LinkedTaskTermination, Error>>>( &mut self, name: Name, boot: F )
Start a new linked task attached to the active facet. The
task will execute the future “boot” to completion unless it is cancelled first (by
e.g. termination of the owning facet or crashing of the owning actor). Stops the active
facet when the linked task completes. Uses name for log messages emitted by the task.
sourcepub fn after<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>(
&mut self,
duration: Duration,
a: F
)
pub fn after<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>( &mut self, duration: Duration, a: F )
Executes the given action after the given duration has elapsed (so long as the active facet still exists at that time).
sourcepub fn every<F: 'static + Send + FnMut(&mut Activation<'_>) -> ActorResult>(
&mut self,
duration: Duration,
a: F
) -> ActorResult
pub fn every<F: 'static + Send + FnMut(&mut Activation<'_>) -> ActorResult>( &mut self, duration: Duration, a: F ) -> ActorResult
Executes the given action immediately, and then every time another multiple of the given duration has elapsed (so long as the active facet still exists at that time).
sourcepub fn at<I: Into<Instant>, F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>(
&mut self,
instant: I,
a: F
)
pub fn at<I: Into<Instant>, F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>( &mut self, instant: I, a: F )
Executes the given action at the given instant (so long as the active facet still exists at that time).
sourcepub fn pre_commit<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>(
&mut self,
action: F
)
pub fn pre_commit<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>( &mut self, action: F )
Schedules the given action to run just prior to commit.
sourcepub fn spawn<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>(
&mut self,
name: Name,
boot: F
) -> ActorRef
pub fn spawn<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>( &mut self, name: Name, boot: F ) -> ActorRef
Schedule the creation of a new actor when the Activation commits.
sourcepub fn spawn_link<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>(
&mut self,
name: Name,
boot: F
) -> ActorRef
pub fn spawn_link<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>( &mut self, name: Name, boot: F ) -> ActorRef
Schedule the creation of a new actor when the Activation commits.
The new actor will be “linked” to the active facet: if the new actor terminates, the active facet is stopped, and if the active facet stops, the new actor’s root facet is stopped.
sourcepub fn facet<F: FnOnce(&mut Activation<'_>) -> ActorResult>(
&mut self,
boot: F
) -> Result<FacetId, ActorError>
pub fn facet<F: FnOnce(&mut Activation<'_>) -> ActorResult>( &mut self, boot: F ) -> Result<FacetId, ActorError>
sourcepub fn prevent_inert_check(&mut self) -> DisarmFn
pub fn prevent_inert_check(&mut self) -> DisarmFn
Useful during facet (and actor) startup, in some situations: when a facet boot
procedure would return while the facet is inert, but the facet should survive until
some subsequent time, call prevent_inert_check to increment a counter that prevents
inertness-checks from succeeding on the active facet.
The result of prevent_inert_check is a function which, when called, decrements the
counter again. After the counter has been decremented, any subsequent inertness checks
will no longer be artificially forced to fail.
An example of when you might want this: creating an actor having only a single
Dataspace entity within it, then using the Dataspace from other actors. At the start of
its life, the Dataspace actor will have no outbound assertions, no child facets, and no
linked tasks, so the only way to prevent it from being prematurely garbage collected is
to use prevent_inert_check in its boot function.
sourcepub fn stop_facet_and_continue<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>(
&mut self,
facet_id: FacetId,
continuation: Option<F>
) -> ActorResult
pub fn stop_facet_and_continue<F: 'static + Send + FnOnce(&mut Activation<'_>) -> ActorResult>( &mut self, facet_id: FacetId, continuation: Option<F> ) -> ActorResult
If continuation is supplied, adds it as a stop action for the Facet named by
facet_id. Then, cleanly stops the facet immediately, without waiting for self to
commit.
sourcepub fn stop_facet(&mut self, facet_id: FacetId)
pub fn stop_facet(&mut self, facet_id: FacetId)
Arranges for the Facet named by facet_id to be stopped cleanly when self
commits.
Equivalent to self.stop_facet_and_continue(facet_id, None), except that the lack of a
continuation means that there’s no need for this method to return ActorResult.
sourcepub fn stop(&mut self)
pub fn stop(&mut self)
Arranges for the active facet to be stopped cleanly when self commits.
Equivalent to self.stop_facet(self.facet.facet_id).
sourcepub fn stop_root(&mut self)
pub fn stop_root(&mut self)
Arranges for the active actor’s root facet to be stopped cleanly when self commits;
this is one way to arrange a clean shutdown of the entire actor.
Equivalent to self.stop_facet(self.state.root).
sourcepub fn named_field<T: Any + Send>(
&mut self,
name: &str,
initial_value: T
) -> Arc<Field<T>>
pub fn named_field<T: Any + Send>( &mut self, name: &str, initial_value: T ) -> Arc<Field<T>>
Create a new named dataflow variable (field) within the active Actor.
sourcepub fn field<T: Any + Send>(&mut self, initial_value: T) -> Arc<Field<T>>
pub fn field<T: Any + Send>(&mut self, initial_value: T) -> Arc<Field<T>>
Create a new anonymous dataflow variable (field) within the active Actor.
sourcepub fn get<T: Any + Send>(&mut self, field: &Field<T>) -> &T
pub fn get<T: Any + Send>(&mut self, field: &Field<T>) -> &T
Retrieve a reference to the current value of a dataflow variable (field); if execution is currently within a dataflow block, marks the block as depending upon the field.
sourcepub fn get_mut<T: Any + Send>(&mut self, field: &Field<T>) -> &mut T
pub fn get_mut<T: Any + Send>(&mut self, field: &Field<T>) -> &mut T
Retrieve a mutable reference to the contents of a dataflow variable (field). As for
get, if used within a dataflow block, marks the block as
depending upon the field. In addition, because the caller may mutate the field, this
function (pessimistically) marks the field as dirty, which will lead to later
reevaluation of dependent blocks.
sourcepub fn set<T: Any + Send>(&mut self, field: &Field<T>, value: T)
pub fn set<T: Any + Send>(&mut self, field: &Field<T>, value: T)
Overwrite the value of a dataflow variable (field). Marks the field as dirty, even if
the new value is eq to the value being overwritten.