#[macro_export]
macro_rules! base_pool_impl {
(
$state:ident
) => {
fn get_id(&self) -> &str {
&self.$state.id
}
fn set_id(&mut self, id: &str) {
self.$state.id = id.to_string();
}
fn set_max_conn(&self, mut max: Option<usize>) {
if let Some(0) = max {
max = None;
}
match max {
None => self
.$state
.max_conn
.store(usize::MAX, std::sync::atomic::Ordering::Relaxed),
Some(v) => self
.$state
.max_conn
.store(v, std::sync::atomic::Ordering::Relaxed),
}
}
fn get_max_conn(&self) -> Option<usize> {
match self
.$state
.max_conn
.load(std::sync::atomic::Ordering::Relaxed)
{
usize::MAX => None,
v => Some(v),
}
}
fn get_cur_conn(&self) -> usize {
self.$state
.cur_conn
.load(std::sync::atomic::Ordering::Relaxed)
}
fn set_keepalive(&self, mut duration: Option<std::time::Duration>) {
if let Some(d) = duration {
if d.is_zero() {
duration = None;
}
}
match duration {
None => self
.$state
.keepalive
.store(u64::MAX, std::sync::atomic::Ordering::Relaxed),
Some(v) => self
.$state
.keepalive
.store(v.as_secs(), std::sync::atomic::Ordering::Relaxed),
}
}
fn get_keepalive(&self) -> Option<std::time::Duration> {
match self
.$state
.keepalive
.load(std::sync::atomic::Ordering::Relaxed)
{
u64::MAX => None,
v => Some(std::time::Duration::from_secs(v)),
}
}
fn get_strategy(&self) -> Arc<dyn Strategy> {
self.$state.lb_strategy.clone()
}
fn set_strategy(&mut self, strategy: Arc<dyn Strategy>) {
self.$state.lb_strategy = strategy;
}
};
}
#[allow(unused_imports)]
pub use base_pool_impl;