lib/celluloid/actor.rb in celluloid-0.17.0 vs lib/celluloid/actor.rb in celluloid-0.17.1
- old
+ new
@@ -1,6 +1,5 @@
-
require "timers"
module Celluloid
# Actors are Celluloid's concurrency primitive. They're implemented as
# normal Ruby objects wrapped in threads which communicate with asynchronous
@@ -130,12 +129,13 @@
@thread = Internals::ThreadHandle.new(@actor_system, :actor) do
setup_thread
run
end
- @proxy = Proxy::Actor.new(@thread, @mailbox)
+ @proxy = Proxy::Actor.new(@mailbox, @thread)
Celluloid::Probe.actor_created(self) if $CELLULOID_MONITORING
+ Celluloid::Actor::Manager.actor_created(self) if $CELLULOID_MANAGED
end
def behavior_proxy
@behavior.proxy
end
@@ -165,13 +165,13 @@
@running = false
end
end
shutdown
- rescue Exception => ex
+ rescue ::Exception => ex
handle_crash(ex)
- raise unless ex.is_a? StandardError
+ raise unless ex.is_a?(StandardError) || ex.is_a?(Celluloid::Interruption)
end
# Terminate this actor
def terminate
@running = false
@@ -188,11 +188,11 @@
message = @mailbox.receive(remaining) do |msg|
msg.is_a?(LinkingResponse) &&
msg.actor.mailbox.address == receiver.mailbox.address &&
msg.type == type
end
- rescue TimeoutError
+ rescue TaskTimeout
next # IO reactor did something, no message in queue yet.
end
if message.instance_of? LinkingResponse
Celluloid::Probe.actors_linked(self, receiver) if $CELLULOID_MONITORING
@@ -203,11 +203,11 @@
system_events << message
else fail "Unexpected message type: #{message.class}. Expected LinkingResponse, NilClass, SystemEvent."
end
end
- fail TimeoutError, "linking timeout of #{LINKING_TIMEOUT} seconds exceeded with receiver: #{receiver}"
+ fail TaskTimeout, "linking timeout of #{LINKING_TIMEOUT} seconds exceeded with receiver: #{receiver}"
end
end
# Send a signal with the given name to all waiting methods
def signal(name, value = nil)
@@ -245,11 +245,11 @@
def timeout(duration)
bt = caller
task = Task.current
timer = @timers.after(duration) do
- exception = Task::TimeoutError.new("execution expired")
+ exception = TaskTimeout.new("execution expired")
exception.set_backtrace bt
task.resume exception
end
yield
ensure
@@ -283,34 +283,9 @@
unless @receivers.handle_message(message)
Internals::Logger.debug "Discarded message (unhandled): #{message}" if $CELLULOID_DEBUG
end
end
message
- end
-
- # Handle high-priority system event messages
- def handle_system_event(event)
- if event.instance_of? ExitEvent
- handle_exit_event(event)
- elsif event.instance_of? LinkingRequest
- event.process(links)
- elsif event.instance_of? NamingRequest
- @name = event.name
- Celluloid::Probe.actor_named(self) if $CELLULOID_MONITORING
- elsif event.instance_of? TerminationRequest
- terminate
- elsif event.instance_of? SignalConditionRequest
- event.call
- else
- Internals::Logger.debug "Discarded message (unhandled): #{message}" if $CELLULOID_DEBUG
- end
- end
-
- # Handle exit events received by this actor
- def handle_exit_event(event)
- @links.delete event.actor
-
- @exit_handler.call(event)
end
def default_exit_handler(event)
fail event.reason if event.reason
end