Class: DCell::MailboxProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/dcell/mailbox_proxy.rb

Overview

A proxy object for a mailbox that delivers messages to the real mailbox on a remote node on a server far, far away…

Defined Under Namespace

Classes: InvalidNodeError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ MailboxProxy

Returns a new instance of MailboxProxy.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dcell/mailbox_proxy.rb', line 7

def initialize(address)
  mailbox_id, node_id = address.split("@")

  # Create a proxy to the mailbox on the remote node
  raise ArgumentError, "no mailbox_id given" unless mailbox_id
 
  @node_id = node_id
  @node = Node[node_id]
  raise ArgumentError, "invalid node_id given" unless @node
  
  @mailbox_id = mailbox_id
end

Class Method Details

._load(address) ⇒ Object

Loader for custom marshal format



45
46
47
48
49
50
51
# File 'lib/dcell/mailbox_proxy.rb', line 45

def self._load(address)
  if mailbox = DCell::Router.find(address)
    mailbox
  else
    DCell::MailboxProxy.new(address)
  end
end

Instance Method Details

#<<(message) ⇒ Object

Send a message to the mailbox



30
31
32
# File 'lib/dcell/mailbox_proxy.rb', line 30

def <<(message)
  @node.async.send_message Message::Relay.new(self, message)
end

#_dump(level) ⇒ Object

Custom marshaller for compatibility with Celluloid::Mailbox marshalling



40
41
42
# File 'lib/dcell/mailbox_proxy.rb', line 40

def _dump(level)
  "#{@mailbox_id}@#{@node_id}"
end

#addressObject

name@host style address



21
22
23
# File 'lib/dcell/mailbox_proxy.rb', line 21

def address
  "#{@mailbox_id}@#{@node_id}"
end

#alive?Boolean

Is the remote mailbox still alive?

Returns:

  • (Boolean)


35
36
37
# File 'lib/dcell/mailbox_proxy.rb', line 35

def alive?
  true # FIXME: hax!
end

#inspectObject



25
26
27
# File 'lib/dcell/mailbox_proxy.rb', line 25

def inspect
  "#<DCell::MailboxProxy:0x#{object_id.to_s(16)} #{address}>"
end