class Mongo::Server::ConnectionPool::GenerationManager
@api private
Attributes
server[R]
Public Class Methods
new(server:)
click to toggle source
# File lib/mongo/server/connection_pool/generation_manager.rb, line 25 def initialize(server:) @map = Hash.new { |hash, key| hash[key] = 1 } @server = server @lock = Mutex.new end
Public Instance Methods
bump(service_id: nil)
click to toggle source
# File lib/mongo/server/connection_pool/generation_manager.rb, line 48 def bump(service_id: nil) @lock.synchronize do if service_id @map[service_id] += 1 else # When service id is not supplied, one of two things may be # happening; # # 1. The pool is not to a load balancer, in which case we only # need to increment the generation for the nil service_id. # 2. The pool is to a load balancer, in which case we need to # increment the generation for each service. # # Incrementing everything in the map accomplishes both tasks. @map.each do |k, v| @map[k] += 1 end end end end
generation(service_id: nil)
click to toggle source
# File lib/mongo/server/connection_pool/generation_manager.rb, line 33 def generation(service_id: nil) if service_id unless server.load_balancer? raise ArgumentError, "Generation scoping to services is only available in load-balanced mode, but the server at #{server.address} is not a load balancer" end else if server.load_balancer? raise ArgumentError, "The server at #{server.address} is a load balancer and therefore does not have a single global generation" end end @lock.synchronize do @map[service_id] end end