sentinel_proxy/agents/
pool.rs1use std::sync::atomic::{AtomicU32, AtomicU64};
4use std::sync::Arc;
5use std::time::{Duration, Instant};
6
7use sentinel_agent_protocol::AgentClient;
8use tokio::sync::RwLock;
9
10pub struct AgentConnectionPool {
12 pub(super) max_connections: usize,
14 pub(super) min_idle: usize,
15 pub(super) max_idle: usize,
16 pub(super) idle_timeout: Duration,
17 pub(super) connections: Arc<RwLock<Vec<AgentConnection>>>,
19 pub(super) active_count: AtomicU32,
21 pub(super) total_created: AtomicU64,
23}
24
25pub(super) struct AgentConnection {
27 pub client: AgentClient,
29 pub created_at: Instant,
31 pub last_used: Instant,
33 pub healthy: bool,
35}
36
37impl AgentConnectionPool {
38 pub fn new(
40 max_connections: usize,
41 min_idle: usize,
42 max_idle: usize,
43 idle_timeout: Duration,
44 ) -> Self {
45 Self {
46 max_connections,
47 min_idle,
48 max_idle,
49 idle_timeout,
50 connections: Arc::new(RwLock::new(Vec::new())),
51 active_count: AtomicU32::new(0),
52 total_created: AtomicU64::new(0),
53 }
54 }
55
56 pub fn active_count(&self) -> u32 {
58 self.active_count.load(std::sync::atomic::Ordering::Relaxed)
59 }
60
61 pub fn total_created(&self) -> u64 {
63 self.total_created.load(std::sync::atomic::Ordering::Relaxed)
64 }
65}