Class: Celluloid::Application
- Includes:
- Celluloid
- Defined in:
- lib/vendor/celluloid/lib/celluloid/application.rb
Overview
Applications describe and manage networks of Celluloid actors
Defined Under Namespace
Classes: Supervisable
Constant Summary
Constants included from Celluloid
Class Method Summary collapse
-
.run ⇒ Object
Run the application in the foreground with a simple watchdog.
-
.run! ⇒ Object
Start this application (and watch it with a supervisor).
-
.supervisables ⇒ Object
Actors or sub-applications to be supervised.
-
.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
-
#initialize ⇒ Application
constructor
Start the application.
-
#restart_supervisor(supervisor, reason) ⇒ Object
Restart a crashed supervisor.
Methods included from Celluloid
#abort, actor?, #after, #alive?, #async, current, current_actor, #current_actor, included, #inspect, #link, #linked_to?, #links, #method_missing, #notify_link, #notify_unlink, #receive, receive, #signal, sleep, #sleep, #tasks, tasks, #terminate, #unlink, version, #wait, #wrapped_object
Constructor Details
#initialize ⇒ Application
Start the application
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vendor/celluloid/lib/celluloid/application.rb', line 39 def initialize @supervisors = {} # This is some serious lolcode, but like... start the supervisors for # this application self.class.supervisables.each do |supervisable| supervisor = supervisable.supervise @supervisors[supervisor] = supervisable end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Celluloid
Class Method Details
.run ⇒ Object
Run the application in the foreground with a simple watchdog
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/celluloid/lib/celluloid/application.rb', line 17 def run loop do supervisor = run! # Take five, toplevel supervisor sleep 5 while supervisor.alive? Logger.error "!!! Celluloid::Application #{self} crashed. Restarting..." end end |
.run! ⇒ Object
Start this application (and watch it with a supervisor)
14 |
# File 'lib/vendor/celluloid/lib/celluloid/application.rb', line 14 alias_method :run!, :supervise |
.supervisables ⇒ Object
Actors or sub-applications to be supervised
9 10 11 |
# File 'lib/vendor/celluloid/lib/celluloid/application.rb', line 9 def supervisables @supervisables ||= [] end |
.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/vendor/celluloid/lib/celluloid/application.rb', line 33 def supervise(klass, = {}) supervisables << Supervisable.new(klass, ) end |
Instance Method Details
#restart_supervisor(supervisor, reason) ⇒ Object
Restart a crashed supervisor
51 52 53 54 55 56 57 |
# File 'lib/vendor/celluloid/lib/celluloid/application.rb', line 51 def restart_supervisor(supervisor, reason) supervisable = @supervisors.delete supervisor raise "a supervisable went missing. This shouldn't be!" unless supervisable supervisor = supervisable.supervise @supervisors[supervisor] = supervisable end |