Skip to main content

Component

Trait Component 

Source
pub trait Component {
Show 27 methods // Required methods fn component_id(&self) -> ComponentId; fn state(&self) -> ComponentState; fn transition_state(&mut self, trigger: ComponentTrigger) -> Result<()>; fn register( &mut self, trader_id: TraderId, clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>, ) -> Result<()>; // Provided methods fn is_ready(&self) -> bool { ... } fn not_running(&self) -> bool { ... } fn is_running(&self) -> bool { ... } fn is_stopped(&self) -> bool { ... } fn is_degraded(&self) -> bool { ... } fn is_faulted(&self) -> bool { ... } fn is_disposed(&self) -> bool { ... } fn initialize(&mut self) -> Result<()> { ... } fn start(&mut self) -> Result<()> { ... } fn stop(&mut self) -> Result<()> { ... } fn resume(&mut self) -> Result<()> { ... } fn degrade(&mut self) -> Result<()> { ... } fn fault(&mut self) -> Result<()> { ... } fn reset(&mut self) -> Result<()> { ... } fn dispose(&mut self) -> Result<()> { ... } fn release_subscriptions(&mut self) { ... } fn on_start(&mut self) -> Result<()> { ... } fn on_stop(&mut self) -> Result<()> { ... } fn on_resume(&mut self) -> Result<()> { ... } fn on_reset(&mut self) -> Result<()> { ... } fn on_dispose(&mut self) -> Result<()> { ... } fn on_degrade(&mut self) -> Result<()> { ... } fn on_fault(&mut self) -> Result<()> { ... }
}
Expand description

Components have state and lifecycle management capabilities.

Required Methods§

Source

fn component_id(&self) -> ComponentId

Returns the unique identifier for this component.

Source

fn state(&self) -> ComponentState

Returns the current state of the component.

Source

fn transition_state(&mut self, trigger: ComponentTrigger) -> Result<()>

Transition the component with the state trigger.

§Errors

Returns an error if the trigger is an invalid transition from the current state.

Source

fn register( &mut self, trader_id: TraderId, clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>, ) -> Result<()>

Registers the component with a system.

§Errors

Returns an error if the component fails to register.

Provided Methods§

Source

fn is_ready(&self) -> bool

Returns whether the component is ready.

Source

fn not_running(&self) -> bool

Returns whether the component is not running.

Source

fn is_running(&self) -> bool

Returns whether the component is running.

Source

fn is_stopped(&self) -> bool

Returns whether the component is stopped.

Source

fn is_degraded(&self) -> bool

Returns whether the component has been degraded.

Source

fn is_faulted(&self) -> bool

Returns whether the component has been faulted.

Source

fn is_disposed(&self) -> bool

Returns whether the component has been disposed.

Source

fn initialize(&mut self) -> Result<()>

Initializes the component.

§Errors

Returns an error if the initialization state transition fails.

Source

fn start(&mut self) -> Result<()>

Starts the component.

§Errors

Returns an error if the component fails to start.

Source

fn stop(&mut self) -> Result<()>

Stops the component.

§Errors

Returns an error if the component fails to stop.

Source

fn resume(&mut self) -> Result<()>

Resumes the component.

§Errors

Returns an error if the component fails to resume.

Source

fn degrade(&mut self) -> Result<()>

Degrades the component.

§Errors

Returns an error if the component fails to degrade.

Source

fn fault(&mut self) -> Result<()>

Faults the component.

§Errors

Returns an error if the component fails to fault.

§Notes

Subscriptions are released whether or not on_fault succeeds, so a faulted component never keeps message bus handlers installed. Retirement relies on this: it deregisters a Faulted component without disposing it, which would otherwise leave those handlers behind.

Source

fn reset(&mut self) -> Result<()>

Resets the component to its initial state.

§Errors

Returns an error if the component fails to reset.

Source

fn dispose(&mut self) -> Result<()>

Disposes of the component, releasing any resources.

§Errors

Returns an error if the component fails to dispose.

§Notes

A failing on_dispose releases subscriptions and moves the component to Faulted, then returns the error. The trader’s registry entries and retained Python wrapper, if any, are deliberately kept, so the component stays inspectable, while Faulted leaves it retirable. Subscriptions are released on this path too, because a handler left installed would resolve a component the trader can now deregister.

on_fault does not run, since invoking a second user hook immediately after on_dispose failed can fail again.

Source

fn release_subscriptions(&mut self)

Releases the message bus registrations this component installed.

Runs on disposal after on_dispose and on faulting after on_fault, so a component the trader then deregisters leaves behind no handler which would resolve an actor that is no longer registered. An override must suit both routes rather than assume disposal, and should be idempotent: a component that faults from inside its own on_dispose releases twice.

Source

fn on_start(&mut self) -> Result<()>

Actions to be performed on start.

§Errors

Returns an error if starting the actor fails.

Source

fn on_stop(&mut self) -> Result<()>

Actions to be performed on stop.

§Errors

Returns an error if stopping the actor fails.

Source

fn on_resume(&mut self) -> Result<()>

Actions to be performed on resume.

§Errors

Returns an error if resuming the actor fails.

Source

fn on_reset(&mut self) -> Result<()>

Actions to be performed on reset.

§Errors

Returns an error if resetting the actor fails.

Source

fn on_dispose(&mut self) -> Result<()>

Actions to be performed on dispose.

§Errors

Returns an error if disposing the actor fails.

Source

fn on_degrade(&mut self) -> Result<()>

Actions to be performed on degrade.

§Errors

Returns an error if degrading the actor fails.

Source

fn on_fault(&mut self) -> Result<()>

Actions to be performed on fault.

§Errors

Returns an error if faulting the actor fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> Component for T
where T: DataActor + DataActorNative + Debug + 'static,