Struct DatapointMapping
pub struct DatapointMapping {
mapping: Vec<DatapointEntry>,
broadcast_sync_subscribers: HashMap<GCSubscriberIdentifier, Arc<dyn GCDatapointSubscriber>>,
broadcast_async_subscribers: HashMap<GCSubscriberIdentifier, Arc<dyn GCDatapointSubscriber>>,
}Expand description
Represents the mapping between datapoint ids and subscribers The mapping is a contiguous array of vectors, where each datapoint id is the index of the array which contains the list of subscribers for that datapoint
Fields§
§mapping: Vec<DatapointEntry>§broadcast_sync_subscribers: HashMap<GCSubscriberIdentifier, Arc<dyn GCDatapointSubscriber>>§broadcast_async_subscribers: HashMap<GCSubscriberIdentifier, Arc<dyn GCDatapointSubscriber>>Implementations§
§impl DatapointMapping
impl DatapointMapping
fn new() -> Self
fn new() -> Self
Creates a new empty mapping
pub fn with_datapoint_count(datapoint_count: usize) -> Self
pub fn with_datapoint_count(datapoint_count: usize) -> Self
Initializes the mapping with a given datapoint count
fn add_subscriber( &mut self, datapoint_id: GCDatapointID, subscriber: Arc<dyn GCDatapointSubscriber>, is_async: bool, ) -> Result<(), GCMessageBrokerError>
pub fn set_scaling_transformation(
&mut self,
datapoint_id: GCDatapointID,
transformation: Option<ScaleTransformation>,
) -> Result<(), GCMessageBrokerError>
pub fn set_scaling_transformation( &mut self, datapoint_id: GCDatapointID, transformation: Option<ScaleTransformation>, ) -> Result<(), GCMessageBrokerError>
Sets a scaling transformation for a datapoint
If the datapoint does not exist, it returns an error. A datapoint exists if a datapoint id a larger ID has been already added to the mapping.
pub fn add_async_subscriber(
&mut self,
datapoint_id: GCDatapointID,
subscriber: Arc<dyn GCDatapointSubscriber>,
) -> Result<(), GCMessageBrokerError>
pub fn add_async_subscriber( &mut self, datapoint_id: GCDatapointID, subscriber: Arc<dyn GCDatapointSubscriber>, ) -> Result<(), GCMessageBrokerError>
Adds a async subscriber to a datapoint
If the subscriber already exists, it returns an error
§Important
If the datapoint id doesn’t exist yet in the mapping, it resizes the array to fit the datapoint id. This means that, if a very high datapoint id is used, it will consume a lot of memory.
pub fn add_sync_subscriber(
&mut self,
datapoint_id: GCDatapointID,
subscriber: Arc<dyn GCDatapointSubscriber>,
) -> Result<(), GCMessageBrokerError>
pub fn add_sync_subscriber( &mut self, datapoint_id: GCDatapointID, subscriber: Arc<dyn GCDatapointSubscriber>, ) -> Result<(), GCMessageBrokerError>
Adds a sync subscriber to a datapoint
If the subscriber already exists, it returns an error
§Important
If the datapoint id doesn’t exist yet in the mapping, it resizes the array to fit the datapoint id. This means that, if a very high datapoint id is used, it will consume a lot of memory.
pub fn add_sync_broadcast_subscriber(
&mut self,
subscriber: Arc<dyn GCDatapointSubscriber>,
)
pub fn add_sync_broadcast_subscriber( &mut self, subscriber: Arc<dyn GCDatapointSubscriber>, )
Adds a sync subscriber to all datapoints, it also registers the subscriber as a broadcast subscriber So, subsequent datapoints added will also have this subscriber.
pub fn add_async_broadcast_subscriber(
&mut self,
subscriber: Arc<dyn GCDatapointSubscriber>,
)
pub fn add_async_broadcast_subscriber( &mut self, subscriber: Arc<dyn GCDatapointSubscriber>, )
Adds an async subscriber to all datapoints, it also registers the subscriber as a broadcast subscriber So, subsequent datapoints added will also have this subscriber.
pub fn get_datapoint_entry(
&self,
datapoint_id: GCDatapointID,
) -> Option<&DatapointEntry>
pub fn get_datapoint_entry( &self, datapoint_id: GCDatapointID, ) -> Option<&DatapointEntry>
Returns information about a datapoint entry
pub fn get_datapoint_count(&self) -> usize
pub fn get_datapoint_count(&self) -> usize
Returns the number of datapoints in the mapping
pub fn get_subscriber_count(&self, datapoint_id: GCDatapointID) -> usize
pub fn get_subscriber_count(&self, datapoint_id: GCDatapointID) -> usize
Returns the number of subscribers for a given datapoint id
pub fn add_datapoint(&mut self, datapoint_id: GCDatapointID)
pub fn add_datapoint(&mut self, datapoint_id: GCDatapointID)
Adds a datapoint to the broker and instantly registers already loaded broadcast subscribers
If the datapoint id already exists, it does nothing If the subscriber already exists, it returns an error
§Important
If the datapoint id doesn’t exist yet in the mapping, it resizes the array to fit the datapoint id. This means that, if a very high datapoint id is used, it will consume a lot of memory.
pub fn remove_subscriber_from_datapoint(
&mut self,
datapoint_id: GCDatapointID,
identifier: &GCSubscriberIdentifier,
) -> bool
pub fn remove_subscriber_from_datapoint( &mut self, datapoint_id: GCDatapointID, identifier: &GCSubscriberIdentifier, ) -> bool
Remove subscriber from a datapoint
pub fn remove_subscriber_from_all_datapoints(
&mut self,
identifier: &GCSubscriberIdentifier,
) -> usize
pub fn remove_subscriber_from_all_datapoints( &mut self, identifier: &GCSubscriberIdentifier, ) -> usize
Removes a subscriber from all datapoint mapping and return the number of subscribers removed