1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::collections::HashMap;

use util::sync::Mutex;

use super::StatsReportType;

#[derive(Debug, Default)]
pub struct StatsCollector {
    pub(crate) reports: Mutex<HashMap<String, StatsReportType>>,
}

impl StatsCollector {
    pub(crate) fn new() -> Self {
        StatsCollector {
            ..Default::default()
        }
    }

    pub(crate) fn insert(&self, id: String, stats: StatsReportType) {
        let mut reports = self.reports.lock();
        reports.insert(id, stats);
    }

    pub(crate) fn merge(&self, stats: HashMap<String, StatsReportType>) {
        let mut reports = self.reports.lock();
        reports.extend(stats)
    }

    pub(crate) fn into_reports(self) -> HashMap<String, StatsReportType> {
        self.reports.into_inner()
    }
}