Class: MonoVM::Whois::Transport::Factory
- Inherits:
-
Object
- Object
- MonoVM::Whois::Transport::Factory
- Defined in:
- lib/monovm/whois/transport/factory.rb
Overview
Chooses a transport for an endpoint.
Client asks for "something that can fetch this endpoint" and gets it, so adding a protocol means registering a transport here and nowhere else. The factory also owns the middleware wrapping, which is why every transport it hands out already caches, throttles and retries consistently — those are decisions about the whole system, not about one protocol.
Instance Attribute Summary collapse
-
#middleware ⇒ Object
readonly
Returns the value of attribute middleware.
-
#transports ⇒ Object
readonly
Returns the value of attribute transports.
Instance Method Summary collapse
-
#for(endpoint) ⇒ Base
A transport that can serve
endpoint, already wrapped. -
#initialize(transports: nil, middleware: []) ⇒ Factory
constructor
A new instance of Factory.
Constructor Details
#initialize(transports: nil, middleware: []) ⇒ Factory
24 25 26 27 28 29 |
# File 'lib/monovm/whois/transport/factory.rb', line 24 def initialize(transports: nil, middleware: []) @transports = transports || [WhoisSocket.new, RdapHttp.new] @middleware = middleware @wrapped = {} @mutex = Mutex.new end |
Instance Attribute Details
#middleware ⇒ Object (readonly)
Returns the value of attribute middleware.
18 19 20 |
# File 'lib/monovm/whois/transport/factory.rb', line 18 def middleware @middleware end |
#transports ⇒ Object (readonly)
Returns the value of attribute transports.
18 19 20 |
# File 'lib/monovm/whois/transport/factory.rb', line 18 def transports @transports end |
Instance Method Details
#for(endpoint) ⇒ Base
Returns a transport that can serve endpoint, already wrapped.
34 35 36 37 38 39 40 41 |
# File 'lib/monovm/whois/transport/factory.rb', line 34 def for(endpoint) transport = transports.find { |candidate| candidate.supports?(endpoint) } raise Error, "no transport can serve #{endpoint}" if transport.nil? # Middleware holds per-host state (throttle clocks, cache entries), so each # transport must be wrapped exactly once and shared, not re-wrapped per call. @wrapped[transport] || @mutex.synchronize { @wrapped[transport] ||= wrap(transport) } end |