Skip to main content

GCMessageBroker

Struct GCMessageBroker 

pub struct GCMessageBroker {
    concurrent_runtime: ConcurrentRuntime,
    datapoint_mapping: Arc<RwLock<DatapointMapping>>,
    is_channel_default_blocking: bool,
}
Expand description

Message broker used to distribute messages to the subscribers. This module should be built using the GCMessageBrokerBuilder that will take care of all the necessary configurations. Whenever the broker is built, it can be used to generate multiple publishers, the broker for sequential messages will start routing the messages to the sequential subscribers immediately. Although, the concurrent subscribers messages will only be processed once the run is called.

Fields§

§concurrent_runtime: ConcurrentRuntime§datapoint_mapping: Arc<RwLock<DatapointMapping>>§is_channel_default_blocking: bool

Implementations§

§

impl GCMessageBroker

pub fn new( concurrent_runtime: ConcurrentRuntime, datapoint_mapping: Arc<RwLock<DatapointMapping>>, is_channel_blocking: bool, ) -> Self

pub fn add_sequential_subscriber( &mut self, subscriber: Arc<dyn GCDatapointSubscriber>, datapoint_id: GCDatapointID, ) -> Result<(), GCMessageBrokerError>

Adds a subscriber to a datapoint ID for the sequential (synchronous) message dispatcher.

Returns an error if the sequential subscriber is already registered for the datapoint_id

pub fn add_concurrent_subscriber( &mut self, subscriber: Arc<dyn GCDatapointSubscriber>, datapoint_id: GCDatapointID, ) -> Result<(), GCMessageBrokerError>

Adds a subscriber to a datapoint ID for the concurrent (asynchronous) message dispatcher.

Returns an error if the concurrent subscriber is already registered for the datapoint_id

pub fn set_scaling_transformation( &mut self, datapoint_id: GCDatapointID, transformation: Option<ScaleTransformation>, ) -> Result<(), GCMessageBrokerError>

Set a scaling transformation for a datapoint

Returns an error if the datapoint_id is smaller then largest datapoint_id registered Any overflows that are caused by the scaling transformation are responsibility of the caller.

pub fn subscriber_count(&self, datapoint_id: GCDatapointID) -> usize

Retrieve the number of subscribers for a given datapoint ID

pub fn remove_datapoint(&mut self, _: GCDatapointID)

Currently this functions does nothing. It is meant as a placeholder for future implementations if needed.

pub fn remove_subscriber( &mut self, identifier: &GCSubscriberIdentifier, ) -> usize

Removes a subscriber from ALL datapoint IDs in the message broker. Returns the number of subscribers removed.

pub fn remove_subscriber_from_datapoint( &mut self, datapoint_id: GCDatapointID, identifier: &GCSubscriberIdentifier, ) -> bool

Removes a subscriber from a specific datapoint ID. Returns true if the subscriber was removed, false if the subscriber was not found.

pub fn add_datapoint(&mut self, datapoint_id: GCDatapointID)

Adds a new datapoint

pub fn generate_publisher(&self) -> GCMessagePublisher

Generates a publisher that can be used to publish messages.

pub fn run(&mut self)

Starts the message broker and distributes the messages to the subscribers concurrently. If this function is called multiple times, subsequent calls will have no effect.

Trait Implementations§

§

impl Default for GCMessageBroker

§

fn default() -> Self

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

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.