saluki_core/components/sources/
context.rs1use std::sync::Arc;
2
3use resource_accounting::ComponentRegistry;
4use saluki_common::sync::shutdown::ShutdownHandle;
5
6use crate::health::Health;
7use crate::{
8 components::ComponentContext,
9 topology::{EventsDispatcher, TopologyContext},
10};
11
12struct SourceContextInner {
13 topology_context: TopologyContext,
14 component_context: ComponentContext,
15 component_registry: ComponentRegistry,
16 dispatcher: EventsDispatcher,
17}
18
19pub struct SourceContext {
21 shutdown_handle: Option<ShutdownHandle>,
22 health_handle: Option<Health>,
23 inner: Arc<SourceContextInner>,
24}
25
26impl SourceContext {
27 pub fn new(
29 topology_context: &TopologyContext, component_context: &ComponentContext,
30 component_registry: ComponentRegistry, shutdown_handle: ShutdownHandle, health_handle: Health,
31 dispatcher: EventsDispatcher,
32 ) -> Self {
33 Self {
34 shutdown_handle: Some(shutdown_handle),
35 health_handle: Some(health_handle),
36 inner: Arc::new(SourceContextInner {
37 topology_context: topology_context.clone(),
38 component_context: component_context.clone(),
39 component_registry,
40 dispatcher,
41 }),
42 }
43 }
44
45 pub fn take_shutdown_handle(&mut self) -> ShutdownHandle {
51 self.shutdown_handle.take().expect("shutdown handle already taken")
52 }
53
54 pub fn take_health_handle(&mut self) -> Health {
60 self.health_handle.take().expect("health handle already taken")
61 }
62
63 pub fn topology_context(&self) -> &TopologyContext {
65 &self.inner.topology_context
66 }
67
68 pub fn component_context(&self) -> &ComponentContext {
70 &self.inner.component_context
71 }
72
73 pub fn component_registry(&self) -> &ComponentRegistry {
75 &self.inner.component_registry
76 }
77
78 pub fn dispatcher(&self) -> &EventsDispatcher {
80 &self.inner.dispatcher
81 }
82}
83
84impl Clone for SourceContext {
85 fn clone(&self) -> Self {
86 Self {
87 shutdown_handle: None,
88 health_handle: None,
89 inner: self.inner.clone(),
90 }
91 }
92}