Skip to main content

DatapointMapping

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

fn new() -> Self

Creates a new empty mapping

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>

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>

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>

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

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

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>

Returns information about a datapoint entry

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

Returns the number of subscribers for a given datapoint id

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

Remove subscriber from a datapoint

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

Trait Implementations§

§

impl Default for DatapointMapping

§

fn default() -> Self

Returns the “default value” for a type. Read more
§

impl From<DatapointMapping> for Arc<RwLock<DatapointMapping>>

§

fn from(mapping: DatapointMapping) -> Self

Converts to this type from the input type.

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