Class: Grenache::Base
- Inherits:
-
Object
- Object
- Grenache::Base
- Includes:
- Configurable
- Defined in:
- lib/grenache/base.rb
Instance Method Summary collapse
-
#announce(key, port, opts = {}, &block) ⇒ Object
Announce a specific service ‘key` available on specific `port` passed block is called when the announce is sent.
-
#initialize(params = {}) ⇒ Base
constructor
Initialize can accept custom configuration parameters.
-
#lookup(key, opts = {}, &block) ⇒ Object
Lookup for a specific service ‘key` passed block is called with the result values in case of `http` backend it return the result directly.
Methods included from Configurable
Constructor Details
#initialize(params = {}) ⇒ Base
Initialize can accept custom configuration parameters
6 7 8 |
# File 'lib/grenache/base.rb', line 6 def initialize(params = {}) @configuration = Configuration.new(params) end |
Instance Method Details
#announce(key, port, opts = {}, &block) ⇒ Object
Announce a specific service ‘key` available on specific `port` passed block is called when the announce is sent
27 28 29 30 31 32 33 34 35 |
# File 'lib/grenache/base.rb', line 27 def announce(key, port, opts={}, &block) payload = [key,port] link.send 'announce', payload, opts, &block if config.auto_announce periodically(1) do link.send 'announce', payload, opts, &block end end end |
#lookup(key, opts = {}, &block) ⇒ Object
Lookup for a specific service ‘key` passed block is called with the result values in case of `http` backend it return the result directly
14 15 16 17 18 19 20 |
# File 'lib/grenache/base.rb', line 14 def lookup(key, opts={}, &block) unless addr = cache.has?(key) addr = link.send('lookup', key, opts, &block) cache.save(key, addr) end addr end |