Class: Motel::Registry

Inherits:
Object show all
Includes:
Omega::Server::Registry
Defined in:
lib/motel/registry.rb

Overview

Motel::Registry is a singleton class/object which acts as the primary mechanism to run locations in the system.

Constant Summary

Constants included from Omega::Server::Registry

Omega::Server::Registry::DEFAULT_COMMAND_POLL, Omega::Server::Registry::DEFAULT_EVENT_POLL, Omega::Server::Registry::DEFAULT_LOOP_POLL

Instance Attribute Summary

Attributes included from Omega::Server::Registry

#backup_excludes, #node, #retrieval, #user, #validation_methods

Instance Method Summary collapse

Methods included from Omega::Server::Registry

#<<, #cleanup_event, #clear!, #delete, #entities, #entity, #exclude_from_backup, #join, #on, #proxies_for, #proxy_for, #raise_event, #restore, #run, #running?, #safe_exec, #save, #start, #stop, #to_s, #update, #validation_callback

Constructor Details

#initializeRegistry

Returns a new instance of Registry


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/motel/registry.rb', line 151

def initialize
  init_registry

  exclude_from_backup Omega::Server::Callback

  # validate location ids are unique before creating
  self.validation_callback { |r,e|
    e.is_a?(Location) &&

    !r.collect { |l| l.id }.include?(e.id)
  }

  # perform a few sanity checks on location / update any attributes needing it
  on(:added)   { |loc| check_location(loc)}
  on(:updated) { |loc,oloc| check_location(loc,oloc)}

  # setup parent when entity is added or updated
  on(:added)   { |loc| adjust_heirarchry(loc) }
  on(:updated) { |loc,oloc| adjust_heirarchry(loc,oloc) }

  # setup location callbacks
  LOCATION_EVENTS.each { |e|
    on(e) { |loc, *args|
      @lock.synchronize{
        # run event on registry location
        rloc = @entities.find { |e| e.id == loc.id }
        rloc.raise_event(e, *args)
      }
    }
  }

  # start location runner
  run { run_locations }
end