saluki_core/components/forwarders/
context.rs

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