use std::any::Any;
use anyhow::Result;
use super::{GetPrefixesRequest, GetRequest, IterateRequest, ProofResponse, ReadSync};
pub struct StatsCollector {
pub sync_get_count: usize,
pub sync_get_prefixes_count: usize,
pub sync_iterate_count: usize,
rs: Box<dyn ReadSync>,
}
impl StatsCollector {
pub fn new(rs: Box<dyn ReadSync>) -> StatsCollector {
StatsCollector {
sync_get_count: 0,
sync_get_prefixes_count: 0,
sync_iterate_count: 0,
rs,
}
}
}
impl ReadSync for StatsCollector {
fn as_any(&self) -> &dyn Any {
self
}
fn sync_get(&mut self, request: GetRequest) -> Result<ProofResponse> {
self.sync_get_count += 1;
self.rs.sync_get(request)
}
fn sync_get_prefixes(&mut self, request: GetPrefixesRequest) -> Result<ProofResponse> {
self.sync_get_prefixes_count += 1;
self.rs.sync_get_prefixes(request)
}
fn sync_iterate(&mut self, request: IterateRequest) -> Result<ProofResponse> {
self.sync_iterate_count += 1;
self.rs.sync_iterate(request)
}
}