Class: Hoodoo::Services::Discovery
- Inherits:
-
Object
- Object
- Hoodoo::Services::Discovery
- Defined in:
- lib/hoodoo/services/discovery/discovery.rb,
lib/hoodoo/services/discovery/results/for_amqp.rb,
lib/hoodoo/services/discovery/results/for_http.rb,
lib/hoodoo/services/discovery/results/for_local.rb,
lib/hoodoo/services/discovery/results/for_remote.rb,
lib/hoodoo/services/discovery/discoverers/by_flux.rb,
lib/hoodoo/services/discovery/discoverers/by_convention.rb,
lib/hoodoo/services/discovery/discoverers/by_drb/by_drb.rb,
lib/hoodoo/services/discovery/discoverers/by_drb/drb_server.rb
Overview
Just used as a namespace here
Defined Under Namespace
Classes: ByDRb, ByFlux, ForAMQP, ForHTTP, ForLocal, ForRemote
Instance Method Summary collapse
-
#announce(resource, version = 1, options = {}) ⇒ Object
Indicate that a resource is available locally and broacast its location to whatever discovery service a subclass supports via #announce_remote.
-
#discover(resource, version = 1) ⇒ Object
Find a resource endpoint.
-
#initialize(options = {}) ⇒ Discovery
constructor
Create a new instance.
-
#is_local?(resource, version = 1) ⇒ Boolean
Was a resource announced in this instance (“locally”)? Returns
true
if so, elsefalse
.
Constructor Details
#initialize(options = {}) ⇒ Discovery
Create a new instance.
options
-
Passed to the subclass in use via #configure_with. Subclasses define their options. Only instantiate such subclasses, not this ‘Base’ class; see the subclass documentation for option details.
44 45 46 47 |
# File 'lib/hoodoo/services/discovery/discovery.rb', line 44 def initialize( = {} ) @known_local_resources = {} configure_with( ) end |
Instance Method Details
#announce(resource, version = 1, options = {}) ⇒ Object
Indicate that a resource is available locally and broacast its location to whatever discovery service a subclass supports via #announce_remote.
resource
-
Resource name as a Symbol or String (e.g.
:Purchase
). version
-
Endpoint version as an Integer; optional; default is 1.
options
-
Defined by whatever subclass is in use. See that subclass’s documentation for details.
Returns the result of calling #announce_remote (in the subclass in use) with the same parameters. See the protected method definition in this base class for details.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hoodoo/services/discovery/discovery.rb', line 66 def announce( resource, version = 1, = {} ) resource = resource.to_sym version = version.to_i result = announce_remote( resource, version, ) @known_local_resources[ resource ] ||= {} @known_local_resources[ resource ][ version ] = result return result end |
#discover(resource, version = 1) ⇒ Object
Find a resource endpoint. This may be recorded locally or via whatever remote discovery mechanism a subclass implements.
resource
-
Resource name as a Symbol or String (e.g.
:Purchase
). version
-
Endpoint version as an Integer; optional; default is 1.
Returns the result of calling #discover_remote (in the subclass in use) with the same parameters. See the protected method definition in this base class for details.
Use #is_local? if you need to know that an endpoint was announced through this same instance (“locally”).
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/hoodoo/services/discovery/discovery.rb', line 93 def discover( resource, version = 1 ) resource = resource.to_sym version = version.to_i if ( is_local?( resource, version ) ) return @known_local_resources[ resource ][ version ] else return discover_remote( resource, version ) end end |
#is_local?(resource, version = 1) ⇒ Boolean
Was a resource announced in this instance (“locally”)? Returns true
if so, else false
.
This only returns true
if #annouce has been called for the given resource and version.
resource
-
Resource name as a Symbol or String (e.g.
:Purchase
). version
-
Endpoint version as an Integer; optional; default is 1.
116 117 118 119 120 121 122 |
# File 'lib/hoodoo/services/discovery/discovery.rb', line 116 def is_local?( resource, version = 1 ) resource = resource.to_sym version = version.to_i return @known_local_resources.has_key?( resource ) && @known_local_resources[ resource ].has_key?( version ) end |