Class: EventedBluepill::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/evented_bluepill/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Group

Returns a new instance of Group.



21
22
23
24
25
# File 'lib/evented_bluepill/group.rb', line 21

def initialize(name, options = {})
  self.name = name
  self.processes = []
  self.logger = options[:logger]
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



18
19
20
# File 'lib/evented_bluepill/group.rb', line 18

def logger
  @logger
end

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/evented_bluepill/group.rb', line 18

def name
  @name
end

#process_loggerObject

Returns the value of attribute process_logger.



19
20
21
# File 'lib/evented_bluepill/group.rb', line 19

def process_logger
  @process_logger
end

#processesObject

Returns the value of attribute processes.



18
19
20
# File 'lib/evented_bluepill/group.rb', line 18

def processes
  @processes
end

Instance Method Details

#add_process(process) ⇒ Object



27
28
29
30
# File 'lib/evented_bluepill/group.rb', line 27

def add_process(process)
  process.logger = self.logger.prefix_with(process.name)
  self.processes << process
end

#determine_initial_stateObject



32
33
34
35
36
# File 'lib/evented_bluepill/group.rb', line 32

def determine_initial_state
  self.processes.each do |process|
    process.determine_initial_state
  end
end

#status(process_name = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/evented_bluepill/group.rb', line 53

def status(process_name = nil)
  lines = []
  if process_name.nil?
    prefix = self.name ? "  " : ""
    lines << "#{self.name}:" if self.name

    self.processes.each do |process|
      lines << "%s%s(pid:%s): %s" % [prefix, process.name, process.actual_pid, process.state]
      if process.monitor_children?
        process.children_timer.each do |child|
          lines << "  %s%s: %s" % [prefix, child.process.name, child.process.state]
        end
      end
    end
  else
    self.processes.each do |process|
      next if process_name != process.name
      lines << "%s%s(pid:%s): %s" % [prefix, process.name, process.actual_pid, process.state]
      lines << process.statistics.to_s
    end
  end
  lines << ""
end