Class SSHKit::Backend::ConnectionPool
In: lib/sshkit/backends/connection_pool.rb
Parent: Object

The ConnectionPool caches connections and allows them to be reused, so long as the reuse happens within the `idle_timeout` period. Timed out connections are eventually closed, forcing a new connection to be used in that case.

Additionally, a background thread is started to check for abandoned connections that have timed out without any attempt at being reused. These are eventually closed as well and removed from the cache.

If `idle_timeout` set to `false`, `0`, or `nil`, no caching is performed, and a new connection is created and then immediately closed each time. The default timeout is 30 (seconds).

There is a single public method: `with`. Example usage:

  pool = SSHKit::Backend::ConnectionPool.new
  pool.with(Net::SSH.method(:start), "host", "username") do |connection|
    # do stuff with connection
  end

Methods

Attributes

caches  [R] 
idle_timeout  [RW] 
timed_out_connections  [R] 

Public Class methods

Public Instance methods

Immediately close all cached connections and empty the pool.

Immediately remove all cached connections, without closing them. This only exists for unit test purposes.

Creates a new connection or reuses a cached connection (if possible) and yields the connection to the given block. Connections are created by invoking the `connection_factory` proc with the given `args`. The arguments are used to construct a key used for caching.

[Validate]