lib/mongo/cluster.rb in mongo-2.0.6 vs lib/mongo/cluster.rb in mongo-2.1.0.beta

- old
+ new

@@ -65,29 +65,35 @@ address = Address.new(host) if !addresses.include?(address) if addition_allowed?(address) log_debug([ "Adding #{address.to_s} to the cluster." ]) @update_lock.synchronize { @addresses.push(address) } - server = Server.new(address, self, event_listeners, options) + server = Server.new(address, self, @monitoring, event_listeners, options) @update_lock.synchronize { @servers.push(server) } server end end end # Instantiate the new cluster. # + # @api private + # # @example Instantiate the cluster. - # Mongo::Cluster.new(["127.0.0.1:27017"]) + # Mongo::Cluster.new(["127.0.0.1:27017"], monitoring) # + # @note Cluster should never be directly instantiated outside of a Client. + # # @param [ Array<String> ] seeds The addresses of the configured servers. + # @param [ Monitoring ] monitoring The monitoring. # @param [ Hash ] options The options. # # @since 2.0.0 - def initialize(seeds, options = {}) + def initialize(seeds, monitoring, options = {}) @addresses = [] @servers = [] + @monitoring = monitoring @event_listeners = Event::Listeners.new @options = options.freeze @topology = Topology.initial(seeds, options) @update_lock = Mutex.new @@ -194,10 +200,35 @@ # @since 2.0.0 def servers topology.servers(servers_list.compact).compact end + # Disconnect all servers. + # + # @example Disconnect the cluster's servers. + # cluster.disconnect! + # + # @return [ true ] Always true. + # + # @since 2.1.0 + def disconnect! + @servers.each { |server| server.disconnect! } and true + end + + # Reconnect all servers. + # + # @example Reconnect the cluster's servers. + # cluster.reconnect! + # + # @return [ true ] Always true. + # + # @since 2.1.0 + def reconnect! + scan! + servers.each { |server| server.reconnect! } and true + end + # Add hosts in a description to the cluster. # # @example Add hosts in a description to the cluster. # cluster.add_hosts(description) # @@ -238,10 +269,14 @@ # # @return [ Cluster ] The cluster. # # @since 2.0.0 def self.create(client) - cluster = Cluster.new(client.cluster.addresses.map(&:to_s), client.options) + cluster = Cluster.new( + client.cluster.addresses.map(&:to_s), + client.instance_variable_get(:@monitoring).dup, + client.options + ) client.instance_variable_set(:@cluster, cluster) end # The addresses in the cluster. #