Class: Grenache::Base

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/grenache/base.rb

Instance Method Summary collapse

Methods included from Configurable

#config, included

Constructor Details

#initialize(params = {}) ⇒ Base

Initialize can accept custom configuration parameters



16
17
18
# File 'lib/grenache/base.rb', line 16

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

Parameters:

  • key (string)

    service identifier

  • port (int)

    service port number



38
39
40
41
42
43
44
45
46
# 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| ... } ⇒ 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

Parameters:

  • key (string)

    identifier of the service

Yields:

  • (addr)


24
25
26
27
28
29
30
31
# 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