hyperdex 1.4.5.3.g9d31c19 → 1.4.5.5.gf1ae4e6

Sign up to get free protection for your applications and to get access to all the features.
data/ext/client.c CHANGED
@@ -40,7 +40,6 @@
40
40
 
41
41
  extern VALUE mod_hyperdex;
42
42
  static VALUE mod_hyperdex_client;
43
- static VALUE class_exception;
44
43
  static VALUE Set;
45
44
  static VALUE class_client;
46
45
  static VALUE class_predicate;
@@ -71,7 +70,9 @@ hyperdex_ruby_client_throw_exception(enum hyperdex_client_returncode status,
71
70
  const char* error_message)
72
71
  {
73
72
  VALUE args[2] = { INT2NUM(status), rb_str_new2(error_message) };
74
- rb_exc_raise(rb_class_new_instance(2, args, class_exception));
73
+ VALUE klass = rb_path2class("HyperDex::Client");
74
+
75
+ rb_exc_raise(rb_funcall2(klass, rb_intern("exception"), 2, args));
75
76
  }
76
77
 
77
78
  /******************************* Predicate class ******************************/
@@ -904,9 +905,6 @@ Init_hyperdex_client()
904
905
  /* setup the module */
905
906
  mod_hyperdex_client = rb_define_module_under(mod_hyperdex, "Client");
906
907
 
907
- /* create the Exception class */
908
- class_exception = rb_define_class_under(mod_hyperdex_client, "HyperDexClientException", rb_eStandardError);
909
-
910
908
  /* create the Client class */
911
909
  class_client = rb_define_class_under(mod_hyperdex_client, "Client", rb_cObject);
912
910
 
@@ -11,6 +11,10 @@ module HyperDex::Client
11
11
  end
12
12
  end
13
13
 
14
+ def self.exception(status, message)
15
+ HyperDex::Client::Exception::Map[status].new(message)
16
+ end
17
+
14
18
  def self.build_attribute(attr)
15
19
  type = attr[:datatype]
16
20
  value = attr[:value].read_string(attr[:value_sz])
@@ -22,10 +26,8 @@ module HyperDex::Client
22
26
  when :INT64
23
27
  i = ::FFI::MemoryPointer.new(:int64_t)
24
28
  if HyperDex::FFI::DS.unpack_int(attr[:value], attr[:value_sz], i) < 0
25
- raise HyperDex::Client::HyperDexClientException.new(
26
- HyperDex::Client::SERVERERROR,
27
- "server sent malformed int attribute (#{value.inspect})"
28
- )
29
+ raise HyperDex::Client::ServerError,
30
+ "server sent malformed int attribute (#{value.inspect})"
29
31
  end
30
32
 
31
33
  i.read_int64
@@ -33,10 +35,8 @@ module HyperDex::Client
33
35
  when :FLOAT
34
36
  d = ::FFI::MemoryPointer.new(:double)
35
37
  if HyperDex::FFI::DS.unpack_float(attr[:value], attr[:value_sz], d) < 0
36
- raise HyperDex::Client::HyperDexClientException.new(
37
- HyperDex::Client::SERVERERROR,
38
- "server sent malformed float attribute (#{value.inspect})"
39
- )
38
+ raise HyperDex::Client::ServerError,
39
+ "server sent malformed float attribute (#{value.inspect})"
40
40
  end
41
41
 
42
42
  d.read_double
@@ -45,10 +45,8 @@ module HyperDex::Client
45
45
  begin
46
46
  JSON.parse(value)
47
47
  rescue JSON::ParserError
48
- raise HyperDex::Client::HyperDexClientException.new(
49
- HyperDex::Client::SERVERERROR,
50
- "server sent malformed attribute(document)"
51
- )
48
+ raise HyperDex::Client::ServerError,
49
+ "server sent malformed attribute(document)"
52
50
  end
53
51
 
54
52
  when :LIST_STRING
@@ -59,10 +57,8 @@ module HyperDex::Client
59
57
  res = []
60
58
  while (result = HyperDex::FFI::DS.iterate_list_string_next(iter, ptr, len)) > 0
61
59
  if result < 0
