use std::sync::Arc;
use action_core::client_server::ActionChannel;
use crate::bus::{ServiceChannel, TopicSlot};
use crate::serialization::SerializationManager;
use super::{MiddlewareLoadSnapshot, MiddlewareStack};
impl MiddlewareStack {
pub fn topic_slot(&mut self, topic: &str, depth: usize) -> Arc<TopicSlot> {
self.topic_bus.get_or_create(topic, depth)
}
pub fn service_channel(&mut self, service: &str) -> Arc<ServiceChannel> {
self.service_bus.get_or_create(service)
}
pub fn action_channel<G, F, R>(&mut self, action: &str) -> Arc<ActionChannel<G, F, R>>
where
G: Send + Sync + 'static,
F: Send + Sync + 'static,
R: Send + Sync + 'static,
{
let entry = self
.action_channels
.entry(action.to_string())
.or_insert_with(|| ActionChannel::<G, F, R>::new());
entry
.clone()
.downcast::<ActionChannel<G, F, R>>()
.expect("ActionChannel type mismatch for action")
}
pub fn load_snapshot(&self) -> MiddlewareLoadSnapshot {
MiddlewareLoadSnapshot {
topics: self.topic_bus.load_entries(),
services: self.service_bus.load_entries(),
session_lifecycle: self.session_manager.lifecycle_counts(),
discovery: self.discovery.snapshot(),
}
}
pub fn serialization(&self) -> &dyn SerializationManager {
&self.serialization
}
}