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: boolImplementations§
§impl GCMessageBroker
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>
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>
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>
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
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)
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
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
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)
pub fn add_datapoint(&mut self, datapoint_id: GCDatapointID)
Adds a new datapoint
pub fn generate_publisher(&self) -> GCMessagePublisher
pub fn generate_publisher(&self) -> GCMessagePublisher
Generates a publisher that can be used to publish messages.
pub fn run(&mut self)
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.