Class: Remotus::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/remotus/pool.rb

Overview

Class representing a connection pool containing many host-specific pools

Class Method Summary collapse

Class Method Details

.clearInteger

Removes all host pools from the pool in a thread-safe manner

Returns:

  • (Integer)

    number of host pools removed



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/remotus/pool.rb', line 58

def clear
  @lock.synchronize do
    Remotus.logger.debug { "Removing all host pools" }
    return 0 unless @pool

    num_pools = count

    # Force connection close
    @pool.each { |_hostname, host_pool| host_pool.close }
    @pool = {}

    return num_pools
  end
end

.connect(host, **options) ⇒ Remotus::HostPool

Attempts to get the host pool for a given host

Parameters:

  • host (String)

    hostname

  • options (Hash)

    options hash

Options Hash (**options):

  • :size (Integer)

    number of connections in the pool

  • :timeout (Integer)

    amount of time to wait for a connection from the pool

  • :port (Integer)

    port to use for the connection

  • :proto (Symbol)

    protocol to use for the connection (:winrm, :ssh), must be specified if port is specified

  • :ip (String)

    IP to use for the connection, preferred over the hostname if set. This should be used if the hostname is required for credential retrieval but the hostname cannot be resolved by DNS.

Returns:



29
30
31
# File 'lib/remotus/pool.rb', line 29

def connect(host, **options)
  host_pool(host, **options)
end

.countInteger

Number of host pools in the pool

Returns:

  • (Integer)

    number of host pools



38
39
40
# File 'lib/remotus/pool.rb', line 38

def count
  pool.keys.count
end

.reapInteger

Reaps (removes) expired host pools from the pool in a thread-safe manner

Returns:

  • (Integer)

    number of host pools reaped



47
48
49
50
51
# File 'lib/remotus/pool.rb', line 47

def reap
  @lock.synchronize do
    return reap_host_pools
  end
end