middleware_core/stack/
channels.rs1use std::sync::Arc;
2
3use action_core::client_server::ActionChannel;
4
5use crate::bus::{ServiceChannel, TopicSlot};
6use crate::serialization::SerializationManager;
7
8use super::{MiddlewareLoadSnapshot, MiddlewareStack};
9
10impl MiddlewareStack {
11 pub fn topic_slot(&mut self, topic: &str, depth: usize) -> Arc<TopicSlot> {
14 self.topic_bus.get_or_create(topic, depth)
15 }
16
17 pub fn service_channel(&mut self, service: &str) -> Arc<ServiceChannel> {
19 self.service_bus.get_or_create(service)
20 }
21
22 pub fn action_channel<G, F, R>(&mut self, action: &str) -> Arc<ActionChannel<G, F, R>>
28 where
29 G: Send + Sync + 'static,
30 F: Send + Sync + 'static,
31 R: Send + Sync + 'static,
32 {
33 let entry = self
34 .action_channels
35 .entry(action.to_string())
36 .or_insert_with(|| ActionChannel::<G, F, R>::new());
37 entry
38 .clone()
39 .downcast::<ActionChannel<G, F, R>>()
40 .expect("ActionChannel type mismatch for action")
41 }
42
43 pub fn load_snapshot(&self) -> MiddlewareLoadSnapshot {
44 MiddlewareLoadSnapshot {
45 topics: self.topic_bus.load_entries(),
46 services: self.service_bus.load_entries(),
47 session_lifecycle: self.session_manager.lifecycle_counts(),
48 discovery: self.discovery.snapshot(),
49 }
50 }
51
52 pub fn serialization(&self) -> &dyn SerializationManager {
53 &self.serialization
54 }
55}