Class: Bluepill::Group

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Group.



6
7
8
9
10
# File 'lib/bluepill/group.rb', line 6

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

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/bluepill/group.rb', line 3

def logger
  @logger
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/bluepill/group.rb', line 3

def name
  @name
end

#process_loggerObject

Returns the value of attribute process_logger.



4
5
6
# File 'lib/bluepill/group.rb', line 4

def process_logger
  @process_logger
end

#processesObject

Returns the value of attribute processes.



3
4
5
# File 'lib/bluepill/group.rb', line 3

def processes
  @processes
end

Instance Method Details

#add_process(process) ⇒ Object



12
13
14
15
# File 'lib/bluepill/group.rb', line 12

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

#determine_initial_stateObject



23
24
25
26
27
# File 'lib/bluepill/group.rb', line 23

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

#status(process_name = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/bluepill/group.rb', line 46

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.each do |child|
          lines << "  %s%s: %s" % [prefix, child.name, child.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

#tickObject



17
18
19
20
21
# File 'lib/bluepill/group.rb', line 17

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