Class: Mongo::Session::SessionPool Private
- Inherits:
-
Object
- Object
- Mongo::Session::SessionPool
- Defined in:
- 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.
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.
34 35 36 37 38 |
# File 'lib/mongo/session/session_pool.rb', line 34 def initialize(cluster) @queue = [] @mutex = Mutex.new @cluster = cluster 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.
79 80 81 82 83 84 85 86 |
# File 'lib/mongo/session/session_pool.rb', line 79 def checkin(session) raise ArgumentError, 'session cannot be nil' if session.nil? @mutex.synchronize do prune! @queue.unshift(session) if return_to_queue?(session) 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.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/mongo/session/session_pool.rb', line 60 def checkout @mutex.synchronize do loop do return ServerSession.new if @queue.empty? session = @queue.shift return session unless about_to_expire?(session) 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.
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 until @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.
48 49 50 |
# File 'lib/mongo/session/session_pool.rb', line 48 def inspect "#<Mongo::Session::SessionPool:0x#{object_id} current_size=#{@queue.size}>" end |