/// Update the topology description based on the provided server description. Also add new
/// servers and remove missing ones as needed.
Update the topology description based on the provided server description. Also add new
servers and remove missing ones as needed.
Update the topology description based on the provided server description . Also add new servers and remove missing ones as needed .
fn update(
        &mut self,
        server: ServerDescription,
        options: &ClientOptions,
        topology: WeakTopology,
    ) -> std::result::Result<bool, String> {
        let old_description = self.description.clone();
        self.description.update(server)?;
        let hosts: HashSet<_> = self.description.server_addresses().cloned().collect();
        self.sync_hosts(&hosts, options, &topology);
        let diff = old_description.diff(&self.description);
        let topology_changed = diff.is_some();
        if let Some(ref handler) = options.sdam_event_handler {
            if let Some(diff) = diff {
                for (address, (previous_description, new_description)) in diff.changed_servers {
                    let event = ServerDescriptionChangedEvent {
                        address: address.clone(),
                        topology_id: topology.common.id,
                        previous_description: ServerInfo::new_owned(previous_description.clone()),
                        new_description: ServerInfo::new_owned(new_description.clone()),
                    };
                    handler.handle_server_description_changed_event(event);
                }
                for address in diff.removed_addresses {
                    let event = ServerClosedEvent {
                        address: address.clone(),
                        topology_id: topology.common.id,
                    };
                    handler.handle_server_closed_event(event);
                }
                for address in diff.added_addresses {
                    let event = ServerOpeningEvent {
                        address: address.clone(),
                        topology_id: topology.common.id,
                    };
                    handler.handle_server_opening_event(event);
                }
                let event = TopologyDescriptionChangedEvent {
                    topology_id: topology.common.id,
                    previous_description: old_description.clone().into(),
                    new_description: self.description.clone().into(),
                };
                handler.handle_topology_description_changed_event(event);
            }
        }
        Ok(topology_changed)
    }
fn update ( & mut self , server : ServerDescription , options : & ClientOptions , topology : WeakTopology , ) -> std :: result :: Result < bool , String > { let old_description = self . description . clone ( ) ; self . description . update ( server ) ? ; let hosts : HashSet < _ > = self . description . server_addresses ( ) . cloned ( ) . collect ( ) ; self . sync_hosts ( & hosts , options , & topology ) ; let diff = old_description . diff ( & self . description ) ; let topology_changed = diff . is_some ( ) ; if let Some ( ref handler ) = options . sdam_event_handler { if let Some ( diff ) = diff { for ( address , ( previous_description , new_description ) ) in diff . changed_servers { let event = ServerDescriptionChangedEvent { address : address . clone ( ) , topology_id : topology . common . id , previous_description : ServerInfo :: new_owned ( previous_description . clone ( ) ) , new_description : ServerInfo :: new_owned ( new_description . clone ( ) ) , } ; handler . handle_server_description_changed_event ( event ) ; } for address in diff . removed_addresses { let event = ServerClosedEvent { address : address . clone ( ) , topology_id : topology . common . id , } ; handler . handle_server_closed_event ( event ) ; } for address in diff . added_addresses { let event = ServerOpeningEvent { address : address . clone ( ) , topology_id : topology . common . id , } ; handler . handle_server_opening_event ( event ) ; } let event = TopologyDescriptionChangedEvent { topology_id : topology . common . id , previous_description : old_description . clone ( ) . into ( ) , new_description : self . description . clone ( ) . into ( ) , } ; handler . handle_topology_description_changed_event ( event ) ; } } Ok ( topology_changed ) }
Update the topology description based on the provided server description.
Update the topology description based on the provided server description .
&mut self
server
ServerDescription
options
&ClientOptions
topology
WeakTopology