saluki_core/components/decoders/
context.rs1use crate::accounting::ComponentRegistry;
2use crate::health::Health;
3use crate::runtime::SupervisorHandle;
4use crate::{
5 components::ComponentContext,
6 topology::{EventsDispatcher, PayloadsConsumer, TopologyContext},
7};
8
9pub struct DecoderContext {
11 topology_context: TopologyContext,
12 component_context: ComponentContext,
13 component_registry: ComponentRegistry,
14 health_handle: Option<Health>,
15 dispatcher: EventsDispatcher,
16 consumer: PayloadsConsumer,
17 supervisor_handle: SupervisorHandle,
18}
19
20impl DecoderContext {
21 pub fn new(
23 topology_context: &TopologyContext, component_context: &ComponentContext,
24 component_registry: ComponentRegistry, health_handle: Health, dispatcher: EventsDispatcher,
25 consumer: PayloadsConsumer, supervisor_handle: SupervisorHandle,
26 ) -> Self {
27 Self {
28 topology_context: topology_context.clone(),
29 component_context: component_context.clone(),
30 component_registry,
31 health_handle: Some(health_handle),
32 dispatcher,
33 consumer,
34 supervisor_handle,
35 }
36 }
37
38 pub fn take_health_handle(&mut self) -> Health {
44 self.health_handle.take().expect("health handle already taken")
45 }
46
47 pub fn topology_context(&self) -> &TopologyContext {
49 &self.topology_context
50 }
51
52 pub fn component_context(&self) -> &ComponentContext {
54 &self.component_context
55 }
56
57 pub fn component_registry(&mut self) -> &ComponentRegistry {
59 &self.component_registry
60 }
61
62 pub fn dispatcher(&self) -> &EventsDispatcher {
64 &self.dispatcher
65 }
66
67 pub fn payloads(&mut self) -> &mut PayloadsConsumer {
69 &mut self.consumer
70 }
71
72 pub fn spawn_handle(&self) -> &SupervisorHandle {
78 &self.supervisor_handle
79 }
80}