pub struct AimDbHandle { /* private fields */ }Expand description
Handle to the AimDB runtime thread.
Created by calling AimDb::attach(). Provides factory methods
for creating typed producers and consumers.
§Thread Safety
AimDbHandle is Send + Sync and can be shared across threads.
However, it should typically be owned by one thread, with only
the producers/consumers being cloned and shared.
§Resource Management
Call detach() explicitly to ensure clean shutdown. If the handle
is dropped without calling detach(), a warning will be logged
and an emergency shutdown will be attempted.
Implementations§
Source§impl AimDbHandle
impl AimDbHandle
Sourcepub fn producer<T>(&self, key: impl AsRef<str>) -> DbResult<SyncProducer<T>>
pub fn producer<T>(&self, key: impl AsRef<str>) -> DbResult<SyncProducer<T>>
Create a synchronous producer for type T.
§Arguments
key: The record key identifying this record instance
§Type Parameters
T: The record type, must implementTypedRecord
§Errors
DbError::RecordNotFoundif typeTwas not registeredDbError::RuntimeShutdownif the runtime thread has stopped
§Example
let producer = handle.producer::<Temperature>("sensor::temp")?;
producer.set(Temperature { celsius: 25.0 })?;Sourcepub fn consumer<T>(&self, key: impl AsRef<str>) -> DbResult<SyncConsumer<T>>
pub fn consumer<T>(&self, key: impl AsRef<str>) -> DbResult<SyncConsumer<T>>
Create a synchronous consumer for type T.
§Arguments
key: The record key identifying this record instance
§Type Parameters
T: The record type, must implementTypedRecord
§Errors
DbError::RecordNotFoundif typeTwas not registeredDbError::RuntimeShutdownif the runtime thread has stopped
§Example
let consumer = handle.consumer::<Temperature>("sensor::temp")?;
let temp = consumer.get()?;Sourcepub fn producer_with_capacity<T>(
&self,
key: impl AsRef<str>,
capacity: usize,
) -> DbResult<SyncProducer<T>>
pub fn producer_with_capacity<T>( &self, key: impl AsRef<str>, capacity: usize, ) -> DbResult<SyncProducer<T>>
Create a synchronous producer with custom channel capacity.
Like producer() but allows specifying the channel buffer size.
Use this when you need different buffering characteristics for specific record types.
§Arguments
key: The record key identifying this record instancecapacity: Channel buffer size (number of items that can be buffered)
§Type Parameters
T: The record type, must implementTypedRecord
§Errors
DbError::RecordNotFoundif typeTwas not registeredDbError::RuntimeShutdownif the runtime thread has stopped
§Example
// High-frequency sensor needs larger buffer
let producer = handle.producer_with_capacity::<HighFrequencySensor>("sensor::high_freq", 1000)?;
producer.set(HighFrequencySensor { value: 42.0 })?;Sourcepub fn consumer_with_capacity<T>(
&self,
key: impl AsRef<str>,
capacity: usize,
) -> DbResult<SyncConsumer<T>>
pub fn consumer_with_capacity<T>( &self, key: impl AsRef<str>, capacity: usize, ) -> DbResult<SyncConsumer<T>>
Create a synchronous consumer with custom channel capacity.
Like consumer() but allows specifying the channel buffer size.
Use this when you need different buffering characteristics for specific record types.
§Arguments
key: The record key identifying this record instancecapacity: Channel buffer size (number of items that can be buffered)
§Type Parameters
T: The record type, must implementTypedRecord
§Errors
DbError::RecordNotFoundif typeTwas not registeredDbError::RuntimeShutdownif the runtime thread has stopped
§Example
// Rare events need smaller buffer
let consumer = handle.consumer_with_capacity::<RareEvent>("events::rare", 10)?;
let event = consumer.get()?;