Class: Concurrent::Actor::Behaviour::Supervising

Inherits:
Abstract
  • Object
show all
Defined in:
lib/concurrent/actor/behaviour/supervising.rb

Instance Attribute Summary

Attributes inherited from Abstract

#core, #subsequent

Instance Method Summary collapse

Methods inherited from Abstract

#broadcast, #on_event, #pass, #reject_envelope

Methods included from InternalDelegations

#behaviour, #behaviour!, #children, #context, #dead_letter_routing, #log, #redirect, #terminate!

Methods included from PublicDelegations

#context_class, #executor, #name, #parent, #path, #reference

Methods included from TypeCheck

#Child!, #Child?, #Match!, #Match?, #Type!, #Type?

Constructor Details

#initialize(core, subsequent, handle, strategy) ⇒ Supervising

Returns a new instance of Supervising.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/concurrent/actor/behaviour/supervising.rb', line 5

def initialize(core, subsequent, handle, strategy)
  super core, subsequent
  @handle   = Match! handle, :terminate!, :resume!, :reset!, :restart!
  @strategy = case @handle
              when :terminate!
                Match! strategy, nil
              when :resume!
                Match! strategy, :one_for_one
              when :reset!, :restart!
                Match! strategy, :one_for_one, :one_for_all
              end
end

Instance Method Details

#on_envelope(envelope) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/concurrent/actor/behaviour/supervising.rb', line 18

def on_envelope(envelope)
  case envelope.message
  when Exception, :paused
    receivers = if @strategy == :one_for_all
                  children
                else
                  [envelope.sender]
                end
    receivers.each { |ch| ch << @handle }
  else
    pass envelope
  end
end