Class: SimpleActor
- Inherits:
-
Object
- Object
- SimpleActor
- Defined in:
- lib/ara/simple_actor.rb
Overview
This class allow you to create simple actors.
Direct Known Subclasses
Instance Method Summary (collapse)
-
- (SimpleActor) initialize
constructor
:nodoc:.
-
- (Object) start
Start actor and return it.
-
- (Object) stop
Stop actor.
-
- (Object) |(message)
(also: #message)
Send a simple message without expecting any response.
Constructor Details
- (SimpleActor) initialize
:nodoc:
5 6 7 8 |
# File 'lib/ara/simple_actor.rb', line 5 def initialize #:nodoc: raise ActorInitializationError, "You can't initialize SimpleActor directly, use Actors.actor_of" if self.class == ::SimpleActor @actorQueue = Queue.new end |
Instance Method Details
- (Object) start
Start actor and return it
myActor = Actors.actor_of(MyActor)
myActor.start
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ara/simple_actor.rb', line 14 def start self.send(:pre_start) if self.respond_to?(:pre_start, true) @thread = Thread.new do loop do receive(@actorQueue.shift) end end return self end |
- (Object) stop
Stop actor
myActor = Actors.actor_of(MyActor).start
...
myActor.stop
30 31 32 33 |
# File 'lib/ara/simple_actor.rb', line 30 def stop @thread.kill self.send(:post_stop) if self.respond_to?(:post_stop, true) end |
- (Object) |(message) Also known as: message
Send a simple message without expecting any response
myActor = Actors.actor_of(MyActor).start
message = ...
myActor | message
40 41 42 43 44 45 46 |
# File 'lib/ara/simple_actor.rb', line 40 def |() if @thread.alive? @actorQueue << else raise DeadActor, "Actor is dead!" end end |