lib/dcell/celluloid_ext.rb in dcell-0.10.0 vs lib/dcell/celluloid_ext.rb in dcell-0.12.0.pre
- old
+ new
@@ -26,28 +26,39 @@
end
# Create an actor proxy object which routes messages over DCell's overlay
# network and back to the original mailbox
def self._load(string)
- mailbox = Celluloid::Mailbox._load(string)
+ mailbox = ::Celluloid::Mailbox._load(string)
case mailbox
- when DCell::MailboxProxy
- DCell::ActorProxy.new mailbox
- when Celluloid::Mailbox
- Celluloid::ActorProxy.new(mailbox)
- else raise "funny, I did not expect to see a #{mailbox.class} here"
+ when ::DCell::MailboxProxy
+ actor = ::DCell::Actor.new(mailbox)
+ ::DCell::ActorProxy.new actor
+ when ::Celluloid::Mailbox
+ actor = find_actor(mailbox)
+ ::Celluloid::ActorProxy.new(actor)
+ else ::Kernel.raise "funny, I did not expect to see a #{mailbox.class} here"
end
end
+
+ def self.find_actor(mailbox)
+ ::Thread.list.each do |t|
+ if actor = t[:actor]
+ return actor if actor.mailbox == mailbox
+ end
+ end
+ ::Kernel.raise "no actor found for mailbox: #{mailbox.inspect}"
+ end
end
class Mailbox
# This custom dumper registers actors with the DCell registry so they can
# be reached remotely.
def _dump(level)
mailbox_id = DCell::Router.register self
- "#{mailbox_id}@#{DCell.id}@#{DCell.addr}"
+ "#{mailbox_id}@#{DCell.id}"
end
# Create a mailbox proxy object which routes messages over DCell's overlay
# network and back to the original mailbox
def self._load(string)
@@ -68,10 +79,10 @@
end
class Future
def _dump(level)
mailbox_id = DCell::Router.register self
- "#{mailbox_id}@#{DCell.id}@#{DCell.addr}"
+ "#{mailbox_id}@#{DCell.id}"
end
def self._load(string)
DCell::FutureProxy._load(string)
end