saluki_core/components/encoders/
context.rs

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