class DCell::Router
Route incoming messages to their recipient actors
Public Class Methods
find(mailbox_address)
click to toggle source
Find a mailbox by its address
# File lib/dcell/router.rb, line 22 def find(mailbox_address) @mutex.synchronize do begin ref = @mailboxes[mailbox_address] return unless ref ref.__getobj__ rescue WeakRef::RefError # The referenced actor is dead, so prune the registry @mailboxes.delete mailbox_address nil end end end
gc()
click to toggle source
Prune all entries that point to dead objects
# File lib/dcell/router.rb, line 37 def gc @mutex.synchronize do @mailboxes.each do |id, ref| @mailboxes.delete id unless ref.weakref_alive? end end end
register(mailbox)
click to toggle source
Enter a mailbox into the registry
# File lib/dcell/router.rb, line 11 def register(mailbox) @mutex.synchronize do address = mailbox.address ref = @mailboxes[address] @mailboxes[address] = WeakRef.new(mailbox) unless ref && ref.weakref_alive? address end end