Class: Manufactured::Registry

Inherits:
Object
  • Object
show all
Includes:
Manufactured, Omega::Server::Registry
Defined in:
lib/manufactured/registry.rb

Overview

Primary server side entity tracker for Manufactured module.

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

Singleton class, access via Manufactured::Registry.instance.

Constant Summary collapse

VALID_TYPES =
[Ship, Station, Loot]
POLL_DELAY =

Time attack thread sleeps between event cycles

0.5

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


59
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
91
92
93
# File 'lib/manufactured/registry.rb', line 59

def initialize
  init_registry

  exclude_from_backup Omega::Server::Command
  exclude_from_backup Omega::Server::EventHandler

  # validate entities upon creation
  self.validation_callback { |r,e|
    # accept manufactured commands
    e.kind_of?(Omega::Server::Command) ||
    # && e.class.modulize.include?("Manufactured")

    e.kind_of?(Omega::Server::Event) ||
    e.kind_of?(Omega::Server::EventHandler) ||

     # confirm entity type & validate
    (VALID_TYPES.include?(e.class) && validate_entity(r, e))
  }

  # sanity checks on entity
  on(:added)   { |e|    check_entity(e)    if VALID_TYPES.include?(e.class) }
  on(:updated) { |e,oe| check_entity(e,oe) if VALID_TYPES.include?(e.class) }

  # sanity checks on commands
  on(:added)   { |c|    check_command(c)   if c.kind_of?(Omega::Server::Command) }

  # uniqueness checks on event handlers
  on(:added)   { |e| sanitize_event_handlers(e) if e.kind_of?(Omega::Server::EventHandler) }

  # run commands
  run { run_commands }

  # run events
  run { run_events }
end

Instance Method Details

#lootObject

Return array of loot tracked by registry


33
# File 'lib/manufactured/registry.rb', line 33

def loot     ; entities.select { |e| e.is_a?(Loot)    } ; end

#shipsObject

Return array of ships tracked by registry


27
# File 'lib/manufactured/registry.rb', line 27

def ships    ; entities.select { |e| e.is_a?(Ship)    } ; end

#stationsObject

Return array of stations tracked by registry


30
# File 'lib/manufactured/registry.rb', line 30

def stations ; entities.select { |e| e.is_a?(Station) } ; end

#stop_commands_for(entity) ⇒ Object


95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/manufactured/registry.rb', line 95

def stop_commands_for(entity)
  # stop all commands related to entity
  @lock.synchronize {
    to_remove = []
    @entities.each { |reg_entity|
      if reg_entity.kind_of?(Omega::Server::Command) &&
         reg_entity.processes?(entity) # TODO flush out processes? methods
        to_remove << reg_entity
      end
    }

    @entities -= to_remove
  }
end