Class: Cosmos::Registry

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

Overview

Primary server side entity tracker for Cosmos module.

Provides a thread safe registry through which cosmos entity heirarchies and resources can be accessed.

Constant Summary collapse

VALID_TYPES =
[Galaxy, SolarSystem, JumpGate, Star, Planet, Moon, Asteroid]

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

Cosmos::Registry intitializer


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cosmos/registry.rb', line 60

def initialize
  init_registry

  # validate entities, ensure
  self.validation_callback { |r,e|
    # they are of valid type and valid
    VALID_TYPES.include?(e.class) && e.valid? &&

    # they have unique ids
    r.find { |re| re.id == e.id }.nil? &&

    # they have unqiue names
    r.find { |re| re.name == e.name }.nil? &&

    # if required, parent_id is set and is valid reference
    (e.class::PARENT_TYPE == 'NilClass' ||
      !e.proxy_to.nil? ||
     (!e.parent_id.nil? &&
      !r.find { |re| re.id == e.parent_id }.nil?) ) &&

    # jump gate endpoint is valid reference
    (!e.is_a?(JumpGate) || !r.find { |re| re.id == e.endpoint_id }.nil?)
  }

  # perform sanity checks on entity / adjust attributes
  on(:added) { |e| check_entity    e                                  }

  # perform additonal checks on jump gate
  on(:added) { |e| check_jump_gate e if e.is_a?(JumpGate)             }

end