saluki_core/components/decoders/
context.rs

1use crate::accounting::ComponentRegistry;
2use crate::health::Health;
3use crate::{
4    components::ComponentContext,
5    topology::{EventsDispatcher, PayloadsConsumer, TopologyContext},
6};
7
8/// Decoder context.
9pub struct DecoderContext {
10    topology_context: TopologyContext,
11    component_context: ComponentContext,
12    component_registry: ComponentRegistry,
13    health_handle: Option<Health>,
14    dispatcher: EventsDispatcher,
15    consumer: PayloadsConsumer,
16}
17
18impl DecoderContext {
19    /// Creates a new `DecoderContext`.
20    pub fn new(
21        topology_context: &TopologyContext, component_context: &ComponentContext,
22        component_registry: ComponentRegistry, health_handle: Health, dispatcher: EventsDispatcher,
23        consumer: PayloadsConsumer,
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 decoder 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 events dispatcher.
60    pub fn dispatcher(&self) -> &EventsDispatcher {
61        &self.dispatcher
62    }
63
64    /// Returns a mutable reference to the payloads consumer.
65    pub fn payloads(&mut self) -> &mut PayloadsConsumer {
66        &mut self.consumer
67    }
68}