Class: Concurrent::Actor::Behaviour::Pausing

Inherits:
Abstract
  • Object
show all
Defined in:
lib/concurrent-ruby-edge/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

#core, #subsequent

Instance Method Summary collapse

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.



13
14
15
16
17
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/pausing.rb', line 13

def initialize(core, subsequent, core_options)
  super core, subsequent, core_options
  @paused   = false
  @deferred = []
end

Instance Method Details

#on_envelope(envelope) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/pausing.rb', line 23

def on_envelope(envelope)
  case envelope.message
  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



74
75
76
77
78
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/pausing.rb', line 74

def on_event(public, event)
  event_name, _ = event
  reject_deferred if event_name == :terminated
  super public, event
end

#pause!(error = nil) ⇒ Object



45
46
47
48
49
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/pausing.rb', line 45

def pause!(error = nil)
  do_pause
  broadcast true, error || :paused
  true
end

#paused?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/pausing.rb', line 19

def paused?
  @paused
end

#reset!Object



58
59
60
61
62
63
64
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/pausing.rb', line 58

def reset!
  return false unless paused?
  broadcast(false, :resetting)
  do_reset
  broadcast(true, :reset)
  true
end

#restart!Object



66
67
68
69
70
71
72
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/pausing.rb', line 66

def restart!
  return false unless paused?
  broadcast(false, :restarting)
  do_restart
  broadcast(true, :restarted)
  true
end

#resume!Object



51
52
53
54
55
56
# File 'lib/concurrent-ruby-edge/concurrent/actor/behaviour/pausing.rb', line 51

def resume!
  return false unless paused?
  do_resume
  broadcast(true, :resumed)
  true
end