<commit_before>// Copyright (c) 2020 DDN. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use crate::{
    agent_error::ImlAgentError,
    daemon_plugins::{DaemonPlugin, Output},
    env,
    http_comms::mailbox_client::send,
};
use async_trait::async_trait;
use futures::{
    executor::block_on,
    stream::{StreamExt as _, TryStreamExt},
    Future, FutureExt,
};
use inotify::{Inotify, WatchMask};
use std::{
    collections::{HashMap, HashSet},
    pin::Pin,
    sync::Arc,
};
use stream_cancel::{Trigger, Tripwire};
use tokio::{fs, net::UnixListener, sync::Mutex};
use tokio_util::codec::{BytesCodec, FramedRead};

pub struct PostOffice {
    // individual mailbox socket listeners
    routes: Arc<Mutex<HashMap<String, Trigger>>>,
    trigger: Option<Trigger>,
}

pub fn create() -> impl DaemonPlugin {
    PostOffice {
        routes: Arc::new(Mutex::new(HashMap::new())),
        trigger: None,
    }
}

/// Return socket address for a given mailbox
pub fn socket_name(mailbox: &str) -> String {
    let sock_dir = env::get_var("SOCK_DIR");
    format!("{}/postman-{}.sock", sock_dir, mailbox)
}

impl std::fmt::Debug for PostOffice {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(
            f,
            "PostOffice {{ {:?} }}",
            block_on(self.routes.lock()).keys()
        )
    }
}<commit_msg>Remove blocking debug in postoffice (#2002)<commit_after>// Copyright (c) 2020 DDN. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use crate::{
    agent_error::ImlAgentError,
    daemon_plugins::{DaemonPlugin, Output},
    env,
    http_comms::mailbox_client::send,
};
use async_trait::async_trait;
use futures::{
    stream::{StreamExt as _, TryStreamExt},
    Future, FutureExt,
};
use inotify::{Inotify, WatchMask};
use std::{
    collections::{HashMap, HashSet},
    pin::Pin,
    sync::Arc,
};
use stream_cancel::{Trigger, Tripwire};
use tokio::{fs, net::UnixListener, sync::Mutex};
use tokio_util::codec::{BytesCodec, FramedRead};

pub struct PostOffice {
    // individual mailbox socket listeners
    routes: Arc<Mutex<HashMap<String, Trigger>>>,
    trigger: Option<Trigger>,
}

pub fn create() -> impl DaemonPlugin {
    PostOffice {
        routes: Arc::new(Mutex::new(HashMap::new())),
        trigger: None,
    }
}

/// Return socket address for a given mailbox
pub fn socket_name(mailbox: &str) -> String {
    let sock_dir = env::get_var("SOCK_DIR");
    format!("{}/postman-{}.sock", sock_dir, mailbox)
}

impl std::fmt::Debug for PostOffice {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "PostOffice {{ {:?} }}", self.routes)
    }
}
{'fraction_non_alphanumeric': 0.15658362989323843, 'fraction_numerical': 0.004270462633451958, 'mean_word_length': 3.7887563884156727, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2754777', 'n_tokens_mistral': 918, 'n_tokens_neox': 932, 'n_words': 237}