类: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 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
初始化会话池。
37 38 39 40 41 |
# File 'lib/ Mongo/session/session_pool.rb', line 37 def 初始化(集群) @queue = [] @mutex = 互斥锁.new @cluster = 集群 end |
实例方法详细信息
# checkin (session) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
将服务器会话签入池。
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ Mongo/session/session_pool.rb', line 86 def checkin(会话) if 会话.nil? 提高 ArgumentError, ' session不能为 nil ' end @mutex.同步 do 修剪! @queue.unshift(会话) if return_to_queue?(会话) end end |
# checkout ⇒ ServerSession
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
从池中查看服务器会话。
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ Mongo/session/session_pool.rb', line 63 def checkout @mutex.同步 do 循环 do if @queue.空? return ServerSession.new else 会话 = @queue.转变 除非 about_to_expire?(会话) return 会话 end end end end end |
# end_sessions ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
向服务器发送 endSessions 命令,结束池中的所有会话。
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ Mongo/session/session_pool.rb', line 103 def end_sessions while !@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 。
51 52 53 |
# File 'lib/ Mongo/session/session_pool.rb', line 51 def 检查 " #<Mongo::Session::SessionPool: 0 x #{ object_id } current_size= #{ @queue . size } > " end |