Sha256: f6313efa164a8c52d17fcbeed0168d31739732b638b51ebfa091b2e8375b493a

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module Net
  class TCPClient
    module Policy
      # Policy for connecting to servers in the order specified
      class Base
        attr_reader :addresses

        # Returns a policy instance for the supplied policy type
        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

        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

        # Calls the block once for each server, with the addresses in order
        def each(&block)
          raise NotImplementedError
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
net_tcp_client-2.2.1 lib/net/tcp_client/policy/base.rb