Class: Mongo::Server::ConnectionPool::GenerationManager Private

Inherits:
Object
  • Object
show all
Defined in:
build/ruby-driver-master/lib/mongo/server/connection_pool/generation_manager.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0, largely rewritten in 2.9.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server:) ⇒ GenerationManager

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.

Returns a new instance of GenerationManager.

Since:

  • 2.0.0, largely rewritten in 2.9.0



25
26
27
28
29
# File 'build/ruby-driver-master/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

Instance Attribute Details

#serverObject (readonly)

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.

Since:

  • 2.0.0, largely rewritten in 2.9.0



31
32
33
# File 'build/ruby-driver-master/lib/mongo/server/connection_pool/generation_manager.rb', line 31

def server
  @server
end

Instance Method Details

#bump(service_id: nil) ⇒ 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.

Since:

  • 2.0.0, largely rewritten in 2.9.0



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'build/ruby-driver-master/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) ⇒ 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.

Since:

  • 2.0.0, largely rewritten in 2.9.0



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'build/ruby-driver-master/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