62
- raise HyperDex::Client::HyperDexClientException.new(
63
- HyperDex::Client::SERVERERROR,
64
- "server sent malformed list(string)"
65
- )
60
+ raise HyperDex::Client::ServerError,
61
+ "server sent malformed list(string)"
66
62
  end
67
63
 
68
64
  str = ptr.read_pointer
@@ -78,10 +74,8 @@ module HyperDex::Client
78
74
  res = []
79
75
  while (result = HyperDex::FFI::DS.iterate_list_int_next(iter, int)) > 0
80
76
  if result < 0
81
- raise HyperDex::Client::HyperDexClientException.new(
82
- HyperDex::Client::SERVERERROR,
83
- "server sent malformed list(int)"
84
- )
77
+ raise HyperDex::Client::ServerError,
78
+ "server sent malformed list(int)"
85
79
  end
86
80
 
87
81
  res << int.read_int64
@@ -96,10 +90,8 @@ module HyperDex::Client
96
90
  res = []
97
91
  while (result = HyperDex::FFI::DS.iterate_list_float_next(iter, dbl)) > 0
98
92
  if result < 0
99
- raise HyperDex::Client::HyperDexClientException.new(
100
- HyperDex::Client::SERVERERROR,
101
- "server sent malformed list(float)"
102
- )
93
+ raise HyperDex::Client::ServerError,
94
+ "server sent malformed list(float)"
103
95
  end
104
96
 
105
97
  res << dbl.read_double
@@ -115,10 +107,8 @@ module HyperDex::Client
115
107
  res = Set.new
116
108
  while (result = HyperDex::FFI::DS.iterate_set_string_next(iter, ptr, len)) > 0
117
109
  if result < 0
118
- raise HyperDex::Client::HyperDexClientException.new(
119
- HyperDex::Client::SERVERERROR,
120
- "server sent malformed set(string)"
121
- )
110
+ raise HyperDex::Client::ServerError,
111
+ "server sent malformed set(string)"
122
112
  end
123
113
 
124
114
  str = ptr.read_pointer
@@ -134,10 +124,8 @@ module HyperDex::Client
134
124
  res = Set.new
135
125
  while (result = HyperDex::FFI::DS.iterate_set_int_next(iter, int)) > 0
136
126
  if result < 0
137
- raise HyperDex::Client::HyperDexClientException.new(
138
- HyperDex::Client::SERVERERROR,
139
- "server sent malformed set(int)"
140
- )
127
+ raise HyperDex::Client::ServerError,
128
+ "server sent malformed set(int)"
141
129
  end
142
130
 
143
131
  res << int.read_int64
@@ -152,10 +140,8 @@ module HyperDex::Client
152
140
  res = Set.new
153
141
  while (result = HyperDex::FFI::DS.iterate_set_float_next(iter, dbl)) > 0
154
142
  if result < 0
155
- raise HyperDex::Client::HyperDexClientException.new(
156
- HyperDex::Client::SERVERERROR,
157
- "server sent malformed set(float)"
158
- )
143
+ raise HyperDex::Client::ServerError,
144
+ "server sent malformed set(float)"
159
145
  end
160
146
 
161
147
  res << dbl.read_double
@@ -173,10 +159,8 @@ module HyperDex::Client
173
159
  res = {}
174
160
  while (result = HyperDex::FFI::DS.iterate_map_string_string_next(iter, kptr, klen, vptr, vlen)) > 0
175
161
  if result < 0
176
- raise HyperDex::Client::HyperDexClientException.new(
177
- HyperDex::Client::SERVERERROR,
178
- "server sent malformed map(string, string)"
179
- )
162
+ raise HyperDex::Client::ServerError,
163
+ "server sent malformed map(string, string)"
180
164
  end
181
165
 
182
166
  kstr = kptr.read_pointer
@@ -197,10 +181,8 @@ module HyperDex::Client
197
181
  res = {}
198
182
  while (result = HyperDex::FFI::DS.iterate_map_string_int_next(iter, kptr, klen, vint)) > 0
199
183
  if result < 0
