class Sponges::Supervisor

Attributes

handler[R]
listener[R]
name[R]
options[R]
store[R]

Public Class Methods

new(name, options, store, block) click to toggle source
# File lib/sponges/supervisor.rb, line 9
def initialize(name, options, store, block)
  @name, @options, @store, @block = name, options, store, block
  $PROGRAM_NAME = [@name, Sponges.env, "supervisor"].compact.join("_")
  store.register Process.pid
  @children_seen = 0
  @handler = Handler.new self
  @listener = Listener.new(self)
end

Public Instance Methods

call() click to toggle source
# File lib/sponges/supervisor.rb, line 34
def call
  @block.call
end
start() click to toggle source
# File lib/sponges/supervisor.rb, line 18
def start
  handler.call
  trap_signals
  options[:size].times do
    handler.push :TTIN
  end
  Sponges.logger.info "Supervisor started, waiting for messages, listening on port #{Sponges::Configuration.port}"
  listener.call
rescue SystemExit => exception
  raise exception
rescue Exception => exception
  Sponges.logger.error exception
  handler.push :INT
  raise exception
end

Private Instance Methods

children_name() click to toggle source
# File lib/sponges/supervisor.rb, line 40
def children_name
  [name, Sponges.env, "child_#{@children_seen +=1}"].compact.join("_")
end
trap_signals() click to toggle source
# File lib/sponges/supervisor.rb, line 44
def trap_signals
  Sponges::SIGNALS.each do |signal|
    trap(signal) {|signal| handler.push signal }
  end
end