class Orchestrator::System

Attributes

config[R]
zones[R]

Public Class Methods

clear_cache() click to toggle source
# File lib/orchestrator/system.rb, line 22
def self.clear_cache
    @@critical.synchronize {
        @@systems = ThreadSafe::Cache.new
    }
end
expire(id) click to toggle source
# File lib/orchestrator/system.rb, line 18
def self.expire(id)
    @@systems.delete(id.to_sym)
end
get(id) click to toggle source
# File lib/orchestrator/system.rb, line 9
def self.get(id)
    name = id.to_sym
    system = @@systems[name]
    if system.nil?
        system = self.load(name)
    end
    return system
end
new(control_system) click to toggle source
# File lib/orchestrator/system.rb, line 32
def initialize(control_system)
    @config = control_system
    @controller = ::Orchestrator::Control.instance

    @modules = {}
    @config.modules.each &method(:index_module)

    # Build an ordered zone cache for setting lookup
    zones = ::Orchestrator::Control.instance.zones
    @zones = []
    @config.zones.each do |zone_id|
        zone = zones[zone_id]
        @zones << zone unless zone.nil?
    end

    # Inform status tracker that that the system has reloaded
    # There may have been a change in module order etc
    @controller.threads.each do |thread|
        thread.next_tick do
            thread.observer.reloaded_system(@config.id, self)
        end
    end
end

Protected Class Methods

load(id) click to toggle source

looks for the system in the database

# File lib/orchestrator/system.rb, line 87
def self.load(id)
    @@critical.synchronize {
        system = @@systems[id]
        return system unless system.nil?

        sys = ControlSystem.find_by_id(id.to_s)
        if sys.nil?
            return nil
        else
            system = System.new(sys)
            @@systems[id] = system
        end
        return system
    }
end

Public Instance Methods

all(mod) click to toggle source
# File lib/orchestrator/system.rb, line 65
def all(mod)
    @modules[mod] || []
end
count(name) click to toggle source
# File lib/orchestrator/system.rb, line 69
def count(name)
    mod = @modules[name.to_sym]
    mod.nil? ? 0 : mod.length
end
get(mod, index) click to toggle source
# File lib/orchestrator/system.rb, line 56
def get(mod, index)
    mods = @modules[mod]
    if mods
        mods[index]
    else
        nil # As subscriptions can be made to modules that don't exist
    end
end
modules() click to toggle source
# File lib/orchestrator/system.rb, line 74
def modules
    @modules.keys
end
settings() click to toggle source
# File lib/orchestrator/system.rb, line 78
def settings
    @config.settings
end

Protected Instance Methods

index_module(mod_id) click to toggle source
# File lib/orchestrator/system.rb, line 103
def index_module(mod_id)
    manager = @controller.loaded?(mod_id)
    if manager
        mod_name = if manager.settings.custom_name.nil?
            manager.settings.dependency.module_name.to_sym
        else
            manager.settings.custom_name.to_sym
        end
        @modules[mod_name] ||= []
        @modules[mod_name] << manager
    end
end