lib/celluloid.rb in celluloid-0.13.0.pre vs lib/celluloid.rb in celluloid-0.13.0.pre2
- old
+ new
@@ -4,20 +4,18 @@
require 'set'
module Celluloid
extend self # expose all instance methods as singleton methods
- # How long actors have to terminate
- SHUTDOWN_TIMEOUT = 10
-
# Warning message added to Celluloid objects accessed outside their actors
BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT "
class << self
- attr_accessor :internal_pool # Internal thread pool
- attr_accessor :logger # Thread-safe logger class
- attr_accessor :task_class # Default task type to use
+ attr_accessor :internal_pool # Internal thread pool
+ attr_accessor :logger # Thread-safe logger class
+ attr_accessor :task_class # Default task type to use
+ attr_accessor :shutdown_timeout # How long actors have to terminate
def included(klass)
klass.send :extend, ClassMethods
klass.send :include, InstanceMethods
end
@@ -48,13 +46,30 @@
# Define an exception handler for actor crashes
def exception_handler(&block)
Logger.exception_handler(&block)
end
+ def suspend(status, waiter)
+ task = Thread.current[:celluloid_task]
+ if task && !Celluloid.exclusive?
+ waiter.before_suspend(task) if waiter.respond_to?(:before_suspend)
+ Task.suspend(status)
+ else
+ waiter.wait
+ end
+ end
+
+ # Launch default services
+ # FIXME: We should set up the supervision hierarchy here
+ def boot
+ Celluloid::Notifications::Fanout.supervise_as :notifications_fanout
+ Celluloid::IncidentReporter.supervise_as :default_incident_reporter, STDERR
+ end
+
# Shut down all running actors
def shutdown
- Timeout.timeout(SHUTDOWN_TIMEOUT) do
+ Timeout.timeout(shutdown_timeout) do
actors = Actor.all
Logger.debug "Terminating #{actors.size} actors..." if actors.size > 0
# Attempt to shut down the supervision tree, if available
Supervisor.root.terminate if Supervisor.root
@@ -75,11 +90,11 @@
end
Logger.debug "Shutdown completed cleanly"
end
rescue Timeout::Error => ex
- Logger.error("Couldn't cleanly terminate all actors in #{SHUTDOWN_TIMEOUT} seconds!")
+ Logger.error("Couldn't cleanly terminate all actors in #{shutdown_timeout} seconds!")
end
end
# Class methods added to classes which include Celluloid
module ClassMethods
@@ -202,10 +217,16 @@
@exclusive_methods ||= Set.new
@exclusive_methods.merge methods.map(&:to_sym)
end
end
+ # Mark methods as running blocks on the receiver
+ def execute_block_on_receiver(*methods)
+ # A noop method in preparation
+ # See https://github.com/celluloid/celluloid/pull/55
+ end
+
# Configuration options for Actor#new
def actor_options
{
:mailbox => mailbox_class.new,
:proxy_class => proxy_class,
@@ -455,6 +476,10 @@
require 'celluloid/supervisor'
require 'celluloid/notifications'
require 'celluloid/logging'
require 'celluloid/legacy' unless defined?(CELLULOID_FUTURE)
-require 'celluloid/boot'
+
+# Configure default systemwide settings
+Celluloid.task_class = Celluloid::TaskFiber
+Celluloid.logger = Logger.new(STDERR)
+Celluloid.shutdown_timeout = 10
\ No newline at end of file