class Net::TCPClient::Policy::Base

Policy for connecting to servers in the order specified

Attributes

addresses[R]

Public Class Methods

factory(policy, server_names) click to toggle source

Returns a policy instance for the supplied policy type

# File lib/net/tcp_client/policy/base.rb, line 9
def self.factory(policy, server_names)
  case policy
  when :ordered
    # Policy for connecting to servers in the order specified
    Ordered.new(server_names)
  when :random
    Random.new(server_names)
  when Proc
    Custom.new(server_names, policy)
  else
    raise(ArgumentError, "Invalid policy: #{policy.inspect}")
  end
end
new(server_names) click to toggle source
# File lib/net/tcp_client/policy/base.rb, line 23
def initialize(server_names)
  # Collect Addresses for the supplied server_names
  @addresses = Array(server_names).collect { |name| Address.addresses_for_server_name(name) }.flatten
end

Public Instance Methods

each(&block) click to toggle source

Calls the block once for each server, with the addresses in order

# File lib/net/tcp_client/policy/base.rb, line 29
def each(&block)
  raise NotImplementedError
end