类:Mongo::Session::SessionPool Private

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

Overview

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

服务器会话池。

由于:

  • 2.5.0

实例方法摘要折叠

构造函数详情

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

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

初始化会话池。

例子:

SessionPool.new(cluster)

参数:

由于:

  • 2.5.0



37
38
39
40
41
# File 'lib/ Mongo/session/session_pool.rb', line 37

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

实例方法详细信息

# checkin (session) ⇒对象

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

将服务器会话签入池。

例子:

签入会话。

pool.checkin(session)

参数:

由于:

  • 2.5.0



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

# checkoutServerSession

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

从池中查看服务器会话。

例子:

查看会话。

pool.checkout

返回:

由于:

  • 2.5.0



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

例子:

结束所有会话。

pool.end_sessions

由于:

  • 2.5.0



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 。

例子:

检查会话池对象。

session_pool.inspect

返回:

  • ( string )

    会话池检查。

由于:

  • 2.5.0



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