Class: OFlow::Test::ActorWrap
- Inherits:
-
Object
- Object
- OFlow::Test::ActorWrap
- Defined in:
- lib/oflow/test/actorwrap.rb
Instance Attribute Summary collapse
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#history ⇒ Object
readonly
Array of Actions.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #debug(msg) ⇒ Object
- #error(msg) ⇒ Object
- #fatal(msg) ⇒ Object
- #full_name ⇒ Object
- #info(msg) ⇒ Object
-
#initialize(name, actor_class, options = {}) ⇒ ActorWrap
constructor
A new instance of ActorWrap.
- #links ⇒ Object
- #log_msg(level, msg, fn) ⇒ Object
- #queue_count ⇒ Object
-
#receive(op, box) ⇒ Object
Calls perform on the actor instance.
- #reset ⇒ Object
-
#ship(dest, box) ⇒ Object
Task API that adds entry to history.
- #state ⇒ Object
- #warn(msg) ⇒ Object
Constructor Details
#initialize(name, actor_class, options = {}) ⇒ ActorWrap
Returns a new instance of ActorWrap.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/oflow/test/actorwrap.rb', line 12 def initialize(name, actor_class, ={}) @name = name @before = [] @state = .fetch(:state, Task::RUNNING) @starting = true @actor = actor_class.new(self, ) @starting = false @history = [] @before.each do |req| receive(req[0], req[1]) end end |
Instance Attribute Details
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
6 7 8 |
# File 'lib/oflow/test/actorwrap.rb', line 6 def actor @actor end |
#history ⇒ Object (readonly)
Array of Actions. Log entries appear with a destination of :log.
10 11 12 |
# File 'lib/oflow/test/actorwrap.rb', line 10 def history @history end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/oflow/test/actorwrap.rb', line 7 def name @name end |
Instance Method Details
#debug(msg) ⇒ Object
70 71 72 |
# File 'lib/oflow/test/actorwrap.rb', line 70 def debug(msg) log_msg(:debug, msg, full_name()) end |
#error(msg) ⇒ Object
78 79 80 |
# File 'lib/oflow/test/actorwrap.rb', line 78 def error(msg) log_msg(:error, msg, full_name()) end |
#fatal(msg) ⇒ Object
86 87 88 |
# File 'lib/oflow/test/actorwrap.rb', line 86 def fatal(msg) log_msg(:fatal, msg, full_name()) end |
#full_name ⇒ Object
29 30 31 |
# File 'lib/oflow/test/actorwrap.rb', line 29 def full_name() ":test:#{@name}" end |
#info(msg) ⇒ Object
74 75 76 |
# File 'lib/oflow/test/actorwrap.rb', line 74 def info(msg) log_msg(:info, msg, full_name()) end |
#links ⇒ Object
37 38 39 40 41 |
# File 'lib/oflow/test/actorwrap.rb', line 37 def links() lnk = Link.new(@name, nil) lnk.instance_variable_set(:@target, self) { nil => lnk } end |
#log_msg(level, msg, fn) ⇒ Object
66 67 68 |
# File 'lib/oflow/test/actorwrap.rb', line 66 def log_msg(level, msg, fn) @history << Action.new(:log, Box.new([level, msg, fn])) end |
#queue_count ⇒ Object
43 44 45 |
# File 'lib/oflow/test/actorwrap.rb', line 43 def queue_count() 0 end |
#receive(op, box) ⇒ Object
Calls perform on the actor instance
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/oflow/test/actorwrap.rb', line 48 def receive(op, box) if @starting @before << [op, box] else begin @actor.perform(op, box) rescue Exception => e ship(:error, Box.new([e, full_name()])) end end nil end |
#reset ⇒ Object
25 26 27 |
# File 'lib/oflow/test/actorwrap.rb', line 25 def reset() @history = [] end |
#ship(dest, box) ⇒ Object
Task API that adds entry to history.
62 63 64 |
# File 'lib/oflow/test/actorwrap.rb', line 62 def ship(dest, box) @history << Action.new(dest, box) end |
#state ⇒ Object
33 34 35 |
# File 'lib/oflow/test/actorwrap.rb', line 33 def state() @state end |
#warn(msg) ⇒ Object
82 83 84 |
# File 'lib/oflow/test/actorwrap.rb', line 82 def warn(msg) log_msg(:warn, msg, full_name()) end |