couchbase-jruby-client 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.jrubyrc +722 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +203 -0
  7. data/README.md +349 -0
  8. data/Rakefile +10 -0
  9. data/couchbase-jruby-client.gemspec +31 -0
  10. data/lib/couchbase/async/callback.rb +19 -0
  11. data/lib/couchbase/async/queue.rb +26 -0
  12. data/lib/couchbase/async.rb +140 -0
  13. data/lib/couchbase/bucket.rb +556 -0
  14. data/lib/couchbase/cluster.rb +105 -0
  15. data/lib/couchbase/constants.rb +12 -0
  16. data/lib/couchbase/design_doc.rb +61 -0
  17. data/lib/couchbase/error.rb +43 -0
  18. data/lib/couchbase/jruby/couchbase_client.rb +22 -0
  19. data/lib/couchbase/jruby/future.rb +8 -0
  20. data/lib/couchbase/operations/arithmetic.rb +301 -0
  21. data/lib/couchbase/operations/delete.rb +104 -0
  22. data/lib/couchbase/operations/design_docs.rb +99 -0
  23. data/lib/couchbase/operations/get.rb +282 -0
  24. data/lib/couchbase/operations/stats.rb +26 -0
  25. data/lib/couchbase/operations/store.rb +461 -0
  26. data/lib/couchbase/operations/touch.rb +136 -0
  27. data/lib/couchbase/operations/unlock.rb +192 -0
  28. data/lib/couchbase/operations/utils.rb +44 -0
  29. data/lib/couchbase/operations.rb +27 -0
  30. data/lib/couchbase/query.rb +73 -0
  31. data/lib/couchbase/result.rb +43 -0
  32. data/lib/couchbase/transcoder.rb +77 -0
  33. data/lib/couchbase/utils.rb +62 -0
  34. data/lib/couchbase/version.rb +3 -0
  35. data/lib/couchbase/view.rb +367 -0
  36. data/lib/couchbase/view_row.rb +193 -0
  37. data/lib/couchbase.rb +157 -0
  38. data/lib/jars/commons-codec-1.5.jar +0 -0
  39. data/lib/jars/couchbase-client-1.2.0-javadoc.jar +0 -0
  40. data/lib/jars/couchbase-client-1.2.0-sources.jar +0 -0
  41. data/lib/jars/couchbase-client-1.2.0.jar +0 -0
  42. data/lib/jars/httpcore-4.1.1.jar +0 -0
  43. data/lib/jars/httpcore-nio-4.1.1.jar +0 -0
  44. data/lib/jars/jettison-1.1.jar +0 -0
  45. data/lib/jars/netty-3.5.5.Final.jar +0 -0
  46. data/lib/jars/spymemcached-2.10.0-javadoc.jar +0 -0
  47. data/lib/jars/spymemcached-2.10.0-sources.jar +0 -0
  48. data/lib/jars/spymemcached-2.10.0.jar +0 -0
  49. data/test/profile/.gitignore +1 -0
  50. data/test/profile/.jrubyrc +722 -0
  51. data/test/profile/Gemfile +6 -0
  52. data/test/profile/benchmark.rb +168 -0
  53. data/test/profile/profile.rb +59 -0
  54. data/test/setup.rb +203 -0
  55. data/test/test_arithmetic.rb +177 -0
  56. data/test/test_async.rb +324 -0
  57. data/test/test_bucket.rb +213 -0
  58. data/test/test_cas.rb +79 -0
  59. data/test/test_couchbase.rb +29 -0
  60. data/test/test_couchbase_rails_cache_store.rb +341 -0
  61. data/test/test_delete.rb +125 -0
  62. data/test/test_design_docs.rb +72 -0
  63. data/test/test_errors.rb +82 -0
  64. data/test/test_format.rb +161 -0
  65. data/test/test_get.rb +417 -0
  66. data/test/test_query.rb +23 -0
  67. data/test/test_stats.rb +57 -0
  68. data/test/test_store.rb +213 -0
  69. data/test/test_timer.rb +43 -0
  70. data/test/test_touch.rb +97 -0
  71. data/test/test_unlock.rb +121 -0
  72. data/test/test_utils.rb +58 -0
  73. data/test/test_version.rb +53 -0
  74. data/test/test_view.rb +94 -0
  75. metadata +255 -0
