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(node_id, mailbox_id) ⇒ MailboxProxy

Returns a new instance of MailboxProxy.

Raises:

  • (ArgumentError)


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

def initialize(node_id, mailbox_id)
  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(string) ⇒ Object

Loader for custom marshal format



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dcell/mailbox_proxy.rb', line 47

def self._load(string)
  mailbox_id, node_id = string.split("@")

  if DCell.id == node_id
    # If we're on the local node, find the real mailbox
    mailbox = DCell::Router.find mailbox_id
    raise "tried to unmarshal dead Celluloid::Mailbox: #{mailbox_id}" unless mailbox
    mailbox
  else
    # Create a proxy to the mailbox on the remote node
    DCell::MailboxProxy.new(node_id, mailbox_id)
  end
end

Instance Method Details

#<<(message) ⇒ Object

Send a message to the mailbox



27
28
29
# File 'lib/dcell/mailbox_proxy.rb', line 27

def <<(message)
  @node.send_message! Message::Relay.new(@mailbox_id, message)
end

#_dump(level) ⇒ Object

Custom marshaller for compatibility with Celluloid::Mailbox marshalling



42
43
44
# File 'lib/dcell/mailbox_proxy.rb', line 42

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

#addressObject

name@host style address



18
19
20
# File 'lib/dcell/mailbox_proxy.rb', line 18

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

#alive?Boolean

Is the remote mailbox still alive?

Returns:

  • (Boolean)


37
38
39
# File 'lib/dcell/mailbox_proxy.rb', line 37

def alive?
  true # FIXME: hax!
end

#inspectObject



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

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

#system_event(event) ⇒ Object

Send a system event



32
33
34
# File 'lib/dcell/mailbox_proxy.rb', line 32

def system_event(event)
  @node.send_message! Message::SystemEvent.new(@mailbox_id, event)
end