Class: Celluloid::Group
- Inherits:
-
Object
- Object
- Celluloid::Group
- Includes:
- Celluloid
- Defined in:
- lib/celluloid/group.rb
Overview
Supervise collections of actors as a group
Defined Under Namespace
Classes: Member
Constant Summary
Constants included from Celluloid
Class Method Summary collapse
-
.members ⇒ Object
Actors or sub-applications to be supervised.
-
.run ⇒ Object
Run the application in the foreground with a simple watchdog.
-
.run! ⇒ Object
Start this application (and watch it with a supervisor).
-
.supervise(klass, options = {}) ⇒ Object
Register an actor class or a sub-application class to be launched and supervised while this application is running.
Instance Method Summary collapse
-
#finalize ⇒ Object
Terminate the group.
-
#initialize ⇒ Group
constructor
Start the group.
-
#restart_actor(actor, reason) ⇒ Object
Restart a crashed actor.
Methods included from Celluloid
#abort, actor?, #after, #alive?, #async, cores, current_actor, #current_actor, #defer, #every, exception_handler, #exclusive, exclusive?, #future, included, #inspect, #link, #linked_to?, #links, #method_missing, #name, #notify_link, #notify_unlink, #receive, receive, shutdown, #signal, #sleep, sleep, #tasks, #terminate, #unlink, uuid, version, #wait, #wrapped_object
Constructor Details
#initialize ⇒ Group
Start the group
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/celluloid/group.rb', line 39 def initialize @actors = {} # This is some serious lolcode, but like... start the supervisors for # this group self.class.members.each do |member| actor = member.start @actors[actor] = member end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Celluloid
Class Method Details
.members ⇒ Object
Actors or sub-applications to be supervised
9 10 11 |
# File 'lib/celluloid/group.rb', line 9 def members @members ||= [] end |
.run ⇒ Object
Run the application in the foreground with a simple watchdog
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/celluloid/group.rb', line 17 def run loop do supervisor = run! # Take five, toplevel supervisor sleep 5 while supervisor.alive? Logger.error "!!! Celluloid::Group #{self} crashed. Restarting..." end end |
.run! ⇒ Object
Start this application (and watch it with a supervisor)
14 |
# File 'lib/celluloid/group.rb', line 14 alias_method :run!, :supervise |
.supervise(klass, options = {}) ⇒ Object
Register an actor class or a sub-application class to be launched and supervised while this application is running. Available options are:
-
as: register this application in the Celluloid::Actor[] directory
-
args: start the actor with the given arguments
33 34 35 |
# File 'lib/celluloid/group.rb', line 33 def supervise(klass, = {}) members << Member.new(klass, ) end |
Instance Method Details
#finalize ⇒ Object
Terminate the group
51 52 53 54 55 56 57 58 |
# File 'lib/celluloid/group.rb', line 51 def finalize @actors.each do |actor, _| begin actor.terminate rescue DeadActorError end end end |
#restart_actor(actor, reason) ⇒ Object
Restart a crashed actor
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/celluloid/group.rb', line 61 def restart_actor(actor, reason) member = @actors.delete actor raise "a group member went missing. This shouldn't be!" unless member # Ignore supervisors that shut down cleanly return unless reason actor = member.start @actors[actor] = member end |