use std::any::Any;
use std::collections::{HashMap, VecDeque};
use std::sync::{Arc, Mutex};
mod service;
mod topic;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct TopicLoadEntry {
pub topic: String,
pub pending: usize,
pub max_depth: usize,
}
impl TopicLoadEntry {
pub fn utilization_ratio(&self) -> f64 {
if self.max_depth == 0 {
return 0.0;
}
self.pending as f64 / self.max_depth as f64
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ServiceLoadEntry {
pub service: String,
pub pending_requests: usize,
pub pending_responses: usize,
}
pub struct TopicSlot {
queue: Mutex<VecDeque<Box<dyn Any + Send>>>,
max_depth: usize,
}
pub struct TopicBus {
slots: HashMap<String, Arc<TopicSlot>>,
default_depth: usize,
}
impl Default for TopicBus {
fn default() -> Self {
Self {
slots: HashMap::new(),
default_depth: 16,
}
}
}
pub struct ServiceChannel {
requests: Mutex<VecDeque<(u64, Box<dyn Any + Send>)>>,
responses: Mutex<HashMap<u64, Box<dyn Any + Send>>>,
}
impl Default for ServiceChannel {
fn default() -> Self {
Self {
requests: Mutex::new(VecDeque::new()),
responses: Mutex::new(HashMap::new()),
}
}
}
#[derive(Default)]
pub struct ServiceBus {
channels: HashMap<String, Arc<ServiceChannel>>,
}