Class: Eye::Application

Inherits:
Object show all
Defined in:
lib/eye/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config = {}) ⇒ Application

Returns a new instance of Application.



5
6
7
8
9
10
# File 'lib/eye/application.rb', line 5

def initialize(name, config = {})
  @groups = Eye::Utils::AliveArray.new
  @name = name
  @config = config
  debug { 'created' }
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



3
4
5
# File 'lib/eye/application.rb', line 3

def groups
  @groups
end

#nameObject (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



20
21
22
# File 'lib/eye/application.rb', line 20

def add_group(group)
  @groups << group
end

#alive?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/eye/application.rb', line 57

def alive?
  true # emulate celluloid actor method
end

#debug_dataObject



46
47
# File 'lib/eye/application.rb', line 46

def debug_data
end

#full_nameObject



16
17
18
# File 'lib/eye/application.rb', line 16

def full_name
  @name
end

#logger_tagObject



12
13
14
# File 'lib/eye/application.rb', line 12

def logger_tag
  full_name
end

#processesObject



67
68
69
70
71
# File 'lib/eye/application.rb', line 67

def processes
  out = []
  @groups.each{|gr| out += gr.processes.to_a }
  Eye::Utils::AliveArray.new(out)
end

#resort_groupsObject

sort processes in name order



25
26
27
# File 'lib/eye/application.rb', line 25

def resort_groups
  @groups = @groups.sort { |a, b| a.hidden ? 1 : (b.hidden ? -1 : (a.name <=> b.name)) }
end

#send_command(command, *args) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/eye/application.rb', line 49

def send_command(command, *args)
  info "send_command #{command}"

  @groups.each do |group|
    group.send_command(command, *args)
  end
end

#status_data(debug = false) ⇒ Object



29
30
31
32
33
# File 'lib/eye/application.rb', line 29

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_shortObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/eye/application.rb', line 35

def status_data_short
  h = Hash.new
  @groups.each do |c|
    c.processes.each do |p|
      h[p.state] ||= 0
      h[p.state] += 1
    end
  end
  { name: @name, type: :application, states: h}
end

#sub_object?(obj) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
# File 'lib/eye/application.rb', line 61

def sub_object?(obj)
  res = @groups.include?(obj)
  res = @groups.any?{|gr| gr.sub_object?(obj)} if !res
  res
end