类:Mongo::Server::ConnectionPool::GenerationManager Private
- 继承:
-
对象
- 对象
- Mongo::Server::ConnectionPool::GenerationManager
- 定义于:
- lib/ Mongo/ 服务器/connection_pool/Generation_manager.rb
Overview
此类是私有 API 的一部分。 应尽可能避免使用此类,因为它将来可能会被删除或更改。
实例属性摘要折叠
- # server ⇒ 对象 只读 private
实例方法摘要折叠
- # Bump (service_id: nil) ⇒ 对象 private
-
# close_all_pipes ⇒ 对象
private
关闭生成管理器中的所有管道。
- #Generation (service_id: nil) ⇒ 对象 private
- #Generation_unlocked (service_id: nil) ⇒ 对象 private
-
#initialize (服务器:) ="GenerationManager"
构造函数
private
一个新的GenerationManager实例。
- # pipeline_fds (service_id: nil) ⇒ 对象 private
- # remove_pipe_fds (Generation, service_id: nil) ⇒ 对象 private
构造函数详情
#initialize (服务器:) = "GenerationManager"
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回 GenerationManager 的新实例。
25 26 27 28 29 30 31 |
# File 'lib/ Mongo/ 服务器/connection_pool/Generation_manager.rb', line 25 def 初始化(服务器:) @map = 哈希.new { |哈希, key| 哈希[key] = 1 } @pipe_fds = 哈希.new { |哈希, key| 哈希[key] = { 1 => IO.管道 } } @server = server 锁 = 互斥锁.new @scheduled_for_close = [] end |
实例属性详细信息
# server ⇒对象(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
33 34 35 |
# File 'lib/ Mongo/ 服务器/connection_pool/Generation_manager.rb', line 33 def server @server end |
实例方法详细信息
# Bump (service_id: nil) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ Mongo/ 服务器/connection_pool/Generation_manager.rb', line 68 def 碰撞(service_id: nil) 锁.同步 do close_all_scheduled if service_id gen = @map[service_id] += 1 @pipe_fds[service_id] ||= {} @pipe_fds[service_id][gen] = IO.管道 else # 未提供服务 ID 时,可能会执行以下两种操作之一: # 发生; # # 1 . 该池不是负载负载均衡器,在这种情况下,我们只需 # 需要为 nil service_id 增加一代。 # 2 . 池是负载负载均衡器,在这种情况下,我们需要 # 递增每个服务的代数。 # # 递增映射中的所有内容可完成这两项任务。 @map.每 do |k, v| gen = @map[k] += 1 @pipe_fds[service_id] ||= {} @pipe_fds[service_id][gen] = IO.管道 end end end end |
# close_all_pipes ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
关闭生成管理器中的所有管道。
仅当拥有此 GenerationManager 的 ConnectionPool 关闭时才应调用此方法,以确保所有管道均已正确关闭。
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ Mongo/ 服务器/connection_pool/Generation_manager.rb', line 99 def close_all_pipes 锁.同步 do close_all_scheduled @pipe_fds.密钥.每 do |service_id| 一代 = @pipe_fds.删除(service_id) 一代.values.每 do |(R, w)| R.关闭 w.关闭 救援 IOError # 忽略关闭时发生的任何 IOError # 管,因为我们对此无能为力。 end end end end |
#Generation (service_id: nil) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
35 36 37 38 39 40 41 |
# File 'lib/ Mongo/ 服务器/connection_pool/Generation_manager.rb', line 35 def 生成(service_id: nil) validate_service_id!(service_id) 锁.同步 do @map[service_id] end end |
#Generation_unlocked (service_id: nil) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
43 44 45 46 47 |
# File 'lib/ Mongo/ 服务器/connection_pool/Generation_manager.rb', line 43 def Generation_unlocked(service_id: nil) validate_service_id!(service_id) @map[service_id] end |
# pipeline_fds (service_id: nil) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
49 50 51 |
# File 'lib/ Mongo/ 服务器/connection_pool/Generation_manager.rb', line 49 def pipeline_fds(service_id: nil) @pipe_fds.dig(service_id, @map[service_id]) end |
# remove_pipe_fds (Generation, service_id: nil) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ Mongo/ 服务器/connection_pool/Generation_manager.rb', line 53 def remove_pipe_fds(生成, service_id: nil) validate_service_id!(service_id) R, w = @pipe_fds[service_id].删除(生成) return 除非 R && w w.关闭 # 安排关闭管的读取端。 我们无法关闭它 # 立即执行,因为我们需要等待任何 Kernel#select 调用 # 注意管道的一部分已关闭,并检查套接字。 这 # 所有这些操作都发生在尝试从套接字读取数据并等待 # 使其再次准备就绪。 @scheduled_for_close << R end |