saluki_core/components/forwarders/
context.rs

1use crate::accounting::ComponentRegistry;
2use crate::health::Health;
3use crate::{
4    components::ComponentContext,
5    topology::{PayloadsConsumer, TopologyContext},
6};
7
8/// Forwarder context.
9pub struct ForwarderContext {
10    topology_context: TopologyContext,
11    component_context: ComponentContext,
12    component_registry: ComponentRegistry,
13    health_handle: Option<Health>,
14    consumer: PayloadsConsumer,
15}
16
17impl ForwarderContext {
18    /// Creates a new `ForwarderContext`.
19    pub fn new(
20        topology_context: &TopologyContext, component_context: &ComponentContext,
21        component_registry: ComponentRegistry, health_handle: Health, consumer: PayloadsConsumer,
22    ) -> Self {
23        Self {
24            topology_context: topology_context.clone(),
25            component_context: component_context.clone(),
26            component_registry,
27            health_handle: Some(health_handle),
28            consumer,
29        }
30    }
31
32    /// Consumes the health handle of this forwarder context.
33    ///
34    /// # Panics
35    ///
36    /// Panics if the health handle has already been taken.
37    pub fn take_health_handle(&mut self) -> Health {
38        self.health_handle.take().expect("health handle already taken")
39    }
40
41    /// Returns a reference to the topology context.
42    pub fn topology_context(&self) -> &TopologyContext {
43        &self.topology_context
44    }
45
46    /// Returns a reference to the component context.
47    pub fn component_context(&self) -> &ComponentContext {
48        &self.component_context
49    }
50
51    /// Returns a reference to the component registry.
52    pub fn component_registry(&mut self) -> &ComponentRegistry {
53        &self.component_registry
54    }
55
56    /// Returns a mutable reference to the payloads consumer.
57    pub fn payloads(&mut self) -> &mut PayloadsConsumer {
58        &mut self.consumer
59    }
60}