saluki_core/components/encoders/
context.rs

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