Class: Orchestrator::System

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestrator/system.rb

Constant Summary collapse

@@systems =
ThreadSafe::Cache.new
@@critical =
Mutex.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(control_system) ⇒ System

Returns a new instance of System.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



29
30
31
# File 'lib/orchestrator/system.rb', line 29

def config
  @config
end

#zonesObject (readonly)

Returns the value of attribute zones.



29
30
31
# File 'lib/orchestrator/system.rb', line 29

def zones
  @zones
end

Class Method Details

.clear_cacheObject



22
23
24
25
26
# File 'lib/orchestrator/system.rb', line 22

def self.clear_cache
    @@critical.synchronize {
        @@systems = ThreadSafe::Cache.new
    }
end

.expire(id) ⇒ Object



18
19
20
# File 'lib/orchestrator/system.rb', line 18

def self.expire(id)
    @@systems.delete(id.to_sym)
end

.get(id) ⇒ Object



9
10
11
12
13
14
15
16
# 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

Instance Method Details

#all(mod) ⇒ Object



57
58
59
# File 'lib/orchestrator/system.rb', line 57

def all(mod)
    @modules[mod] || []
end

#count(name) ⇒ Object



61
62
63
64
# File 'lib/orchestrator/system.rb', line 61

def count(name)
    mod = @modules[name.to_sym]
    mod.nil? ? 0 : mod.length
end

#get(mod, index) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/orchestrator/system.rb', line 48

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

#modulesObject



66
67
68
# File 'lib/orchestrator/system.rb', line 66

def modules
    @modules.keys
end

#settingsObject



70
71
72
# File 'lib/orchestrator/system.rb', line 70

def settings
    @config.settings
end