Class: Concurrent::Actor::Behaviour::Pausing
- Defined in:
- lib/concurrent/actor/behaviour/pausing.rb
Overview
Note:
TODO missing example
Allows to pause actors on errors. When paused all arriving messages are collected and processed after the actor is resumed or reset. Resume will simply continue with next message. Reset also reinitialized context.
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#initialize(core, subsequent, core_options) ⇒ Pausing
constructor
A new instance of Pausing.
- #on_envelope(envelope) ⇒ Object
- #on_event(public, event) ⇒ Object
- #pause!(error = nil) ⇒ Object
- #paused? ⇒ Boolean
- #reset! ⇒ Object
- #restart! ⇒ Object
- #resume! ⇒ Object
Methods inherited from Abstract
#broadcast, #pass, #reject_envelope
Methods included from InternalDelegations
#behaviour, #behaviour!, #children, #context, #dead_letter_routing, #log, #redirect, #terminate!, #terminated?
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, core_options) ⇒ Pausing
Returns a new instance of Pausing.
11 12 13 14 15 |
# File 'lib/concurrent/actor/behaviour/pausing.rb', line 11 def initialize(core, subsequent, ) super core, subsequent, @paused = false @deferred = [] end |
Instance Method Details
#on_envelope(envelope) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/concurrent/actor/behaviour/pausing.rb', line 21 def on_envelope(envelope) case envelope. when :pause! pause! when :paused? paused? when :resume! resume! when :reset! reset! when :restart! restart! else if paused? @deferred << envelope MESSAGE_PROCESSED else pass envelope end end end |
#on_event(public, event) ⇒ Object
72 73 74 75 76 |
# File 'lib/concurrent/actor/behaviour/pausing.rb', line 72 def on_event(public, event) event_name, _ = event reject_deferred if event_name == :terminated super public, event end |
#pause!(error = nil) ⇒ Object
43 44 45 46 47 |
# File 'lib/concurrent/actor/behaviour/pausing.rb', line 43 def pause!(error = nil) do_pause broadcast true, error || :paused true end |
#paused? ⇒ Boolean
17 18 19 |
# File 'lib/concurrent/actor/behaviour/pausing.rb', line 17 def paused? @paused end |
#reset! ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/concurrent/actor/behaviour/pausing.rb', line 56 def reset! return false unless paused? broadcast(false, :resetting) do_reset broadcast(true, :reset) true end |
#restart! ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/concurrent/actor/behaviour/pausing.rb', line 64 def restart! return false unless paused? broadcast(false, :restarting) do_restart broadcast(true, :restarted) true end |
#resume! ⇒ Object
49 50 51 52 53 54 |
# File 'lib/concurrent/actor/behaviour/pausing.rb', line 49 def resume! return false unless paused? do_resume broadcast(true, :resumed) true end |