200
- raise HyperDex::Client::HyperDexClientException.new(
201
- HyperDex::Client::SERVERERROR,
202
- "server sent malformed map(string, int)"
203
- )
184
+ raise HyperDex::Client::ServerError,
185
+ "server sent malformed map(string, int)"
204
186
  end
205
187
 
206
188
  kstr = kptr.read_pointer
@@ -219,10 +201,8 @@ module HyperDex::Client
219
201
  res = {}
220
202
  while (result = HyperDex::FFI::DS.iterate_map_string_float_next(iter, kptr, klen, vdbl)) > 0
221
203
  if result < 0
222
- raise HyperDex::Client::HyperDexClientException.new(
223
- HyperDex::Client::SERVERERROR,
224
- "server sent malformed map(string, float)"
225
- )
204
+ raise HyperDex::Client::ServerError,
205
+ "server sent malformed map(string, float)"
226
206
  end
227
207
 
228
208
  kstr = kptr.read_pointer
@@ -241,10 +221,8 @@ module HyperDex::Client
241
221
  res = {}
242
222
  while (result = HyperDex::FFI::DS.iterate_map_int_string_next(iter, kint, vptr, vlen)) > 0
243
223
  if result < 0
244
- raise HyperDex::Client::HyperDexClientException.new(
245
- HyperDex::Client::SERVERERROR,
246
- "server sent malformed map(int, string)"
247
- )
224
+ raise HyperDex::Client::ServerError,
225
+ "server sent malformed map(int, string)"
248
226
  end
249
227
 
250
228
  vstr = vptr.read_pointer
@@ -262,10 +240,8 @@ module HyperDex::Client
262
240
  res = {}
263
241
  while (result = HyperDex::FFI::DS.iterate_map_int_int_next(iter, kint, vint)) > 0
264
242
  if result < 0
265
- raise HyperDex::Client::HyperDexClientException.new(
266
- HyperDex::Client::SERVERERROR,
267
- "server sent malformed map(int, int)"
268
- )
243
+ raise HyperDex::Client::ServerError,
244
+ "server sent malformed map(int, int)"
269
245
  end
270
246
 
271
247
  res[kint.read_int64] = vint.read_int64
@@ -281,10 +257,8 @@ module HyperDex::Client
281
257
  res = {}
282
258
  while (result = HyperDex::FFI::DS.iterate_map_int_float_next(iter, kint, vdbl)) > 0
283
259
  if result < 0
284
- raise HyperDex::Client::HyperDexClientException.new(
285
- HyperDex::Client::SERVERERROR,
286
- "server sent malformed map(int, float)"
287
- )
260
+ raise HyperDex::Client::ServerError,
261
+ "server sent malformed map(int, float)"
288
262
  end
289
263
 
290
264
  res[kint.read_int64] = vdbl.read_double
@@ -301,10 +275,8 @@ module HyperDex::Client
301
275
  res = {}
302
276
  while (result = HyperDex::FFI::DS.iterate_map_float_string_next(iter, kdbl, vptr, vlen)) > 0
303
277
  if result < 0
304
- raise HyperDex::Client::HyperDexClientException.new(
305
- HyperDex::Client::SERVERERROR,
306
- "server sent malformed map(float, string)"
307
- )
278
+ raise HyperDex::Client::ServerError,
279
+ "server sent malformed map(float, string)"
308
280
  end
309
281
 
310
282
  vstr = vptr.read_pointer
@@ -322,10 +294,8 @@ module HyperDex::Client
322
294
  res = {}
323
295
  while (result = HyperDex::FFI::DS.iterate_map_float_int_next(iter, kdbl, vint)) > 0
324
296
  if result < 0
325
- raise HyperDex::Client::HyperDexClientException.new(
326
- HyperDex::Client::SERVERERROR,
327
- "server sent malformed map(float, int)"
328
- )
297
+ raise HyperDex::Client::ServerError,
298
+ "server sent malformed map(float, int)"
329
299
  end
330
300
 
331
301
  res[kdbl.read_double] = vint.read_int64
@@ -341,10 +311,8 @@ module HyperDex::Client
341
311
  res = {}
