Sha256: 52752f0b757294c42704598a0ed84af1e760ac2751a3313684032df3a36be720

Contents?: true

Size: 1.04 KB

Versions: 3

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

3 entries across 3 versions & 1 rubygems

Version Path
net_tcp_client-2.2.0 lib/net/tcp_client/policy/base.rb
net_tcp_client-2.0.1 lib/net/tcp_client/policy/base.rb
net_tcp_client-2.0.0 lib/net/tcp_client/policy/base.rb