类:Mongo::Session::SessionPool Private

继承:
对象
  • 对象
显示全部
定义于:
lib/ Mongo/session/session_pool.rb

Overview

此类是私有 API 的一部分。 应尽可能避免使用此类,因为它将来可能会被删除或更改。

服务器会话池。

由于:

  • 2.5.0

实例方法摘要折叠

构造函数详情

#初始化(集群)→会话池

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

初始化会话池。

例子:

SessionPool.new(cluster)

参数:

由于:

  • 2.5.0



34
35
36
37
38
# File 'lib/ Mongo/session/session_pool.rb', line 34

def 初始化(集群)
  @queue = []
  @mutex = 互斥锁.new
  @cluster = 集群
end

实例方法详细信息

# checkin (session) ⇒对象

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

将服务器会话签入池。

例子:

签入会话。

pool.checkin(session)

参数:

引发:

  • ( ArgumentError )

由于:

  • 2.5.0



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

# checkoutServerSession

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

从池中查看服务器会话。

例子:

查看会话。

pool.checkout

返回:

由于:

  • 2.5.0



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 命令,结束池中的所有会话。

例子:

结束所有会话。

pool.end_sessions

由于:

  • 2.5.0



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 。

例子:

检查会话池对象。

session_pool.inspect

返回:

  • ( string )

    会话池检查。

由于:

  • 2.5.0



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