342
312
  while (result = HyperDex::FFI::DS.iterate_map_float_float_next(iter, kdbl, vdbl)) > 0
343
313
  if result < 0
344
- raise HyperDex::Client::HyperDexClientException.new(
345
- HyperDex::Client::SERVERERROR,
346
- "server sent malformed map(int, float)"
347
- )
314
+ raise HyperDex::Client::ServerError,
315
+ "server sent malformed map(int, float)"
348
316
  end
349
317
 
350
318
  res[kdbl.read_double] = vdbl.read_double
@@ -353,10 +321,8 @@ module HyperDex::Client
353
321
  res
354
322
 
355
323
  else
356
- raise HyperDex::Client::HyperDexClientException.new(
357
- HyperDex::Client::SERVERERROR,
358
- "server sent malformed attributes"
359
- )
324
+ raise HyperDex::Client::ServerError,
325
+ "server sent malformed attributes"
360
326
  end
361
327
  end
362
328
 
@@ -372,6 +338,6 @@ end
372
338
 
373
339
  require_relative 'client/client'
374
340
  require_relative 'client/deferred'
375
- require_relative 'client/hyperdex_client_exception'
341
+ require_relative 'client/exception'
376
342
  require_relative 'client/iterator'
377
343
  require_relative 'client/response'
@@ -16,10 +16,7 @@ class HyperDex::Client::Client
16
16
  rc = ::FFI::MemoryPointer.new(HyperDex::FFI::Client.enum_type(:hyperdex_client_returncode).native_type)
17
17
  while (ret = HyperDex::FFI::Client.hyperdex_client_loop(@client, timeout, rc)) < 0
18
18
  if rc.read_int32 != HyperDex::Client::INTERRUPTED
19
- raise HyperDex::Client::HyperDexClientException.new(
20
- rc.read_int32,
21
- self.error_message
22
- )
19
+ raise HyperDex::Client.exception(rc.read_int32, self.error_message)
23
20
  end
24
21
  end
25
22
 
@@ -28,10 +25,8 @@ class HyperDex::Client::Client
28
25
 
29
26
  def poll_fd
30
27
  if (fd = HyperDex::FFI::Client.hyperdex_client_poll(@client)) < 0
31
- raise HyperDex::Client::HyperDexClientException.new(
32
- HyperDex::Client::EXCEPTION,
33
- "CAN'T HAPPEN: hyperdex_client_poll failed!"
34
- )
28
+ raise HyperDex::Client::PollFailed,
29
+ self.error_messsage
35
30
  end
36
31
 
37
32
  fd
