Class: Mongo::Session::SessionPool Private
- Inherits:
-
Object
- Object
- Mongo::Session::SessionPool
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/session/session_pool.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A pool of server sessions.
Class Method Summary collapse
-
.create(cluster) ⇒ Object
private
Create a SessionPool.
Instance Method Summary collapse
-
#checkin(session) ⇒ Object
private
Checkin a server session to the pool.
-
#checkout ⇒ ServerSession
private
Check out a server session from the pool.
-
#end_sessions ⇒ Object
private
End all sessions in the pool by sending the endSessions command to the server.
-
#initialize(cluster) ⇒ SessionPool
constructor
private
Initialize a SessionPool.
-
#inspect ⇒ String
private
Get a formatted string for use in inspection.
Constructor Details
#initialize(cluster) ⇒ SessionPool
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a SessionPool.
52 53 54 55 56 |
# File 'build/ruby-driver-v2.19/lib/mongo/session/session_pool.rb', line 52 def initialize(cluster) @queue = [] @mutex = Mutex.new @cluster = cluster end |
Class Method Details
.create(cluster) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a SessionPool.
38 39 40 41 |
# File 'build/ruby-driver-v2.19/lib/mongo/session/session_pool.rb', line 38 def self.create(cluster) pool = new(cluster) cluster.instance_variable_set(:@session_pool, pool) end |
Instance Method Details
#checkin(session) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checkin a server session to the pool.
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'build/ruby-driver-v2.19/lib/mongo/session/session_pool.rb', line 101 def checkin(session) if session.nil? raise ArgumentError, 'session cannot be nil' end @mutex.synchronize do prune! unless about_to_expire?(session) @queue.unshift(session) end end end |
#checkout ⇒ ServerSession
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check out a server session from the pool.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'build/ruby-driver-v2.19/lib/mongo/session/session_pool.rb', line 78 def checkout @mutex.synchronize do loop do if @queue.empty? return ServerSession.new else session = @queue.shift unless about_to_expire?(session) return session end end end end end |
#end_sessions ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
End all sessions in the pool by sending the endSessions command to the server.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'build/ruby-driver-v2.19/lib/mongo/session/session_pool.rb', line 120 def end_sessions while !@queue.empty? server = ServerSelector.get(mode: :primary_preferred).select_server(@cluster) op = Operation::Command.new( selector: { endSessions: @queue.shift(10_000).map(&:session_id), }, db_name: Database::ADMIN, ) context = Operation::Context.new(options: { server_api: server.[:server_api], }) op.execute(server, context: context) end rescue Mongo::Error, Error::AuthError end |
#inspect ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a formatted string for use in inspection.
66 67 68 |
# File 'build/ruby-driver-v2.19/lib/mongo/session/session_pool.rb', line 66 def inspect "#<Mongo::Session::SessionPool:0x#{object_id} current_size=#{@queue.size}>" end |