Class: Concurrent::Actor::Behaviour::Termination
- Defined in:
- lib/concurrent/actor/behaviour/termination.rb
Overview
Note:
Actor rejects envelopes when terminated.
Handles actor termination.
Instance Attribute Summary collapse
-
#terminated ⇒ Object
readonly
Returns the value of attribute terminated.
Attributes inherited from Abstract
Instance Method Summary collapse
-
#initialize(core, subsequent) ⇒ Termination
constructor
A new instance of Termination.
- #on_envelope(envelope) ⇒ Object
-
#terminate! ⇒ Object
Terminates the actor.
-
#terminated? ⇒ true, false
If actor is terminated.
Methods inherited from Abstract
#broadcast, #on_event, #pass, #reject_envelope
Methods included from InternalDelegations
#behaviour, #behaviour!, #children, #context, #dead_letter_routing, #log, #redirect
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) ⇒ Termination
Returns a new instance of Termination.
13 14 15 16 |
# File 'lib/concurrent/actor/behaviour/termination.rb', line 13 def initialize(core, subsequent) super core, subsequent @terminated = Event.new end |
Instance Attribute Details
#terminated ⇒ Object (readonly)
Returns the value of attribute terminated.
11 12 13 |
# File 'lib/concurrent/actor/behaviour/termination.rb', line 11 def terminated @terminated end |
Instance Method Details
#on_envelope(envelope) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/concurrent/actor/behaviour/termination.rb', line 24 def on_envelope(envelope) case envelope. when :terminated? terminated? when :terminate! terminate! when :terminated_event terminated else if terminated? reject_envelope envelope MESSAGE_PROCESSED else pass envelope end end end |
#terminate! ⇒ Object
Terminates the actor. Any Envelope received after termination is rejected. Terminates all its children, does not wait until they are terminated.
44 45 46 47 48 49 50 |
# File 'lib/concurrent/actor/behaviour/termination.rb', line 44 def terminate! return true if terminated? terminated.set broadcast(:terminated) # TODO do not end up in Dead Letter Router parent << :remove_child if parent true end |
#terminated? ⇒ true, false
Note:
Actor rejects envelopes when terminated.
Returns if actor is terminated.
20 21 22 |
# File 'lib/concurrent/actor/behaviour/termination.rb', line 20 def terminated? @terminated.set? end |