Class: HTTPX::Resolver::Multi
- Inherits:
-
Object
- Object
- HTTPX::Resolver::Multi
show all
- Includes:
- Callbacks
- Defined in:
- lib/httpx/resolver/multi.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Callbacks
#callbacks_for?, #emit, #on, #once
Constructor Details
#initialize(resolver_type, options) ⇒ Multi
Returns a new instance of Multi.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/httpx/resolver/multi.rb', line 13
def initialize(resolver_type, options)
@current_selector = nil
@current_session = nil
@options = options
@resolver_options = @options.resolver_options
@resolvers = options.ip_families.map do |ip_family|
resolver = resolver_type.new(ip_family, options)
resolver.multi = self
resolver
end
@errors = Hash.new { |hs, k| hs[k] = [] }
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
11
12
13
|
# File 'lib/httpx/resolver/multi.rb', line 11
def options
@options
end
|
#resolvers ⇒ Object
Returns the value of attribute resolvers.
11
12
13
|
# File 'lib/httpx/resolver/multi.rb', line 11
def resolvers
@resolvers
end
|
Instance Method Details
#close ⇒ Object
54
55
56
|
# File 'lib/httpx/resolver/multi.rb', line 54
def close
@resolvers.each(&:close)
end
|
#closed? ⇒ Boolean
38
39
40
|
# File 'lib/httpx/resolver/multi.rb', line 38
def closed?
@resolvers.all?(&:closed?)
end
|
#connections ⇒ Object
58
59
60
|
# File 'lib/httpx/resolver/multi.rb', line 58
def connections
@resolvers.filter_map { |r| r.resolver_connection if r.respond_to?(:resolver_connection) }
end
|
#current_selector=(s) ⇒ Object
28
29
30
31
|
# File 'lib/httpx/resolver/multi.rb', line 28
def current_selector=(s)
@current_selector = s
@resolvers.each { |r| r.__send__(__method__, s) }
end
|
#current_session=(s) ⇒ Object
33
34
35
36
|
# File 'lib/httpx/resolver/multi.rb', line 33
def current_session=(s)
@current_session = s
@resolvers.each { |r| r.__send__(__method__, s) }
end
|
#early_resolve(connection) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/httpx/resolver/multi.rb', line 62
def early_resolve(connection)
hostname = connection.peer.host
addresses = @resolver_options[:cache] && (connection.addresses || HTTPX::Resolver.nolookup_resolve(hostname))
return false unless addresses
resolved = false
addresses.group_by(&:family).sort { |(f1, _), (f2, _)| f2 <=> f1 }.each do |family, addrs|
resolver = @resolvers.find { |r| r.family == family } || @resolvers.first
next unless resolver
resolver.emit_addresses(connection, family, addrs, true)
resolved = true
end
resolved
end
|
#empty? ⇒ Boolean
42
43
44
|
# File 'lib/httpx/resolver/multi.rb', line 42
def empty?
@resolvers.all?(&:empty?)
end
|
#inflight? ⇒ Boolean
46
47
48
|
# File 'lib/httpx/resolver/multi.rb', line 46
def inflight?
@resolvers.any(&:inflight?)
end
|
#lazy_resolve(connection) ⇒ Object
84
85
86
87
88
89
90
91
|
# File 'lib/httpx/resolver/multi.rb', line 84
def lazy_resolve(connection)
@resolvers.each do |resolver|
resolver << @current_session.try_clone_connection(connection, @current_selector, resolver.family)
next if resolver.empty?
@current_session.select_resolver(resolver, @current_selector)
end
end
|
#timeout ⇒ Object
50
51
52
|
# File 'lib/httpx/resolver/multi.rb', line 50
def timeout
@resolvers.filter_map(&:timeout).min
end
|