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



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

Parameters:

  • key (string)

    service identifier

  • port (int)

    service port number



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

Parameters:

  • key (string)

    identifier of the service



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