class StalkClimber::ConnectionPool

Attributes

addresses[R]

Addresses the pool is connected to

test_tube[R]

Test tube used when probing Beanstalk server for information

Public Class Methods

new(addresses = nil, test_tube = nil) click to toggle source

Constructs a Beaneater::Pool from a less strict URL url can be a string or an array of addresses. Valid URLs match any of the following forms:

localhost (host only)
192.168.1.100:11300 (host and port)
beanstalk://127.0.0.1:11300 (host and port prefixed by beanstalk scheme)
# File lib/stalk_climber/connection_pool.rb, line 17
def initialize(addresses = nil, test_tube = nil)
  @addresses = Array(parse_addresses(addresses) || host_from_env || Beaneater.configuration.beanstalkd_url)
  @test_tube = test_tube
  @connections = @addresses.map { |address| Connection.new(address, test_tube) }
end

Public Instance Methods

tubes() click to toggle source
# File lib/stalk_climber/connection_pool.rb, line 24
def tubes
  @tubes ||= StalkClimber::Tubes.new(self)
end

Protected Instance Methods

parse_addresses(addresses) → String click to toggle source

Parses the given urls into a collection of beanstalk addresses

# File lib/stalk_climber/connection_pool.rb, line 35
def parse_addresses(addresses)
  return if addresses.empty?
  uris = addresses.is_a?(Array) ? addresses.dup : addresses.split(/[\s,]+/)
  uris.map! do |uri_string|
    begin
      uri = URI.parse(uri_string)
    rescue URI::InvalidURIError
      # IP based hosts without a scheme will fail to parse
    end
    if uri && uri.scheme && uri.host
      raise(InvalidURIScheme, "Invalid beanstalk URI: #{uri_string}") unless uri.scheme == 'beanstalk'
      host = uri.host
      port = uri.port
    else
      # if parse failure or missing scheme or host, assume the uri format is a
      # hostname optionally followed by a port.
      # i.e. 'localhost:11300' or '0.0.0.0'
      match = uri_string.split(/:/)
      host = match[0]
      port = match[1]
    end
    "#{host}:#{port || 11300}"
  end
end