@@ -0,0 +1,109 @@
1
+ module HyperDex::Client
2
+ class Exception < StandardError
3
+ @status = HyperDex::Client::EXCEPTION
4
+
5
+ def status
6
+ self.class.status
7
+ end
8
+
9
+ def self.status
10
+ self.class.instance_variable_get(:@status)
11
+ end
12
+
13
+ def symbol
14
+ HyperDex::FFI::Client.
15
+ hyperdex_client_returncode_to_string(status).
16
+ read_string
17
+ end
18
+ end
19
+
20
+ HyperDexClientException = Exception
21
+
22
+ class UnknownSpaceError < Exception
23
+ @status = HyperDex::Client::UNKNOWNSPACE
24
+ end
25
+
26
+ class CoordFailError < Exception
27
+ @status = HyperDex::Client::COORDFAIL
28
+ end
29
+
30
+ class ServerError < Exception
31
+ @status = HyperDex::Client::SERVERERROR
32
+ end
33
+
34
+ class PollFailedError < Exception
35
+ @status = HyperDex::Client::POLLFAILED
36
+ end
37
+
38
+ class OverflowError < Exception
39
+ @status = HyperDex::Client::OVERFLOW
40
+ end
41
+
42
+ class ReconfigureError < Exception
43
+ @status = HyperDex::Client::RECONFIGURE
44
+ end
45
+
46
+ class TimeoutError < Exception
47
+ @status = HyperDex::Client::TIMEOUT
48
+ end
49
+
50
+ class UnknownAttrError < Exception
51
+ @status = HyperDex::Client::UNKNOWNATTR
52
+ end
53
+
54
+ class DupeAttrError < Exception
55
+ @status = HyperDex::Client::DUPEATTR
56
+ end
57
+
58
+ class NonePendingError < Exception
59
+ @status = HyperDex::Client::NONEPENDING
60
+ end
61
+
62
+ class DontUseKeyError < Exception
63
+ @status = HyperDex::Client::DONTUSEKEY
64
+ end
65
+
66
+ class WrongTypeError < Exception
67
+ @status = HyperDex::Client::WRONGTYPE
68
+ end
69
+
70
+ class NoMemError < Exception
71
+ @status = HyperDex::Client::NOMEM
72
+ end
73
+
74
+ class InterruptedError < Exception
75
+ @status = HyperDex::Client::INTERRUPTED
76
+ end
77
+
78
+ class ClusterJumpError < Exception
79
+ @status = HyperDex::Client::CLUSTER_JUMP
80
+ end
81
+
82
+ class OfflineError < Exception
83
+ @status = HyperDex::Client::OFFLINE
84
+ end
85
+
86
+ class InternalError < Exception
87
+ @status = HyperDex::Client::INTERNAL
88
+ end
89
+
90
+ class GarbageError < Exception
91
+ @status = HyperDex::Client::GARBAGE
92
+ end
93
+
94
+ EXCEPTION_STATUS_MAP = ObjectSpace.each_object(Class).reduce({}) do |h, ex|
95
+ if ex.ancestors.include?(::HyperDex::Client::Exception)
96
+ h[ex.status] = ex
97
+ end
98
+ h
99
+ end
100
+
101
+ def self.exception(status, message)
102
+ klass = EXCEPTION_STATUS_MAP[status]
103
+ if klass.nil?
104
+ klass = HyperDex::Client::Exception
105
+ end
106
+
107
+ klass.new(message)
108
+ end
109
+ end
@@ -12,9 +12,7 @@ class HyperDex::Client::Iterator < HyperDex::Client::Response
12
12
  elsif status == HyperDex::Client::SUCCESS
13
13
  @backlog << encode_return
14
14
  else
15
- @backlog << HyperDex::Client::HyperDexClientException.new(
16
- status, @client.error_message
17
- )
15
+ @backlog << HyperDex::Client::exception(status, @client.error_message)
18
16
  end
19
17
  end
20
18
 
@@ -61,10 +61,7 @@ class HyperDex::Client::Response
61
61
  when HyperDex::Client::CMPFAIL
62
62
  false
63
63
  else
64
- raise HyperDex::Client::HyperDexClientException.new(
65
- status,
66
- @client.error_message
67
- )
64
+ raise HyperDex::Client.exception(status, @client.error_message)
68
65
  end
69
66
  end
70
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperdex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.5.3.g9d31c19
4
+ version: 1.4.5.5.gf1ae4e6
5
5
  prerelease: 8
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-21 00:00:00.000000000 Z
12
+ date: 2014-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi-enum-generator
@@ -241,7 +241,7 @@ files:
241
241
  - lib/hyperdex/client.rb
242
242
  - lib/hyperdex/client/client.rb
243
243
  - lib/hyperdex/client/deferred.rb
244
- - lib/hyperdex/client/hyperdex_client_exception.rb
244
+ - lib/hyperdex/client/exception.rb
245
245
  - lib/hyperdex/client/iterator.rb
246
246
  - lib/hyperdex/client/response.rb
247
247
  - lib/hyperdex/ffi.rb
@@ -264,7 +264,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
264
264
  version: '0'
265
265
  segments:
266
266
  - 0
267
- hash: -1553449030944828785
267
+ hash: -2098128700064581276
268
268
  required_rubygems_version: !ruby/object:Gem::Requirement
269
269
  none: false
270
270
  requirements:
@@ -1,9 +0,0 @@
1
- class HyperDex::Client::HyperDexClientException
2
- attr_accessor :status, :symbol
3
-
4
- def initialize(status, message)
5
- super(message)
6
- @status = status
7
- @symbol = HyperDex::FFI::Client.hyperdex_client_returncode_to_string(status).read_string
8
- end
9
- end