Method: Mongo::Cluster#set_server_list
- Defined in:
- lib/mongo/cluster.rb
#set_server_list(server_address_strs) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the list of servers to the addresses in the provided list of address strings.
This method is called by the SRV monitor after receiving new DNS records for the monitored hostname.
Removes servers in the cluster whose addresses are not in the passed list of server addresses, and adds servers for any addresses in the argument which are not already in the cluster.
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
# File 'lib/mongo/cluster.rb', line 712 def set_server_list(server_address_strs) @sdam_flow_lock.synchronize do # If one of the new addresses is not in the current servers list, # add it to the servers list. server_address_strs.each do |address_str| unless servers_list.any? { |server| server.address.seed == address_str } add(address_str) end end # If one of the servers' addresses are not in the new address list, # remove that server from the servers list. servers_list.each do |server| unless server_address_strs.any? { |address_str| server.address.seed == address_str } remove(server.address.seed) end end end end |