pub fn configure(settings: &Settings, components: &[ComponentInfo]) -> Result<Option<ComponentSender>, ComponentError> {
    // ensure our service is configure in services
    if !settings.services.contains("ChatService") {
        log::debug!("chat service is not configured");
        return Ok(None);
    }
    // find ourself in the list
    for c in &settings.coordinator {
        if let Some(v) = c.get("ChatCoordinator") {
            let coordinator = match v {
                CoordinatorVariant::SimpleTcpConfig { tcp_address, kv } if kv.is_some() => {
                    let mutable = Mutex::new(MutableCoordinatorData {
                        kv: kv.as_ref().unwrap().clone(),
                        ..MutableCoordinatorData::default()
                    });
                    Some(ChatCoordinator {
                        net_sender: get_network_sender(),
                        bind_addr: tcp_address.to_string(),
                        components: components.to_owned(),
                        mutable,
                    })
                },
                #[allow(unreachable_patterns)] // in case it becomes reachable, we want to know
                _ => None,
            };
            if let Some(coordinator) = coordinator {
                {
                    // maybe move up and into the match
                    let mutable = coordinator.mutable.lock();
                    if coordinator.bind_addr.parse::<SocketAddr>().is_err() {
                        log::error!("Unable to parse {} into a SocketAddr", &coordinator.bind_addr);
                        continue;
                    }
                    if !mutable.kv.contains_key(&"name_prompt".to_string()) {
                        log::error!("chat service is missing keyword name_prompt from config");
                        continue;
                    }
                }
                log::debug!("chat service selected configuration: {:#?}", v);
                let (m, sender) = executor::connect::<_, NetCmd>(coordinator);
                // save out network sender until we give it away during start
                m.mutable.lock().my_sender.replace(sender);
                let sender = executor::and_connect::<_, ComponentCmd>(&m);
                return Ok(Some(sender));
            }
        }
    }
    log::warn!("The configuration for the chat service coordinator was not found.");
    Err(ComponentError::BadConfig(
        "The configuration for the chat service coordinator was not found.".to_string(),
    ))
}
/// Not quite as simple as the echo service, which has a pathway of Coordinate -> Consumer -> Producer -> Coordinator
///
/// Normally, we'd add a new component to manage routing with multiple chat rooms. However, we're going to cheap
/// out and just have a single room.
Not quite as simple as the echo service, which has a pathway of Coordinate -> Consumer -> Producer -> Coordinator
Normally, we'd add a new component to manage routing with multiple chat rooms. However, we're going to cheap
out and just have a single room.
Not quite as simple as the echo service which has a pathway of Coordinate - > Consumer - > Producer - > Coordinator Normally we ' d add a new component to manage routing with multiple chat rooms . However we ' re going to cheap out and just have a single room .
pub fn configure(settings: &Settings, components: &[ComponentInfo]) -> Result<Option<ComponentSender>, ComponentError> {
    // ensure our service is configure in services
    if !settings.services.contains("ChatService") {
        log::debug!("chat service is not configured");
        return Ok(None);
    }
    // find ourself in the list
    for c in &settings.coordinator {
        if let Some(v) = c.get("ChatCoordinator") {
            let coordinator = match v {
                CoordinatorVariant::SimpleTcpConfig { tcp_address, kv } if kv.is_some() => {
                    let mutable = Mutex::new(MutableCoordinatorData {
                        kv: kv.as_ref().unwrap().clone(),
                        ..MutableCoordinatorData::default()
                    });
                    Some(ChatCoordinator {
                        net_sender: get_network_sender(),
                        bind_addr: tcp_address.to_string(),
                        components: components.to_owned(),
                        mutable,
                    })
                },
                #[allow(unreachable_patterns)] // in case it becomes reachable, we want to know
                _ => None,
            };
            if let Some(coordinator) = coordinator {
                {
                    // maybe move up and into the match
                    let mutable = coordinator.mutable.lock();
                    if coordinator.bind_addr.parse::<SocketAddr>().is_err() {
                        log::error!("Unable to parse {} into a SocketAddr", &coordinator.bind_addr);
                        continue;
                    }
                    if !mutable.kv.contains_key(&"name_prompt".to_string()) {
                        log::error!("chat service is missing keyword name_prompt from config");
                        continue;
                    }
                }
                log::debug!("chat service selected configuration: {:#?}", v);
                let (m, sender) = executor::connect::<_, NetCmd>(coordinator);
                // save out network sender until we give it away during start
                m.mutable.lock().my_sender.replace(sender);
                let sender = executor::and_connect::<_, ComponentCmd>(&m);
                return Ok(Some(sender));
            }
        }
    }
    log::warn!("The configuration for the chat service coordinator was not found.");
    Err(ComponentError::BadConfig(
        "The configuration for the chat service coordinator was not found.".to_string(),
    ))
}
pub fn configure ( settings : & Settings , components : & [ ComponentInfo ] ) -> Result < Option < ComponentSender > , ComponentError > { // ensure our service is configure in services if ! settings . services . contains ( " " ) { log :: debug ! ( " " ) ; return Ok ( None ) ; } // find ourself in the list for c in & settings . coordinator { if let Some ( v ) = c . get ( " " ) { let coordinator = match v { CoordinatorVariant :: SimpleTcpConfig { tcp_address , kv } if kv . is_some ( ) => { let mutable = Mutex :: new ( MutableCoordinatorData { kv : kv . as_ref ( ) . unwrap ( ) . clone ( ) , .. MutableCoordinatorData :: default ( ) } ) ; Some ( ChatCoordinator { net_sender : get_network_sender ( ) , bind_addr : tcp_address . to_string ( ) , components : components . to_owned ( ) , mutable , } ) } , # [ allow ( unreachable_patterns ) ] // in case it becomes reachable, we want to know _ => None , } ; if let Some ( coordinator ) = coordinator { { // maybe move up and into the match let mutable = coordinator . mutable . lock ( ) ; if coordinator . bind_addr . parse :: < SocketAddr > ( ) . is_err ( ) { log :: error ! ( " " coordinator bind_addr ) ; continue ; } if ! mutable . kv . contains_key ( & " " . to_string ( ) ) { log :: error ! ( " " ) ; continue ; } } log :: debug ! ( " " v ) ; let ( m , sender ) = executor :: connect :: < _ , NetCmd > ( coordinator ) ; // save out network sender until we give it away during start m . mutable . lock ( ) . my_sender . replace ( sender ) ; let sender = executor :: and_connect :: < _ , ComponentCmd > ( & m ) ; return Ok ( Some ( sender ) ) ; } } } log :: warn ! ( " " ) ; Err ( ComponentError :: BadConfig ( " " . to_string ( ) , ) ) }
Not quite as simple as the echo service, which has a pathway of Coordinate -> Consumer -> Producer -> Coordinator
Normally, we'd add a new component to manage routing with multiple chat rooms.
Not quite as simple as the echo service which has a pathway of Coordinate - > Consumer - > Producer - > Coordinator Normally we ' d add a new component to manage routing with multiple chat rooms .
settings
&Settings
components
&[ComponentInfo]