123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Cluster::SocketReaper Private

Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/cluster/reapers/socket_reaper.rb

Overview

A manager that calls a method on each of a cluster's pools to close idle sockets.

Since:

  • 2.5.0

Class Method Summary

Instance Method Summary

  • #execute Internal use only

    Execute the operation to close the pool's idle sockets.

  • #flush Internal use only

    When the socket reaper is garbage-collected, there's no need to close.

Constructor Details

.new(cluster) ⇒ SocketReaper

Initialize the SocketReaper object.

Examples:

Initialize the socket reaper.

SocketReaper.new(cluster)

Parameters:

  • cluster (Mongo::Cluster)

    The cluster whose pools' idle sockets need to be reaped at regular intervals.

Since:

  • 2.5.0

[ GitHub ]

  
# File 'lib/mongo/cluster/reapers/socket_reaper.rb', line 35

def initialize(cluster)
  @cluster = cluster
end

Instance Method Details

#execute

Execute the operation to close the pool's idle sockets.

Examples:

Close the idle sockets in each of the cluster's pools.

socket_reaper.execute

Since:

  • 2.5.0

[ GitHub ]

  
# File 'lib/mongo/cluster/reapers/socket_reaper.rb', line 45

def execute
  @cluster.servers.each do |server|
    server.pool_internal&.close_idle_sockets
  end
  true
end

#flush

When the socket reaper is garbage-collected, there's no need to close idle sockets; sockets will be closed anyway when the pools are garbage collected.

Since:

  • 2.5.0

[ GitHub ]

  
# File 'lib/mongo/cluster/reapers/socket_reaper.rb', line 57

def flush; end