cassandra-driver 1.0.0.beta.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +4 -0
  3. data/README.md +125 -0
  4. data/lib/cassandra/auth/providers/password.rb +73 -0
  5. data/lib/cassandra/auth/providers.rb +16 -0
  6. data/lib/cassandra/auth.rb +97 -0
  7. data/lib/cassandra/client/batch.rb +212 -0
  8. data/lib/cassandra/client/client.rb +591 -0
  9. data/lib/cassandra/client/column_metadata.rb +54 -0
  10. data/lib/cassandra/client/connection_manager.rb +72 -0
  11. data/lib/cassandra/client/connector.rb +277 -0
  12. data/lib/cassandra/client/execute_options_decoder.rb +59 -0
  13. data/lib/cassandra/client/null_logger.rb +37 -0
  14. data/lib/cassandra/client/peer_discovery.rb +50 -0
  15. data/lib/cassandra/client/prepared_statement.rb +314 -0
  16. data/lib/cassandra/client/query_result.rb +230 -0
  17. data/lib/cassandra/client/request_runner.rb +71 -0
  18. data/lib/cassandra/client/result_metadata.rb +48 -0
  19. data/lib/cassandra/client/void_result.rb +78 -0
  20. data/lib/cassandra/client.rb +144 -0
  21. data/lib/cassandra/cluster/client.rb +768 -0
  22. data/lib/cassandra/cluster/connector.rb +244 -0
  23. data/lib/cassandra/cluster/control_connection.rb +425 -0
  24. data/lib/cassandra/cluster/metadata.rb +124 -0
  25. data/lib/cassandra/cluster/options.rb +42 -0
  26. data/lib/cassandra/cluster/registry.rb +198 -0
  27. data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +47 -0
  28. data/lib/cassandra/cluster/schema/partitioners/ordered.rb +37 -0
  29. data/lib/cassandra/cluster/schema/partitioners/random.rb +37 -0
  30. data/lib/cassandra/cluster/schema/partitioners.rb +21 -0
  31. data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +92 -0
  32. data/lib/cassandra/cluster/schema/replication_strategies/none.rb +39 -0
  33. data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +44 -0
  34. data/lib/cassandra/cluster/schema/replication_strategies.rb +21 -0
  35. data/lib/cassandra/cluster/schema/type_parser.rb +138 -0
  36. data/lib/cassandra/cluster/schema.rb +340 -0
  37. data/lib/cassandra/cluster.rb +215 -0
  38. data/lib/cassandra/column.rb +92 -0
  39. data/lib/cassandra/compression/compressors/lz4.rb +72 -0
  40. data/lib/cassandra/compression/compressors/snappy.rb +66 -0
  41. data/lib/cassandra/compression.rb +66 -0
  42. data/lib/cassandra/driver.rb +111 -0
  43. data/lib/cassandra/errors.rb +79 -0
  44. data/lib/cassandra/execution/info.rb +51 -0
  45. data/lib/cassandra/execution/options.rb +80 -0
  46. data/lib/cassandra/execution/trace.rb +152 -0
  47. data/lib/cassandra/future.rb +675 -0
  48. data/lib/cassandra/host.rb +79 -0
  49. data/lib/cassandra/keyspace.rb +133 -0
  50. data/lib/cassandra/listener.rb +87 -0
  51. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +149 -0
  52. data/lib/cassandra/load_balancing/policies/round_robin.rb +132 -0
  53. data/lib/cassandra/load_balancing/policies/token_aware.rb +119 -0
  54. data/lib/cassandra/load_balancing/policies/white_list.rb +90 -0
  55. data/lib/cassandra/load_balancing/policies.rb +19 -0
  56. data/lib/cassandra/load_balancing.rb +113 -0
  57. data/lib/cassandra/protocol/cql_byte_buffer.rb +307 -0
  58. data/lib/cassandra/protocol/cql_protocol_handler.rb +323 -0
  59. data/lib/cassandra/protocol/frame_decoder.rb +128 -0
  60. data/lib/cassandra/protocol/frame_encoder.rb +48 -0
  61. data/lib/cassandra/protocol/request.rb +38 -0
  62. data/lib/cassandra/protocol/requests/auth_response_request.rb +47 -0
  63. data/lib/cassandra/protocol/requests/batch_request.rb +76 -0
  64. data/lib/cassandra/protocol/requests/credentials_request.rb +47 -0
  65. data/lib/cassandra/protocol/requests/execute_request.rb +103 -0
  66. data/lib/cassandra/protocol/requests/options_request.rb +39 -0
  67. data/lib/cassandra/protocol/requests/prepare_request.rb +50 -0
  68. data/lib/cassandra/protocol/requests/query_request.rb +153 -0
  69. data/lib/cassandra/protocol/requests/register_request.rb +38 -0
  70. data/lib/cassandra/protocol/requests/startup_request.rb +49 -0
  71. data/lib/cassandra/protocol/requests/void_query_request.rb +24 -0
  72. data/lib/cassandra/protocol/response.rb +38 -0
  73. data/lib/cassandra/protocol/responses/auth_challenge_response.rb +41 -0
  74. data/lib/cassandra/protocol/responses/auth_success_response.rb +41 -0
  75. data/lib/cassandra/protocol/responses/authenticate_response.rb +41 -0
  76. data/lib/cassandra/protocol/responses/detailed_error_response.rb +60 -0
  77. data/lib/cassandra/protocol/responses/error_response.rb +50 -0
  78. data/lib/cassandra/protocol/responses/event_response.rb +39 -0
  79. data/lib/cassandra/protocol/responses/prepared_result_response.rb +64 -0
  80. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +43 -0
  81. data/lib/cassandra/protocol/responses/ready_response.rb +44 -0
  82. data/lib/cassandra/protocol/responses/result_response.rb +48 -0
  83. data/lib/cassandra/protocol/responses/rows_result_response.rb +139 -0
  84. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +60 -0
  85. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +57 -0
  86. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +42 -0
  87. data/lib/cassandra/protocol/responses/status_change_event_response.rb +44 -0
  88. data/lib/cassandra/protocol/responses/supported_response.rb +41 -0
  89. data/lib/cassandra/protocol/responses/topology_change_event_response.rb +34 -0
  90. data/lib/cassandra/protocol/responses/void_result_response.rb +39 -0
  91. data/lib/cassandra/protocol/type_converter.rb +384 -0
  92. data/lib/cassandra/protocol.rb +93 -0
  93. data/lib/cassandra/reconnection/policies/constant.rb +48 -0
  94. data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
  95. data/lib/cassandra/reconnection/policies.rb +20 -0
  96. data/lib/cassandra/reconnection.rb +49 -0
  97. data/lib/cassandra/result.rb +215 -0
  98. data/lib/cassandra/retry/policies/default.rb +47 -0
  99. data/lib/cassandra/retry/policies/downgrading_consistency.rb +71 -0
  100. data/lib/cassandra/retry/policies/fallthrough.rb +39 -0
  101. data/lib/cassandra/retry/policies.rb +21 -0
  102. data/lib/cassandra/retry.rb +142 -0
  103. data/lib/cassandra/session.rb +202 -0
  104. data/lib/cassandra/statement.rb +22 -0
  105. data/lib/cassandra/statements/batch.rb +95 -0
  106. data/lib/cassandra/statements/bound.rb +48 -0
  107. data/lib/cassandra/statements/prepared.rb +81 -0
  108. data/lib/cassandra/statements/simple.rb +58 -0
  109. data/lib/cassandra/statements/void.rb +33 -0
  110. data/lib/cassandra/statements.rb +23 -0
  111. data/lib/cassandra/table.rb +299 -0
  112. data/lib/cassandra/time_uuid.rb +142 -0
  113. data/lib/cassandra/util.rb +167 -0
  114. data/lib/cassandra/uuid.rb +104 -0
  115. data/lib/cassandra/version.rb +21 -0
  116. data/lib/cassandra.rb +428 -0
  117. data/lib/cassandra_murmur3.jar +0 -0
  118. metadata +211 -0
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ module Protocol
21
+ class TopologyChangeEventResponse < StatusChangeEventResponse
22
+ TYPE = 'TOPOLOGY_CHANGE'.freeze
23
+
24
+ def initialize(*args)
25
+ super
26
+ @type = TYPE
27
+ end
28
+
29
+ private
30
+
31
+ EVENT_TYPES[TYPE] = self
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ module Protocol
21
+ class VoidResultResponse < ResultResponse
22
+ def self.decode(protocol_version, buffer, length, trace_id=nil)
23
+ new(trace_id)
24
+ end
25
+
26
+ def to_s
27
+ %(RESULT VOID)
28
+ end
29
+
30
+ def void?
31
+ true
32
+ end
33
+
34
+ private
35
+
36
+ RESULT_TYPES[0x01] = self
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,384 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ module Protocol
21
+ class TypeConverter
22
+ def initialize
23
+ @from_bytes_converters = from_bytes_converters
24
+ @to_bytes_converters = to_bytes_converters
25
+ end
26
+
27
+ def from_bytes(buffer, type, size_bytes=4)
28
+ return nil if buffer.empty?
29
+ case type
30
+ when Array
31
+ return nil unless read_size(buffer, size_bytes)
32
+ case type.first
33
+ when :list
34
+ bytes_to_list(buffer, @from_bytes_converters[type[1]])
35
+ when :map
36
+ bytes_to_map(buffer, @from_bytes_converters[type[1]], @from_bytes_converters[type[2]])
37
+ when :set
38
+ bytes_to_set(buffer, @from_bytes_converters[type[1]])
39
+ end
40
+ else
41
+ @from_bytes_converters[type].call(buffer, size_bytes)
42
+ end
43
+ end
44
+
45
+ def to_bytes(buffer, type, value, size_bytes=4)
46
+ case type
47
+ when Array
48
+ unless value.nil? || value.is_a?(Enumerable)
49
+ raise InvalidValueError, 'Value for collection must be enumerable'
50
+ end
51
+ case type.first
52
+ when :list, :set
53
+ _, sub_type = type
54
+ if value
55
+ raw = CqlByteBuffer.new
56
+ raw.append_short(value.size)
57
+ value.each do |element|
58
+ to_bytes(raw, sub_type, element, 2)
59
+ end
60
+ buffer.append_bytes(raw)
61
+ else
62
+ nil_to_bytes(buffer, size_bytes)
63
+ end
64
+ when :map
65
+ _, key_type, value_type = type
66
+ if value
67
+ raw = CqlByteBuffer.new
68
+ raw.append_short(value.size)
69
+ value.each do |key, value|
70
+ to_bytes(raw, key_type, key, 2)
71
+ to_bytes(raw, value_type, value, 2)
72
+ end
73
+ buffer.append_bytes(raw)
74
+ else
75
+ nil_to_bytes(buffer, size_bytes)
76
+ end
77
+ else
78
+ raise UnsupportedColumnTypeError, %(Unsupported column collection type: #{type.first})
79
+ end
80
+ else
81
+ converter = @to_bytes_converters[type]
82
+ unless converter
83
+ raise UnsupportedColumnTypeError, %(Unsupported column type: #{type})
84
+ end
85
+ converter.call(buffer, value, size_bytes)
86
+ end
87
+ rescue TypeError => e
88
+ raise TypeError, %("#{value}" cannot be encoded as #{type.to_s.upcase}: #{e.message}), e.backtrace
89
+ end
90
+
91
+ private
92
+
93
+ def from_bytes_converters
94
+ {
95
+ :ascii => method(:bytes_to_ascii),
96
+ :bigint => method(:bytes_to_bigint),
97
+ :blob => method(:bytes_to_blob),
98
+ :boolean => method(:bytes_to_boolean),
99
+ :counter => method(:bytes_to_bigint),
100
+ :decimal => method(:bytes_to_decimal),
101
+ :double => method(:bytes_to_double),
102
+ :float => method(:bytes_to_float),
103
+ :int => method(:bytes_to_int),
104
+ :timestamp => method(:bytes_to_timestamp),
105
+ :varchar => method(:bytes_to_varchar),
106
+ :text => method(:bytes_to_varchar),
107
+ :varint => method(:bytes_to_varint),
108
+ :timeuuid => method(:bytes_to_timeuuid),
109
+ :uuid => method(:bytes_to_uuid),
110
+ :inet => method(:bytes_to_inet),
111
+ }
112
+ end
113
+
114
+ def to_bytes_converters
115
+ {
116
+ :ascii => method(:ascii_to_bytes),
117
+ :bigint => method(:bigint_to_bytes),
118
+ :blob => method(:blob_to_bytes),
119
+ :boolean => method(:boolean_to_bytes),
120
+ :counter => method(:bigint_to_bytes),
121
+ :decimal => method(:decimal_to_bytes),
122
+ :double => method(:double_to_bytes),
123
+ :float => method(:float_to_bytes),
124
+ :inet => method(:inet_to_bytes),
125
+ :int => method(:int_to_bytes),
126
+ :text => method(:varchar_to_bytes),
127
+ :varchar => method(:varchar_to_bytes),
128
+ :timestamp => method(:timestamp_to_bytes),
129
+ :timeuuid => method(:uuid_to_bytes),
130
+ :uuid => method(:uuid_to_bytes),
131
+ :varint => method(:varint_to_bytes),
132
+ }
133
+ end
134
+
135
+ def read_size(buffer, size_bytes)
136
+ if size_bytes == 2
137
+ size = buffer.read_short
138
+ return nil if size & 0x8000 == 0x8000
139
+ else
140
+ size = buffer.read_signed_int
141
+ return nil if size & 0x80000000 == 0x80000000
142
+ end
143
+ size
144
+ end
145
+
146
+ def bytes_to_ascii(buffer, size_bytes)
147
+ bytes = size_bytes == 4 ? buffer.read_bytes : buffer.read_short_bytes
148
+ bytes ? bytes.force_encoding(::Encoding::ASCII) : nil
149
+ end
150
+
151
+ def bytes_to_bigint(buffer, size_bytes)
152
+ return nil unless read_size(buffer, size_bytes)
153
+ buffer.read_long
154
+ end
155
+
156
+ def bytes_to_blob(buffer, size_bytes)
157
+ bytes = size_bytes == 4 ? buffer.read_bytes : buffer.read_short_bytes
158
+ bytes ? bytes : nil
159
+ end
160
+
161
+ def bytes_to_boolean(buffer, size_bytes)
162
+ return nil unless read_size(buffer, size_bytes)
163
+ buffer.read(1) == Constants::TRUE_BYTE
164
+ end
165
+
166
+ def bytes_to_decimal(buffer, size_bytes)
167
+ size = read_size(buffer, size_bytes)
168
+ return nil unless size
169
+ buffer.read_decimal(size)
170
+ end
171
+
172
+ def bytes_to_double(buffer, size_bytes)
173
+ return nil unless read_size(buffer, size_bytes)
174
+ buffer.read_double
175
+ end
176
+
177
+ def bytes_to_float(buffer, size_bytes)
178
+ return nil unless read_size(buffer, size_bytes)
179
+ buffer.read_float
180
+ end
181
+
182
+ def bytes_to_int(buffer, size_bytes)
183
+ return nil unless read_size(buffer, size_bytes)
184
+ buffer.read_signed_int
185
+ end
186
+
187
+ def bytes_to_timestamp(buffer, size_bytes)
188
+ return nil unless read_size(buffer, size_bytes)
189
+ timestamp = buffer.read_long
190
+ Time.at(timestamp/1000.0)
191
+ end
192
+
193
+ def bytes_to_varchar(buffer, size_bytes)
194
+ bytes = size_bytes == 4 ? buffer.read_bytes : buffer.read_short_bytes
195
+ bytes ? bytes.force_encoding(::Encoding::UTF_8) : nil
196
+ end
197
+
198
+ def bytes_to_varint(buffer, size_bytes)
199
+ size = read_size(buffer, size_bytes)
200
+ return nil unless size
201
+ buffer.read_varint(size)
202
+ end
203
+
204
+ def bytes_to_uuid(buffer, size_bytes)
205
+ return nil unless read_size(buffer, size_bytes)
206
+ buffer.read_uuid
207
+ end
208
+
209
+ def bytes_to_timeuuid(buffer, size_bytes)
210
+ return nil unless read_size(buffer, size_bytes)
211
+ buffer.read_uuid(TimeUuid)
212
+ end
213
+
214
+ def bytes_to_inet(buffer, size_bytes)
215
+ size = read_size(buffer, size_bytes)
216
+ return nil unless size
217
+ IPAddr.new_ntoh(buffer.read(size))
218
+ end
219
+
220
+ def bytes_to_list(buffer, value_converter)
221
+ list = []
222
+ size = buffer.read_short
223
+ size.times do
224
+ list << value_converter.call(buffer, 2)
225
+ end
226
+ list
227
+ end
228
+
229
+ def bytes_to_map(buffer, key_converter, value_converter)
230
+ map = {}
231
+ size = buffer.read_short
232
+ size.times do
233
+ key = key_converter.call(buffer, 2)
234
+ value = value_converter.call(buffer, 2)
235
+ map[key] = value
236
+ end
237
+ map
238
+ end
239
+
240
+ def bytes_to_set(buffer, value_converter)
241
+ set = Set.new
242
+ size = buffer.read_short
243
+ size.times do
244
+ set << value_converter.call(buffer, 2)
245
+ end
246
+ set
247
+ end
248
+
249
+ def ascii_to_bytes(buffer, value, size_bytes)
250
+ v = value && value.encode(::Encoding::ASCII)
251
+ if size_bytes == 4
252
+ buffer.append_bytes(v)
253
+ else
254
+ buffer.append_short_bytes(v)
255
+ end
256
+ end
257
+
258
+ def bigint_to_bytes(buffer, value, size_bytes)
259
+ if value
260
+ size_to_bytes(buffer, 8, size_bytes)
261
+ buffer.append_long(value)
262
+ else
263
+ nil_to_bytes(buffer, size_bytes)
264
+ end
265
+ end
266
+
267
+ def blob_to_bytes(buffer, value, size_bytes)
268
+ v = value && value.encode(::Encoding::BINARY)
269
+ if size_bytes == 4
270
+ buffer.append_bytes(v)
271
+ else
272
+ buffer.append_short_bytes(v)
273
+ end
274
+ end
275
+
276
+ def boolean_to_bytes(buffer, value, size_bytes)
277
+ if !value.nil?
278
+ size_to_bytes(buffer, 1, size_bytes)
279
+ buffer.append(value ? Constants::TRUE_BYTE : Constants::FALSE_BYTE)
280
+ else
281
+ nil_to_bytes(buffer, size_bytes)
282
+ end
283
+ end
284
+
285
+ def decimal_to_bytes(buffer, value, size_bytes)
286
+ raw = value && CqlByteBuffer.new.append_decimal(value)
287
+ if size_bytes == 4
288
+ buffer.append_bytes(raw)
289
+ else
290
+ buffer.append_short_bytes(raw)
291
+ end
292
+ end
293
+
294
+ def double_to_bytes(buffer, value, size_bytes)
295
+ if value
296
+ size_to_bytes(buffer, 8, size_bytes)
297
+ buffer.append_double(value)
298
+ else
299
+ nil_to_bytes(buffer, size_bytes)
300
+ end
301
+ end
302
+
303
+ def float_to_bytes(buffer, value, size_bytes)
304
+ if value
305
+ size_to_bytes(buffer, 4, size_bytes)
306
+ buffer.append_float(value)
307
+ else
308
+ nil_to_bytes(buffer, size_bytes)
309
+ end
310
+ end
311
+
312
+ def inet_to_bytes(buffer, value, size_bytes)
313
+ if value
314
+ size_to_bytes(buffer, value.ipv6? ? 16 : 4, size_bytes)
315
+ buffer.append(value.hton)
316
+ else
317
+ nil_to_bytes(buffer, size_bytes)
318
+ end
319
+ end
320
+
321
+ def int_to_bytes(buffer, value, size_bytes)
322
+ if value
323
+ size_to_bytes(buffer, 4, size_bytes)
324
+ buffer.append_int(value)
325
+ else
326
+ nil_to_bytes(buffer, size_bytes)
327
+ end
328
+ end
329
+
330
+ def varchar_to_bytes(buffer, value, size_bytes)
331
+ v = value && value.encode(::Encoding::UTF_8)
332
+ if size_bytes == 4
333
+ buffer.append_bytes(v)
334
+ else
335
+ buffer.append_short_bytes(v)
336
+ end
337
+ end
338
+
339
+ def timestamp_to_bytes(buffer, value, size_bytes)
340
+ if value
341
+ ms = (value.to_f * 1000).to_i
342
+ size_to_bytes(buffer, 8, size_bytes)
343
+ buffer.append_long(ms)
344
+ else
345
+ nil_to_bytes(buffer, size_bytes)
346
+ end
347
+ end
348
+
349
+ def uuid_to_bytes(buffer, value, size_bytes)
350
+ if value
351
+ size_to_bytes(buffer, 16, size_bytes)
352
+ buffer.append_uuid(value)
353
+ else
354
+ nil_to_bytes(buffer, size_bytes)
355
+ end
356
+ end
357
+
358
+ def varint_to_bytes(buffer, value, size_bytes)
359
+ raw = value && CqlByteBuffer.new.append_varint(value)
360
+ if size_bytes == 4
361
+ buffer.append_bytes(raw)
362
+ else
363
+ buffer.append_short_bytes(raw)
364
+ end
365
+ end
366
+
367
+ def size_to_bytes(buffer, size, size_bytes)
368
+ if size_bytes == 4
369
+ buffer.append_int(size)
370
+ else
371
+ buffer.append_short(size)
372
+ end
373
+ end
374
+
375
+ def nil_to_bytes(buffer, size_bytes)
376
+ if size_bytes == 4
377
+ buffer.append_int(-1)
378
+ else
379
+ buffer.append_short(-1)
380
+ end
381
+ end
382
+ end
383
+ end
384
+ end
@@ -0,0 +1,93 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ # @private
21
+ ProtocolError = Class.new(Error)
22
+
23
+ # @private
24
+ module Protocol
25
+ DecodingError = Class.new(ProtocolError)
26
+ EncodingError = Class.new(ProtocolError)
27
+ InvalidStreamIdError = Class.new(ProtocolError)
28
+ InvalidValueError = Class.new(ProtocolError)
29
+ UnsupportedOperationError = Class.new(ProtocolError)
30
+ UnsupportedFrameTypeError = Class.new(ProtocolError)
31
+ UnsupportedResultKindError = Class.new(ProtocolError)
32
+ UnsupportedColumnTypeError = Class.new(ProtocolError)
33
+ UnsupportedEventTypeError = Class.new(ProtocolError)
34
+ UnsupportedFeatureError = Class.new(ProtocolError)
35
+ UnexpectedCompressionError = Class.new(ProtocolError)
36
+ UnmaterializedRowsError = Class.new(ProtocolError)
37
+
38
+ module Formats
39
+ CHAR_FORMAT = 'c'.freeze
40
+ DOUBLE_FORMAT = 'G'.freeze
41
+ FLOAT_FORMAT = 'g'.freeze
42
+ INT_FORMAT = 'N'.freeze
43
+ SHORT_FORMAT = 'n'.freeze
44
+
45
+ BYTES_FORMAT = 'C*'.freeze
46
+ TWO_INTS_FORMAT = 'NN'.freeze
47
+ HEADER_FORMAT = 'c4N'.freeze
48
+ end
49
+
50
+ module Constants
51
+ TRUE_BYTE = "\x01".freeze
52
+ FALSE_BYTE = "\x00".freeze
53
+ PROTOCOL_VERSION = "\x01".freeze
54
+ COMPRESSION_OFF = "\x00".freeze
55
+ end
56
+ end
57
+ end
58
+
59
+ require 'cassandra/protocol/cql_byte_buffer'
60
+ require 'cassandra/protocol/type_converter'
61
+ require 'cassandra/protocol/response'
62
+ require 'cassandra/protocol/responses/auth_challenge_response'
63
+ require 'cassandra/protocol/responses/auth_success_response'
64
+ require 'cassandra/protocol/responses/error_response'
65
+ require 'cassandra/protocol/responses/detailed_error_response'
66
+ require 'cassandra/protocol/responses/ready_response'
67
+ require 'cassandra/protocol/responses/authenticate_response'
68
+ require 'cassandra/protocol/responses/supported_response'
69
+ require 'cassandra/protocol/responses/result_response'
70
+ require 'cassandra/protocol/responses/void_result_response'
71
+ require 'cassandra/protocol/responses/rows_result_response'
72
+ require 'cassandra/protocol/responses/raw_rows_result_response'
73
+ require 'cassandra/protocol/responses/set_keyspace_result_response'
74
+ require 'cassandra/protocol/responses/prepared_result_response'
75
+ require 'cassandra/protocol/responses/schema_change_result_response'
76
+ require 'cassandra/protocol/responses/event_response'
77
+ require 'cassandra/protocol/responses/schema_change_event_response'
78
+ require 'cassandra/protocol/responses/status_change_event_response'
79
+ require 'cassandra/protocol/responses/topology_change_event_response'
80
+ require 'cassandra/protocol/request'
81
+ require 'cassandra/protocol/requests/auth_response_request'
82
+ require 'cassandra/protocol/requests/batch_request'
83
+ require 'cassandra/protocol/requests/startup_request'
84
+ require 'cassandra/protocol/requests/credentials_request'
85
+ require 'cassandra/protocol/requests/options_request'
86
+ require 'cassandra/protocol/requests/register_request'
87
+ require 'cassandra/protocol/requests/query_request'
88
+ require 'cassandra/protocol/requests/void_query_request'
89
+ require 'cassandra/protocol/requests/prepare_request'
90
+ require 'cassandra/protocol/requests/execute_request'
91
+ require 'cassandra/protocol/frame_encoder'
92
+ require 'cassandra/protocol/frame_decoder'
93
+ require 'cassandra/protocol/cql_protocol_handler'
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ module Reconnection
21
+ module Policies
22
+ # A reconnection policy that returns a constant reconnection interval
23
+ class Constant < Policy
24
+ # @private
25
+ class Schedule
26
+ def initialize(interval)
27
+ @interval = interval
28
+ end
29
+
30
+ def next
31
+ @interval
32
+ end
33
+ end
34
+
35
+ # @param interval [Numeric] reconnection interval (in seconds)
36
+ def initialize(interval)
37
+ @schedule = Schedule.new(Float(interval))
38
+ end
39
+
40
+ # @return [Cassandra::Reconnection::Schedule] reconnection schedule
41
+ # with constant interval
42
+ def schedule
43
+ @schedule
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,79 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ module Reconnection
21
+ module Policies
22
+ # A reconnection policy that returns a constant exponentially growing
23
+ # reconnection interval up to a given maximum
24
+ class Exponential < Policy
25
+ # @private
26
+ class Schedule
27
+ def initialize(start, max, exponent)
28
+ @interval = start
29
+ @max = max
30
+ @exponent = exponent
31
+ end
32
+
33
+ def next
34
+ @interval.tap { backoff if @interval < @max }
35
+ end
36
+
37
+ private
38
+
39
+ def backoff
40
+ new_interval = @interval * @exponent
41
+
42
+ if new_interval >= @max
43
+ @interval = @max
44
+ else
45
+ @interval = new_interval
46
+ end
47
+ end
48
+ end
49
+
50
+ # @param start [Numeric] beginning interval
51
+ # @param max [Numeric] maximum reconnection interval
52
+ # @param exponent [Numeric] (2) interval exponent to use
53
+ #
54
+ # @example Using this policy
55
+ # policy = Cassandra::Reconnection::Policies::Exponential.new(0.5, 10, 2)
56
+ # schedule = policy.schedule
57
+ # schedule.next # 0.5
58
+ # schedule.next # 1.0
59
+ # schedule.next # 2.0
60
+ # schedule.next # 4.0
61
+ # schedule.next # 8.0
62
+ # schedule.next # 10.0
63
+ # schedule.next # 10.0
64
+ # schedule.next # 10.0
65
+ def initialize(start, max, exponent = 2)
66
+ @start = start
67
+ @max = max
68
+ @exponent = exponent
69
+ end
70
+
71
+ # @return [Cassandra::Reconnection::Schedule] an exponential
72
+ # reconnection schedule
73
+ def schedule
74
+ Schedule.new(@start, @max, @exponent)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ require 'cassandra/reconnection/policies/constant'
20
+ require 'cassandra/reconnection/policies/exponential'