Class: Concurrent::Actor::Behaviour::Termination
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Abstract
|
|
Instance Chain:
|
|
Inherits: |
Concurrent::Actor::Behaviour::Abstract
|
Defined in: | lib/concurrent-ruby-edge/concurrent/actor/behaviour/termination.rb |
Overview
Note:
Actor
rejects envelopes when terminated.
Note:
TODO missing example
Handles actor termination. Waits until all its children are terminated, can be configured on behaviour initialization.
Constant Summary
Concern::Logging
- Included
Class Method Summary
- .new(core, subsequent, core_options, trapping = false, terminate_children = true) ⇒ Termination constructor
Abstract
- Inherited
Instance Attribute Summary
- #terminated readonly
- #terminated? ⇒ true, false readonly
- #trapping=(val) rw
- #trapping? ⇒ Boolean rw
Abstract
- Inherited
Actor::InternalDelegations
- Included
Instance Method Summary
- #on_envelope(envelope)
-
#terminate!(reason = nil, envelope = nil)
Terminates the actor.
Abstract
- Inherited
#broadcast | broadcasts event to all behaviours and context. |
#on_envelope | override to add extra behaviour. |
#on_event | override to add extra behaviour. |
#pass, #reject_envelope |
Actor::InternalDelegations
- Included
#behaviour | see Core#behaviour |
#behaviour! | see Core#behaviour! |
#children, #context, #dead_letter_routing, | |
#log | delegates to core.log. |
#redirect, #terminate! |
Concern::Logging
- Included
#log | Logs through Concurrent.global_logger, it can be overridden by setting @logger. |
Actor::PublicDelegations
- Included
#actor_class | Alias for PublicDelegations#context_class. |
#context_class, #executor, #name, #parent, #path, | |
#ref | Alias for PublicDelegations#reference. |
#reference |
Actor::TypeCheck
- Included
Constructor Details
.new(core, subsequent, core_options, trapping = false, terminate_children = true) ⇒ Termination
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/termination.rb', line 17
def initialize(core, subsequent, , trapping = false, terminate_children = true) super core, subsequent, @terminated = Concurrent::Promises.resolvable_future @public_terminated = @terminated.with_hidden_resolvable @trapping = trapping @terminate_children = terminate_children end
Instance Attribute Details
#terminated (readonly)
[ GitHub ]# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/termination.rb', line 15
attr_reader :terminated
#terminated? ⇒ true
, false
(readonly)
Note:
Actor
rejects envelopes when terminated.
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/termination.rb', line 27
def terminated? @terminated.resolved? end
#trapping=(val) (rw)
[ GitHub ]# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/termination.rb', line 35
def trapping=(val) @trapping = !!val end
#trapping? ⇒ Boolean
(rw)
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/termination.rb', line 31
def trapping? @trapping end
Instance Method Details
#on_envelope(envelope)
[ GitHub ]# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/termination.rb', line 39
def on_envelope(envelope) command, reason = envelope. case command when :terminated? terminated? when :terminate! if trapping? && reason != :kill pass envelope else terminate! reason, envelope end when :termination_event @public_terminated else if terminated? reject_envelope envelope MESSAGE_PROCESSED else pass envelope end end end
#terminate!(reason = nil, envelope = nil)
Terminates the actor. Any Envelope received after termination is rejected. Terminates all its children, does not wait until they are terminated.
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/termination.rb', line 64
def terminate!(reason = nil, envelope = nil) return true if terminated? self_termination = Concurrent::Promises.resolved_future(reason.nil?, reason.nil? || nil, reason) all_terminations = if @terminate_children Concurrent::Promises.zip(*children.map { |ch| ch.ask(:terminate!) }, self_termination) else self_termination end all_terminations.chain_resolvable(@terminated) if envelope && envelope.future all_terminations.chain { |fulfilled, _, t_reason| envelope.future.resolve fulfilled, true, t_reason } end broadcast(true, [:terminated, reason]) # TODO do not end up in Dead Letter Router parent << :remove_child if parent MESSAGE_PROCESSED end