Class: Sponges::Supervisor

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sponges/supervisor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, store, block) ⇒ Supervisor

Returns a new instance of Supervisor.



9
10
11
12
13
14
15
16
# 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

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



5
6
7
# File 'lib/sponges/supervisor.rb', line 5

def handler
  @handler
end

#listenerObject (readonly)

Returns the value of attribute listener.



5
6
7
# File 'lib/sponges/supervisor.rb', line 5

def listener
  @listener
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/sponges/supervisor.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/sponges/supervisor.rb', line 5

def options
  @options
end

#storeObject (readonly)

Returns the value of attribute store.



5
6
7
# File 'lib/sponges/supervisor.rb', line 5

def store
  @store
end

Instance Method Details

#callObject



34
35
36
# File 'lib/sponges/supervisor.rb', line 34

def call
  @block.call
end

#startObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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