Class: Concurrent::Actor::Behaviour::Supervised
- Defined in:
- lib/concurrent/actor/behaviour/supervised.rb
Overview
Sets and holds the supervisor of the actor if any. There is at most one supervisor for each actor. Each supervisor is automatically linked. Messages: ‘:pause!, :resume!, :reset!, :restart!` are accepted only from supervisor.
Instance Attribute Summary collapse
-
#supervisor ⇒ Object
readonly
Returns the value of attribute supervisor.
Attributes inherited from Abstract
Instance Method Summary collapse
-
#initialize(core, subsequent) ⇒ Supervised
constructor
A new instance of Supervised.
- #on_envelope(envelope) ⇒ Object
- #on_event(event) ⇒ Object
- #supervise(ref) ⇒ Object
- #un_supervise(ref) ⇒ Object
Methods inherited from Abstract
#broadcast, #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) ⇒ Supervised
Returns a new instance of Supervised.
11 12 13 14 |
# File 'lib/concurrent/actor/behaviour/supervised.rb', line 11 def initialize(core, subsequent) super core, subsequent @supervisor = nil end |
Instance Attribute Details
#supervisor ⇒ Object (readonly)
Returns the value of attribute supervisor.
9 10 11 |
# File 'lib/concurrent/actor/behaviour/supervised.rb', line 9 def supervisor @supervisor end |
Instance Method Details
#on_envelope(envelope) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/concurrent/actor/behaviour/supervised.rb', line 16 def on_envelope(envelope) case envelope. when :supervise supervise envelope.sender when :supervisor supervisor when :un_supervise un_supervise envelope.sender when :pause!, :resume!, :reset!, :restart! # allow only supervisor to control the actor if @supervisor == envelope.sender pass envelope else false end else pass envelope end end |
#on_event(event) ⇒ Object
52 53 54 55 |
# File 'lib/concurrent/actor/behaviour/supervised.rb', line 52 def on_event(event) @supervisor = nil if event == :terminated super event end |
#supervise(ref) ⇒ Object
36 37 38 39 40 |
# File 'lib/concurrent/actor/behaviour/supervised.rb', line 36 def supervise(ref) @supervisor = ref behaviour!(Linking).link ref true end |
#un_supervise(ref) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/concurrent/actor/behaviour/supervised.rb', line 42 def un_supervise(ref) if @supervisor == ref behaviour!(Linking).unlink ref @supervisor = nil true else false end end |