lib/mongo/server/connection_pool.rb
# Closes all idle connections in the pool and schedules currently checked
# out connections to be closed when they are checked back into the pool.
# The pool remains operational and can create new connections when
# requested.
#
# @option options [ true | false ] :lazy If true, do not close any of
#   the idle connections and instead let them be closed during a
#   subsequent check out operation.
# @option options [ Object ] :service_id Discard state for the specified
#   service id only.
# @option options [ true | false ] :stop_populator Whether to stop
#   the populator background thread. For internal driver use only.
# @option options [ Object ] :service_id Clear connections with
#   the specified service id only.
#
# @return [ true ] true.
#
# @since 2.1.0
Closes all idle connections in the pool and schedules currently checked
out connections to be closed when they are checked back into the pool.
The pool remains operational and can create new connections when
requested.
Closes all idle connections in the pool and schedules currently checked out connections to be closed when they are checked back into the pool . The pool remains operational and can create new connections when requested .
def clear(options = nil)
        raise_if_closed!
        check_invariants
        if options && options[:stop_populator]
          stop_populator
        end
        service_id = options && options[:service_id]
        @lock.synchronize do
          @generation_manager.bump(service_id: service_id)
          publish_cmap_event(
            Monitoring::Event::Cmap::PoolCleared.new(
              @server.address,
              service_id: service_id,
            )
          )
          unless options && options[:lazy]
            if service_id
              loop do
                conn = @available_connections.detect do |conn|
                  conn.service_id == service_id
                end
                if conn
                  @available_connections.delete(conn)
                  conn.disconnect!(reason: :stale)
                  @populate_semaphore.signal
                else
                  break
                end
              end
            else
              until @available_connections.empty?
                connection = @available_connections.pop
                connection.disconnect!(reason: :stale)
                @populate_semaphore.signal
              end
            end
          end
        end
        true
      ensure
        check_invariants
      end
def clear ( options = nil ) raise_if_closed! check_invariants if options && options [ :stop_populator ] stop_populator end service_id = options && options [ :service_id ] @lock . synchronize do @generation_manager . bump ( service_id : service_id ) publish_cmap_event ( Monitoring :: Event :: Cmap :: PoolCleared . new ( @server . address , service_id : service_id , ) ) unless options && options [ :lazy ] if service_id loop do conn = @available_connections . detect do | conn | conn . service_id == service_id end if conn @available_connections . delete ( conn ) conn . disconnect! ( reason : :stale ) @populate_semaphore . signal else break end end else until @available_connections . empty? connection = @available_connections . pop connection . disconnect! ( reason : :stale ) @populate_semaphore . signal end end end end true ensure check_invariants end
Closes all idle connections in the pool and schedules currently checked
out connections to be closed when they are checked back into the pool.
Closes all idle connections in the pool and schedules currently checked out connections to be closed when they are checked back into the pool .
None
 true 
options
:service_id Clear connections with the specified service id only.
: service_id Clear connections with the specified service id only .
since
None