Class: Jubatus::Common::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/jubatus/common/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, name) ⇒ Client

Returns a new instance of Client.


11
12
13
14
# File 'lib/jubatus/common/client.rb', line 11

def initialize(client, name)
  @client = client
  @name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name


9
10
11
# File 'lib/jubatus/common/client.rb', line 9

def name
  @name
end

Instance Method Details

#call(method, args, ret_type, args_type) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jubatus/common/client.rb', line 16

def call(method, args, ret_type, args_type)
  if args.size != args_type.size
    raise "number of arguemnts for \"%s\" must to be %d, but %d arguments are given" % [method, args_type.size, args.size]
  end
  values = [@name]
  args.zip(args_type).each do |v, t|
    values << t.to_msgpack(v)
  end
  future = @client.call_async_apply(method, values)
  future.attach_error_handler do |error, result|
    error_handler(error, result)
  end
  ret = future.get

  if ret_type != nil
    return ret_type.from_msgpack(ret)
  end
end

#error_handler(error, result) ⇒ Object


35
36
37
38
39
40
41
42
43
# File 'lib/jubatus/common/client.rb', line 35

def error_handler(error, result)
  if error == 1
    raise UnknownMethod
  elsif error == 2
    raise TypeMismatch
  else
    raise MessagePack::RPC::RPCError.create(error, result)
  end
end