data/LICENSE.txt ADDED
@@ -0,0 +1,203 @@
1
+ Copyright (c) 2013 Mike Evans
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright [yyyy] [name of copyright owner]
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,349 @@
1
+ # Couchbase JRuby Client
2
+
3
+ Attempt to recreate the ruby Couchbase client api in JRuby and the
4
+ Couchbase Java SDK.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'couchbase-jruby-client'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install couchbase-jruby-client
19
+
20
+ ## Caveat
21
+
22
+ Please consider this project a very incomplete "alpha" version at best. I'm getting close
23
+ to full coverage, though there are still some missing features. In fact, as I've gotten
24
+ more familiar with the differences between the native ruby api and the java, there are
25
+ definitely some features that don't make sense to implement.
26
+
27
+ Ultimately hoping to get to 100% support of the couchbase-ruby-model gem.
28
+
29
+ ## Usage (Copied from couchbase-ruby-client)
30
+
31
+ First of all you need to load library:
32
+
33
+ require 'couchbase'
34
+
35
+ There are several ways to establish new connection to Couchbase Server.
36
+ By default it uses the `http://localhost:8091/pools/default/buckets/default`
37
+ as the endpoint. The client will automatically adjust configuration when
38
+ the cluster will rebalance its nodes when nodes are added or deleted
39
+ therefore this client is "smart".
40
+
41
+ c = Couchbase.connect
42
+
43
+ This is equivalent to following forms:
44
+
45
+ c = Couchbase.connect("http://localhost:8091/pools/default/buckets/default")
46
+ c = Couchbase.connect("http://localhost:8091/pools/default")
47
+ c = Couchbase.connect("http://localhost:8091")
48
+ c = Couchbase.connect(:hostname => "localhost")
49
+ c = Couchbase.connect(:hostname => "localhost", :port => 8091)
50
+ c = Couchbase.connect(:pool => "default", :bucket => "default")
51
+
52
+ The hash parameters take precedence on string URL.
53
+
54
+ If you worry about state of your nodes or not sure what node is alive,
55
+ you can pass the list of nodes and the library will iterate over it
56
+ until finds the working one. From that moment it won't use **your**
57
+ list, because node list from cluster config is more actual.
58
+
59
+ c = Couchbase.connect(:bucket => "mybucket",
60
+ :node_list => ['example.com:8091', example.net'])
61
+
62
+ There is also handy method `Couchbase.bucket` which uses thread local
63
+ storage to keep the reference to default connection. You can set the
64
+ connection options via `Couchbase.connection_options`:
65
+
66
+ Couchbase.connection_options = {:bucket => 'blog'}
67
+ Couchbase.bucket.name #=> "blog"
68
+ Couchbase.bucket.set("foo", "bar") #=> 3289400178357895424
69
+
70
+ The library supports both synchronous and asynchronous mode. In
71
+ asynchronous mode all operations will return control to caller
72
+ without blocking current thread. You can pass the block to method and it
73
+ will be called with result when the operation will be completed. You
74
+ need to run event loop when you scheduled your operations:
75
+
76
+ c = Couchbase.connect
77
+ c.run do |conn|
78
+ conn.get("foo") {|ret| puts ret.value}
79
+ conn.set("bar", "baz")
80
+ end
81
+
82
+ The handlers could be nested
83
+
84
+ c.run do |conn|
85
+ conn.get("foo") do |ret|
86
+ conn.incr(ret.value, :initial => 0)
87
+ end
88
+ end
89
+
90
+ The asynchronous callback receives instance of `Couchbase::Result` which
91
+ responds to several methods to figure out what was happened:
92
+
93
+ * `success?`. Returns `true` if operation succed.
94
+
95
+ * `error`. Returns `nil` or exception object (subclass of
96
+ `Couchbase::Error::Base`) if something went wrong.
97
+
98
+ * `key`
99
+
100
+ * `value`
101
+
102
+ * `flags`
103
+
104
+ * `cas`. The CAS version tag.
105
+
106
+ * `node`. Node address. It is used in flush and stats commands.
107
+
108
+ * `operation`. The symbol, representing an operation.
109
+
110
+
111
+ To handle global errors in async mode `#on_error` callback should be
112
+ used. It can be set in following fashions:
113
+
114
+ c.on_error do |opcode, key, exc|
115
+ # ...
116
+ end
117
+
118
+ handler = lambda {|opcode, key, exc| }
119
+ c.on_error = handler
120
+
121
+ By default connection uses `:quiet` mode. This mean it won't raise
122
+ exceptions when the given key is not exists:
123
+
124
+ c.get("missing-key") #=> nil
125
+
126
+ It could be useful when you are trying to make you code a bit efficient
127
+ by avoiding exception handling. (See `#add` and `#replace` operations).
128
+ You can turn on these exception by passing `:quiet => false` when you
129
+ are instantiating the connection or change corresponding attribute:
130
+
131
+ c.quiet = false
132
+ c.get("missing-key") #=> raise Couchbase::Error::NotFound
133
+ c.get("missing-key", :quiet => true) #=> nil
134
+
135
+ The library supports three different formats for representing values:
136
+
137
+ * `:document` (default) format supports most of ruby types which could
138
+ be mapped to JSON data (hashes, arrays, string, numbers). A future
139
+ version will be able to run map/reduce queries on the values in the
140
+ document form (hashes)
141
+
142
+ * `:plain` This format avoids any conversions to be applied to your
143
+ data, but your data should be passed as String. This is useful for
144
+ building custom algorithms or formats. For example to implement a set:
145
+ http://dustin.github.com/2011/02/17/memcached-set.html
146
+
147
+ * `:marshal` Use this format if you'd like to transparently serialize your
148
+ ruby object with standard `Marshal.dump` and `Marshal.load` methods
149
+
150
+ The couchbase API is the superset of [Memcached binary protocol][5], so
151
+ you can use its operations.
152
+
153
+ ### Get
154
+
155
+ val = c.get("foo")
156
+ val, flags, cas = c.get("foo", :extended => true)
157
+
158
+ Get and touch
159
+
160
+ val = c.get("foo", :ttl => 10)
161
+
162
+ Get multiple values. In quiet mode will put `nil` values on missing
163
+ positions:
164
+
165
+ vals = c.get("foo", "bar", "baz")
166
+ val_foo, val_bar, val_baz = c.get("foo", "bar", "baz")
167
+ c.run do
168
+ c.get("foo") do |ret|
169
+ ret.success?
170
+ ret.error
171
+ ret.key
172
+ ret.value
173
+ ret.flags
174
+ ret.cas
175
+ end
176
+ end
177
+
178
+ Get multiple values with extended information. The result will
179
+ represented by hash with tuples `[value, flags, cas]` as a value.
180
+
181
+ vals = c.get("foo", "bar", "baz", :extended => true)
182
+ vals.inspect #=> {"baz"=>["3", 0, 4784582192793125888],
183
+ "foo"=>["1", 0, 8835713818674332672],
184
+ "bar"=>["2", 0, 10805929834096100352]}
185
+
186
+ Hash-like syntax
187
+
188
+ c["foo"]
189
+ c["foo", "bar", "baz"]
190
+ c["foo", {:extended => true}]
191
+ c["foo", :extended => true] # for ruby 1.9.x only
192
+
193
+ ### Touch
194
+
195
+ c.touch("foo") # use :default_ttl
196
+ c.touch("foo", 10)
197
+ c.touch("foo", :ttl => 10)
198
+ c.touch("foo" => 10, "bar" => 20)
199
+ c.touch("foo" => 10, "bar" => 20){|key, success| }
200
+
201
+ ### Set
202
+
203
+ c.set("foo", "bar")
204
+ c.set("foo", "bar", :flags => 0x1000, :ttl => 30, :format => :plain)
205
+ c["foo"] = "bar"
206
+ c["foo", {:flags => 0x1000, :format => :plain}] = "bar"
207
+ c["foo", :flags => 0x1000] = "bar" # for ruby 1.9.x only
208
+ c.set("foo", "bar", :cas => 8835713818674332672)
209
+ c.set("foo", "bar"){|cas, key, operation| }
210
+
211
+ ### Add
212
+
213
+ Add command will fail if the key already exists. It accepts the same
214
+ options as set command above.
215
+
216
+ c.add("foo", "bar")
217
+ c.add("foo", "bar", :flags => 0x1000, :ttl => 30, :format => :plain)
218
+
219
+ ### Replace
220
+
221
+ The replace command will fail if the key already exists. It accepts the same
222
+ options as set command above.
223
+
224
+ c.replace("foo", "bar")
225
+
226
+ ### Prepend/Append
227
+
228
+ These commands are meaningful when you are using the `:plain` value format,
229
+ because the concatenation is performed by server which has no idea how
230
+ to merge to JSON values or values in ruby Marshal format. You may receive
231
+ an `Couchbase::Error::ValueFormat` error.
232
+
233
+ c.set("foo", "world")
234
+ c.append("foo", "!")
235
+ c.prepend("foo", "Hello, ")
236
+ c.get("foo") #=> "Hello, world!"
237
+
238
+ ### Increment/Decrement
239
+
240
+ These commands increment the value assigned to the key. It will raise
241
+ Couchbase::Error::DeltaBadval if the delta or value is not a number.
242
+
243
+ c.set("foo", 1)
244
+ c.incr("foo") #=> 2
245
+ c.incr("foo", :delta => 2) #=> 4
246
+ c.incr("foo", 4) #=> 8
247
+ c.incr("foo", -1) #=> 7
248
+ c.incr("foo", -100) #=> 0
249
+ c.run do
250
+ c.incr("foo") do |ret|
251
+ ret.success?
252
+ ret.value
253
+ ret.cas
254
+ end
255
+ end
256
+
257
+ c.set("foo", 10)
258
+ c.decr("foo", 1) #=> 9
259
+ c.decr("foo", 100) #=> 0
260
+ c.run do
261
+ c.decr("foo") do |ret|
262
+ ret.success?
263
+ ret.value
264
+ ret.cas
265
+ end
266
+ end
267
+
268
+ c.incr("missing1", :initial => 10) #=> 10
269
+ c.incr("missing1", :initial => 10) #=> 11
270
+ c.incr("missing2", :create => true) #=> 0
271
+ c.incr("missing2", :create => true) #=> 1
272
+
273
+ Note that it isn't the same as increment/decrement in ruby, which is
274
+ performed on client side with following `set` operation:
275
+
276
+ c["foo"] = 10
277
+ c["foo"] -= 20 #=> -10
278
+
279
+ ### Delete
280
+
281
+ c.delete("foo")
282
+ c.delete("foo", :cas => 8835713818674332672)
283
+ c.delete("foo", 8835713818674332672)
284
+ c.run do
285
+ c.delete do |ret|
286
+ ret.success?
287
+ ret.key
288
+ end
289
+ end
290
+
291
+ ### Flush
292
+
293
+ Flush the items in the cluster.
294
+
295
+ c.flush
296
+ c.run do
297
+ c.flush do |ret|
298
+ ret.success?
299
+ ret.node
300
+ end
301
+ end
302
+
303
+ ### Stats
304
+
305
+ Return statistics from each node in the cluster
306
+
307
+ c.stats
308
+ c.stats(:memory)
309
+ c.run do
310
+ c.stats do |ret|
311
+ ret.success?
312
+ ret.node
313
+ ret.key
314
+ ret.value
315
+ end
316
+ end
317
+
318
+ The result is represented as a hash with the server node address as
319
+ the key and stats as key-value pairs.
320
+
321
+ {
322
+ "threads"=>
323
+ {
324
+ "172.16.16.76:12008"=>"4",
325
+ "172.16.16.76:12000"=>"4",
326
+ # ...
327
+ },
328
+ "connection_structures"=>
329
+ {
330
+ "172.16.16.76:12008"=>"22",
331
+ "172.16.16.76:12000"=>"447",
332
+ # ...
333
+ },
334
+ "ep_max_txn_size"=>
335
+ {
336
+ "172.16.16.76:12008"=>"1000",
337
+ "172.16.16.76:12000"=>"1000",
338
+ # ...
339
+ },
340
+ # ...
341
+ }
342
+
343
+ ## Contributing
344
+
345
+ 1. Fork it
346
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
347
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
348
+ 4. Push to the branch (`git push origin my-new-feature`)
349
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'couchbase/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'couchbase-jruby-client'
8
+ s.version = Couchbase::VERSION
9
+ s.authors = ['Mike Evans']
10
+ s.email = ['mike@urlgonomics.com']
11
+ s.description = %q{Couchbase JRuby driver}
12
+ s.summary = %q{The unofficial jruby client library for use with Couchbase Server.}
13
+ s.homepage = 'https://github.com/mje113/couchbase-jruby-client'
14
+ s.license = 'Apache'
15
+ #s.platform = Gem::Platform::JAVA
16
+
17
+ s.files = `git ls-files`.split($/)
18
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
+ s.require_paths = ['lib']
21
+
22
+ s.add_runtime_dependency 'multi_json', '~> 1.0'
23
+ s.add_runtime_dependency 'atomic', '~> 1.1.14'
24
+
25
+ s.add_development_dependency 'bundler', '~> 1.3'
26
+ s.add_development_dependency 'rake'
27
+ s.add_development_dependency 'minitest', '~> 5.0.4'
28
+ s.add_development_dependency 'jrjackson', '~> 0.2.3'
29
+ s.add_development_dependency 'active_support'
30
+ s.add_development_dependency 'pry'
31
+ end
@@ -0,0 +1,19 @@
1
+ module Couchbase
2
+ module Async
3
+ class Callback
4
+ include Java::NetSpyMemcachedInternal::OperationCompletionListener
5
+
6
+ def initialize(operation, &callback)
7
+ @operation, @callback = operation, callback
8
+ end
9
+
10
+ def onComplete(future)
11
+ result = Couchbase::Result.new(operation: @operation, future: future)
12
+ @callback.call(result)
13
+ rescue Exception => e
14
+ result.error = e
15
+ return result
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ module Couchbase
2
+ module Async
3
+ class Queue
4
+
5
+ def initialize(bucket)
6
+ @bucket = bucket
7
+ @futures = []
8
+ end
9
+
10
+ def add_future(future, options, &block)
11
+ @futures << [ future, options, block ]
12
+ end
13
+
14
+ def join
15
+ while future = @futures.pop
16
+ begin
17
+ future, options, callback = future
18
+ future.get
19
+ result = Couchbase::Result.new({ bucket: @bucket, future: future }.merge(options))
20
+ callback.call(result) unless callback.nil?
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end