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, sender, method, arguments, block) ⇒ RPC

Returns a new instance of RPC.



29
30
31
# File 'lib/dcell/rpc.rb', line 29

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

Class Method Details

._load(string) ⇒ Object

Loader for custom marshal format

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dcell/rpc.rb', line 40

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
    type = string.slice!(0, string.index(":") + 1)
    types = {
      "rpc" => RPC,
      "rpb" => RPB,
      "rpbc" => RPBC,
    }
    types.fetch(type[0..-2]).new("#{uuid}@#{node_id}", *Marshal.load(string))
  end
end

Instance Method Details

#_dump(level) ⇒ Object

Custom marshaller for compatibility with Celluloid::Mailbox marshalling



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

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