Skip to main content

ReactionBase

Struct ReactionBase 

Source
pub struct ReactionBase {
    pub id: String,
    pub queries: Vec<String>,
    pub auto_start: bool,
    pub status: Arc<RwLock<ComponentStatus>>,
    pub priority_queue: PriorityQueue<QueryResult>,
    pub subscription_tasks: Arc<RwLock<Vec<JoinHandle<()>>>>,
    pub processing_task: Arc<RwLock<Option<JoinHandle<()>>>>,
    pub shutdown_tx: Arc<RwLock<Option<Sender<()>>>>,
    /* private fields */
}
Expand description

Base implementation for common reaction functionality

Fields§

§id: String

Reaction identifier

§queries: Vec<String>

List of query IDs to subscribe to

§auto_start: bool

Whether this reaction should auto-start

§status: Arc<RwLock<ComponentStatus>>

Current component status

§priority_queue: PriorityQueue<QueryResult>

Priority queue for timestamp-ordered result processing

§subscription_tasks: Arc<RwLock<Vec<JoinHandle<()>>>>

Handles to subscription forwarder tasks

§processing_task: Arc<RwLock<Option<JoinHandle<()>>>>

Handle to the main processing task

§shutdown_tx: Arc<RwLock<Option<Sender<()>>>>

Sender for shutdown signal to processing task

Implementations§

Source§

impl ReactionBase

Source

pub fn new(params: ReactionBaseParams) -> Self

Create a new ReactionBase with the given parameters

Dependencies (event channel, query subscriber, state store) are not required during construction - they will be provided via initialize() when the reaction is added to DrasiLib.

Source

pub async fn initialize(&self, context: ReactionRuntimeContext)

Initialize the reaction with runtime context.

This method is called automatically by DrasiLib’s add_reaction() method. Plugin developers do not need to call this directly.

The context provides access to:

  • reaction_id: The reaction’s unique identifier
  • status_tx: Channel for reporting component status events
  • state_store: Optional persistent state storage
  • query_provider: Access to query instances for subscription
Source

pub async fn context(&self) -> Option<ReactionRuntimeContext>

Get the runtime context if initialized.

Returns None if initialize() has not been called yet.

Source

pub async fn state_store(&self) -> Option<Arc<dyn StateStoreProvider>>

Get the state store if configured.

Returns None if no state store was provided in the context.

Source

pub fn get_auto_start(&self) -> bool

Get whether this reaction should auto-start

Source

pub fn status_tx(&self) -> Arc<RwLock<Option<ComponentEventSender>>>

Get the status channel Arc for internal use by spawned tasks

This returns the internal status_tx wrapped in Arc<RwLock<Option<…>>> which allows background tasks to send component status events.

Returns a clone of the Arc that can be moved into spawned tasks.

Source

pub fn clone_shared(&self) -> Self

Clone the ReactionBase with shared Arc references

This creates a new ReactionBase that shares the same underlying data through Arc references. Useful for passing to spawned tasks.

Source

pub async fn create_shutdown_channel(&self) -> Receiver<()>

Create a shutdown channel and store the sender

Returns the receiver which should be passed to the processing task. The sender is stored internally and will be triggered by stop_common().

This should be called before spawning the processing task.

Source

pub fn get_id(&self) -> &str

Get the reaction ID

Source

pub fn get_queries(&self) -> &[String]

Get the query IDs

Source

pub async fn get_status(&self) -> ComponentStatus

Get current status

Source

pub async fn send_component_event( &self, status: ComponentStatus, message: Option<String>, ) -> Result<()>

Send a component lifecycle event

If the event channel has not been injected yet, this method silently succeeds without sending anything. This allows reactions to be used in a standalone fashion without DrasiLib if needed.

Source

pub async fn set_status_with_event( &self, status: ComponentStatus, message: Option<String>, ) -> Result<()>

Transition to a new status and send event

Source

pub async fn subscribe_to_queries(&self) -> Result<()>

Subscribe to all configured queries and spawn forwarder tasks

This method handles the common pattern of:

  1. Getting query instances via the injected QueryProvider
  2. Subscribing to each configured query
  3. Spawning forwarder tasks to enqueue results to priority queue
§Prerequisites
  • inject_query_provider() must have been called (done automatically by DrasiLib)
§Returns
  • Ok(()) if all subscriptions succeeded
  • Err(...) if QueryProvider not injected or any subscription failed
Source

pub async fn stop_common(&self) -> Result<()>

Perform common cleanup operations

This method handles:

  1. Sending shutdown signal to processing task (for graceful termination)
  2. Aborting all subscription forwarder tasks
  3. Waiting for or aborting the processing task
  4. Draining the priority queue
Source

pub async fn set_processing_task(&self, task: JoinHandle<()>)

Set the processing task handle

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> 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, 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