SessionPool — Documentation by YARD 0.9.37 (original) (raw)

Class: Mongo::Session::SessionPoolPrivate

Inherits:

Object

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 Summarycollapse

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.

37 38 39 40 41 # File 'lib/mongo/session/session_pool.rb', line 37 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.

86 87 88 89 90 91 92 93 94 95 # File 'lib/mongo/session/session_pool.rb', line 86 def checkin(session) if session.nil? raise ArgumentError, 'session cannot be nil' end @mutex.synchronize do prune! @queue.unshift(session) if return_to_queue?(session) end end

#checkoutServerSession

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.

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.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.

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.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.options[: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.

51 52 53 # File 'lib/mongo/session/session_pool.rb', line 51 def inspect "#<Mongo::Session::SessionPool:0x#{object_id} current_size=#{@queue.size}>" end