类:Mongo::Session::SessionPool Private
- 继承:
-
对象
- 对象
- Mongo::Session::SessionPool
- 定义于:
- lib/ Mongo/session/session_pool.rb
Overview
此类是私有 API 的一部分。 应尽可能避免使用此类,因为它将来可能会被删除或更改。
服务器会话池。
实例方法摘要折叠
-
# checkin (session) ⇒ 对象
private
将服务器会话签入池。
-
#checkout ⇒ ServerSession
private
从池中查看服务器会话。
-
# end_sessions ⇒ 对象
private
向服务器发送 endSessions 命令,结束池中的所有会话。
-
#initialize(cluster) ⇒ SessionPool
构造函数
private
初始化会话池。
-
#检查⇒ string
private
获取用于检查的格式化string 。
构造函数详情
#初始化(集群)→会话池
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
初始化会话池。
34 35 36 37 38 |
# File 'lib/ Mongo/session/session_pool.rb', line 34 def 初始化(集群) @queue = [] @mutex = 互斥锁.new @cluster = 集群 end |
实例方法详细信息
# checkin (session) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
将服务器会话签入池。
79 80 81 82 83 84 85 86 |
# File 'lib/ Mongo/session/session_pool.rb', line 79 def checkin(会话) 提高 ArgumentError, ' session不能为 nil ' if 会话.nil? @mutex.同步 do 修剪! @queue.unshift(会话) if return_to_queue?(会话) end end |
# checkout ⇒ ServerSession
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
从池中查看服务器会话。
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ Mongo/session/session_pool.rb', line 60 def checkout @mutex.同步 do 循环 do return ServerSession.new if @queue.空? 会话 = @queue.转变 return 会话 除非 about_to_expire?(会话) end end end |
# end_sessions ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
向服务器发送 endSessions 命令,结束池中的所有会话。
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ Mongo/session/session_pool.rb', line 94 def end_sessions 直到 @queue.空? server = ServerSelector.获取(模式: :primary_preferred).select_server(@cluster) op = 操作::命令.new( 选择器: { endSessions: @queue.转变(10 _ 000).map(和:session_id), }, db_name: Database::ADMIN ) 上下文 = 操作::上下文.new(选项: { server_api: server.[:server_api], }) op.执行(server, 上下文: 上下文) end 救援 mongo::错误, 错误::AuthError end |
#检查⇒ string
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
获取用于检查的格式化string 。
48 49 50 |
# File 'lib/ Mongo/session/session_pool.rb', line 48 def 检查 " #<Mongo::Session::SessionPool: 0 x #{ object_id } current_size= #{ @queue . size } > " end |