primary[R]
Object
Create a new set of connection pools.
The pool manager will by default use the original seed list passed to the connection objects, accessible via connection.seeds. In addition, the user may pass an additional list of seeds nodes discovered in real time. The union of these lists will be used when attempting to connect, with the newly-discovered nodes being used first.
# File lib/mongo/util/pool_manager.rb, line 24 def initialize(client, seeds=[]) @client = client @seeds = seeds @pools = Set.new @primary = nil @primary_pool = nil @secondaries = Set.new @secondary_pools = [] @hosts = Set.new @members = Set.new @refresh_required = false @max_bson_size = DEFAULT_MAX_BSON_SIZE @max_message_size = @max_bson_size * MESSAGE_SIZE_FACTOR @connect_mutex = Mutex.new thread_local[:locks][:connecting_manager] = false end
We're healthy if all members are pingable and if the view of the replica set returned by isMaster is equivalent to our view. If any of these isn't the case, set @refresh_required to true, and return.
# File lib/mongo/util/pool_manager.rb, line 71 def check_connection_health return if thread_local[:locks][:connecting_manager] members = copy_members begin seed = get_valid_seed_node rescue ConnectionFailure @refresh_required = true return end unless current_config = seed.config @refresh_required = true seed.close return end if current_config['hosts'].length != members.length @refresh_required = true seed.close return end current_config['hosts'].each do |host| member = members.detect do |m| m.address == host end if member && validate_existing_member(current_config, member) next else @refresh_required = true seed.close return end end seed.close end
# File lib/mongo/util/pool_manager.rb, line 119 def close(opts={}) begin pools.each { |pool| pool.close(opts) } rescue ConnectionFailure end end
# File lib/mongo/util/pool_manager.rb, line 115 def closed? pools.all? { |pool| pool.closed? } end
# File lib/mongo/util/pool_manager.rb, line 46 def connect @connect_mutex.synchronize do begin thread_local[:locks][:connecting_manager] = true @refresh_required = false disconnect_old_members connect_to_members initialize_pools(@members) update_max_sizes @seeds = discovered_seeds ensure thread_local[:locks][:connecting_manager] = false end end end
# File lib/mongo/util/pool_manager.rb, line 42 def inspect "<Mongo::PoolManager:0x#{self.object_id.to_s(16)} @seeds=#{@seeds}>" end
# File lib/mongo/util/pool_manager.rb, line 126 def read read_pool.host_port end
Generated with the Darkfish Rdoc Generator 2.