Class: DCell::RPC

Inherits:
Celluloid::SyncCall show all
Defined in:
lib/dcell/rpc.rb

Defined Under Namespace

Classes: Manager

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, caller, method, arguments, block) ⇒ RPC

Returns a new instance of RPC.



5
6
7
# File 'lib/dcell/rpc.rb', line 5

def initialize(id, caller, method, arguments, block)
  @id, @caller, @method, @arguments, @block = id, caller, method, arguments, block
end

Class Method Details

._load(string) ⇒ Object

Loader for custom marshal format

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dcell/rpc.rb', line 16

def self._load(string)
  id = string.slice!(0, string.index(":") + 1)
  match = id.match(/^([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})@(.+?):$/)
  raise ArgumentError, "couldn't parse call ID" unless match

  uuid, node_id = match[1], match[2]

  if DCell.id == node_id
    Manager.claim uuid
  else
    caller, method, arguments, block = Marshal.load(string)
    RPC.new("#{uuid}@#{node_id}", caller, method, arguments, block)
  end
end

Instance Method Details

#_dump(level) ⇒ Object

Custom marshaller for compatibility with Celluloid::Mailbox marshalling



10
11
12
13
# File 'lib/dcell/rpc.rb', line 10

def _dump(level)
  payload = Marshal.dump [@caller, @method, @arguments, @block]
  "#{@id}:#{payload}"
end