class Grenache::Base
Public Class Methods
new(params = {})
click to toggle source
Initialize can accept custom configuration parameters
# File lib/grenache/base.rb, line 16 def initialize(params = {}) @configuration = Configuration.new(params) end
Public Instance Methods
announce(key, port, opts={}, &block)
click to toggle source
Announce a specific service `key` available on specific `port` passed block is called when the announce is sent @param key [string] service identifier @param port [int] service port number @block callback
# File lib/grenache/base.rb, line 38 def announce(key, port, opts={}, &block) payload = [key,port] link.send 'announce', payload, opts, &block if config.auto_announce periodically(config.auto_announce_interval) do link.send 'announce', payload, opts, &block end end end
lookup(key, opts={}) { |addr| ... }
click to toggle source
Lookup for a specific service `key` passed block is called with the result values in case of `http` backend it return the result directly @param key [string] identifier of the service
# File lib/grenache/base.rb, line 24 def lookup(key, opts={}, &block) unless addr = cache.has?(key) addr = link.send('lookup', key, opts, &block) cache.save(key, addr) end yield addr if block_given? addr end
Private Instance Methods
cache()
click to toggle source
# File lib/grenache/base.rb, line 50 def cache @cache ||= Cache.new(config.cache_expire) end
link()
click to toggle source
# File lib/grenache/base.rb, line 60 def link @link ||= Link.new config end
periodically(seconds) { || ... }
click to toggle source
# File lib/grenache/base.rb, line 54 def periodically(seconds) EM.add_periodic_timer(seconds) do yield end end