Module: Distribunaut::Utils::Rinda

Defined in:
lib/distribunaut/utils/rinda.rb

Class Method Summary collapse

Class Method Details

.available_servicesObject



37
38
39
40
41
42
43
44
45
# File 'lib/distribunaut/utils/rinda.rb', line 37

def self.available_services
  ring_server = self.ring_server
  all = ring_server.read_all([nil, nil, nil, nil])
  services = []
  all.each do |service|
    services << Distribunaut::Tuple.from_array(service)
  end
  services
end

.read(values = {}) ⇒ Object



30
31
32
33
34
35
# File 'lib/distribunaut/utils/rinda.rb', line 30

def self.read(values = {})
  tuple = build_tuple(values)
  results = ring_server.read(tuple.to_array, tuple.timeout)
  tuple = Distribunaut::Tuple.from_array(results)
  tuple.object
end

.register(values = {}) ⇒ Object



15
16
17
18
# File 'lib/distribunaut/utils/rinda.rb', line 15

def self.register(values = {})
  tuple = build_tuple(values)
  ring_server.write(tuple.to_array, ::Rinda::SimpleRenewer.new)
end

.register_or_renew(values = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/distribunaut/utils/rinda.rb', line 5

def self.register_or_renew(values = {})
  tuple = build_tuple(values)
  begin
    ring_server.take(tuple.to_search_array, tuple.timeout)
  rescue ::Rinda::RequestExpiredError => e
    # it's ok that it expired. It could be that it was never registered.
  end
  register(values)
end

.ring_serverObject



20
21
22
23
24
25
26
27
28
# File 'lib/distribunaut/utils/rinda.rb', line 20

def self.ring_server
  if configatron.distribunaut.retrieve(:acl, nil)
    acl = ACL.new(configatron.distribunaut.acl)
    DRb.install_acl(acl)
  end
  ::DRb.start_service
  rs = ::Rinda::RingFinger.primary
  rs
end