Class: Eye::Application
- Inherits:
-
Object
- Object
- Eye::Application
- Includes:
- Logger::Helpers
- Defined in:
- lib/eye/application.rb
Instance Attribute Summary collapse
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes included from Logger::Helpers
Instance Method Summary collapse
- #add_group(group) ⇒ Object
- #alive? ⇒ Boolean
- #debug_data ⇒ Object
- #full_name ⇒ Object
-
#initialize(name, config = {}) ⇒ Application
constructor
A new instance of Application.
- #processes ⇒ Object
-
#resort_groups ⇒ Object
sort processes in name order.
- #send_command(command, *args) ⇒ Object
- #status_data(debug = false) ⇒ Object
- #status_data_short ⇒ Object
- #sub_object?(obj) ⇒ Boolean
- #update_config(cfg) ⇒ Object
Constructor Details
#initialize(name, config = {}) ⇒ Application
Returns a new instance of Application.
7 8 9 10 11 12 13 |
# File 'lib/eye/application.rb', line 7 def initialize(name, config = {}) @groups = Eye::Utils::AliveArray.new @name = name @logger = Eye::Logger.new(full_name) @config = config debug 'created' end |
Instance Attribute Details
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
3 4 5 |
# File 'lib/eye/application.rb', line 3 def groups @groups end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/eye/application.rb', line 3 def name @name end |
Instance Method Details
#add_group(group) ⇒ Object
23 24 25 |
# File 'lib/eye/application.rb', line 23 def add_group(group) @groups << group end |
#alive? ⇒ Boolean
60 61 62 |
# File 'lib/eye/application.rb', line 60 def alive? true # emulate celluloid actor method end |
#debug_data ⇒ Object
49 50 |
# File 'lib/eye/application.rb', line 49 def debug_data end |
#full_name ⇒ Object
15 16 17 |
# File 'lib/eye/application.rb', line 15 def full_name @name end |
#processes ⇒ Object
70 71 72 |
# File 'lib/eye/application.rb', line 70 def processes Eye::Utils::AliveArray.new(@groups.map{|gr| gr.processes.to_a }.flatten) end |
#resort_groups ⇒ Object
sort processes in name order
28 29 30 |
# File 'lib/eye/application.rb', line 28 def resort_groups @groups = @groups.sort_by{|gr| gr.name == '__default__' ? 'zzzzz' : gr.name } end |
#send_command(command, *args) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/eye/application.rb', line 52 def send_command(command, *args) debug "send_command #{command} #{args}" @groups.each do |group| group.send_command(command, *args) end end |
#status_data(debug = false) ⇒ Object
32 33 34 35 36 |
# File 'lib/eye/application.rb', line 32 def status_data(debug = false) h = { name: @name, type: :application, subtree: @groups.map{|gr| gr.status_data(debug) }} h.merge!(debug: debug_data) if debug h end |
#status_data_short ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/eye/application.rb', line 38 def status_data_short h = Hash.new 0 @groups.each do |c| c.processes.each do |p| h[p.state] += 1 end end str = h.sort_by{|a,b| a}.map{|k, v| "#{k}:#{v}" } * ', ' { name: @name, type: :application, state: str} end |
#sub_object?(obj) ⇒ Boolean
64 65 66 67 68 |
# File 'lib/eye/application.rb', line 64 def sub_object?(obj) res = @groups.include?(obj) res = @groups.any?{|gr| gr.sub_object?(obj)} if !res res end |
#update_config(cfg) ⇒ Object
19 20 21 |
# File 'lib/eye/application.rb', line 19 def update_config(cfg) @config = cfg end |