couchbase-jruby-client 0.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +203 -0
  6. data/README.md +347 -0
  7. data/Rakefile +10 -0
  8. data/couchbase-jruby-client.gemspec +30 -0
  9. data/lib/couchbase/async/callback.rb +19 -0
  10. data/lib/couchbase/async/queue.rb +26 -0
  11. data/lib/couchbase/async.rb +139 -0
  12. data/lib/couchbase/bucket.rb +663 -0
  13. data/lib/couchbase/cluster.rb +105 -0
  14. data/lib/couchbase/constants.rb +12 -0
  15. data/lib/couchbase/error.rb +28 -0
  16. data/lib/couchbase/jruby/couchbase_client.rb +22 -0
  17. data/lib/couchbase/jruby/future.rb +8 -0
  18. data/lib/couchbase/operations/arithmetic.rb +301 -0
  19. data/lib/couchbase/operations/delete.rb +104 -0
  20. data/lib/couchbase/operations/get.rb +298 -0
  21. data/lib/couchbase/operations/stats.rb +16 -0
  22. data/lib/couchbase/operations/store.rb +468 -0
  23. data/lib/couchbase/operations/touch.rb +123 -0
  24. data/lib/couchbase/operations/utils.rb +49 -0
  25. data/lib/couchbase/operations.rb +23 -0
  26. data/lib/couchbase/result.rb +43 -0
  27. data/lib/couchbase/transcoder.rb +83 -0
  28. data/lib/couchbase/utils.rb +62 -0
  29. data/lib/couchbase/version.rb +3 -0
  30. data/lib/couchbase/view.rb +506 -0
  31. data/lib/couchbase/view_row.rb +272 -0
  32. data/lib/couchbase.rb +177 -0
  33. data/lib/jars/commons-codec-1.5.jar +0 -0
  34. data/lib/jars/couchbase-client-1.2.0-javadoc.jar +0 -0
  35. data/lib/jars/couchbase-client-1.2.0-sources.jar +0 -0
  36. data/lib/jars/couchbase-client-1.2.0.jar +0 -0
  37. data/lib/jars/httpcore-4.1.1.jar +0 -0
  38. data/lib/jars/httpcore-nio-4.1.1.jar +0 -0
  39. data/lib/jars/jettison-1.1.jar +0 -0
  40. data/lib/jars/netty-3.5.5.Final.jar +0 -0
  41. data/lib/jars/spymemcached-2.10.0-javadoc.jar +0 -0
  42. data/lib/jars/spymemcached-2.10.0-sources.jar +0 -0
  43. data/lib/jars/spymemcached-2.10.0.jar +0 -0
  44. data/test/profile/.gitignore +1 -0
  45. data/test/profile/Gemfile +6 -0
  46. data/test/profile/benchmark.rb +195 -0
  47. data/test/setup.rb +201 -0
  48. data/test/test_arithmetic.rb +177 -0
  49. data/test/test_async.rb +324 -0
  50. data/test/test_bucket.rb +213 -0
  51. data/test/test_cas.rb +78 -0
  52. data/test/test_couchbase.rb +29 -0
  53. data/test/test_couchbase_rails_cache_store.rb +341 -0
  54. data/test/test_delete.rb +125 -0
  55. data/test/test_errors.rb +82 -0
  56. data/test/test_format.rb +161 -0
  57. data/test/test_get.rb +417 -0
  58. data/test/test_stats.rb +57 -0
  59. data/test/test_store.rb +216 -0
  60. data/test/test_timer.rb +42 -0
  61. data/test/test_touch.rb +97 -0
  62. data/test/test_unlock.rb +119 -0
  63. data/test/test_utils.rb +58 -0
  64. data/test/test_version.rb +52 -0
  65. metadata +226 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad1a954f2653038b6e13351bd8130de1408ad422
4
+ data.tar.gz: e00809d731f61750b1dacce31ea0763d601a3375
5
+ SHA512:
6
+ metadata.gz: 3bc04936147969b1c4269c12c2eb56d83fe91c1141507e3ca442b6d435223059f6bb7c35707c1fbe2049085efd1598b15b265eaa5dfa9fc4becce3413801d02f
7
+ data.tar.gz: 887df622f19773b4868bc78b8c3dc5d83abbef541402db9b8087dcca7a4fc5d3928cb4cbf46397171ac7d27a7d618d9906269a91686e2df202a41e95aa5f81f7
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-1.7.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in couchbase-jruby-client.gemspec
4
+ gemspec
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,347 @@
1
+ # Couchbase::Jruby::Client
2
+
3
+ Attempt to recreate the ruby Couchbase cient 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.
23
+ Most of your typical operations such as connecting to a Couchbase cluster, storing
24
+ and retrieving documents are working, though I'm currently skeptical on the performance
25
+ compared to the native Java SDK without this wrapper.
26
+
27
+ ## Usage (Copied from )
28
+
29
+ First of all you need to load library:
30
+
31
+ require 'couchbase'
32
+
33
+ There are several ways to establish new connection to Couchbase Server.
34
+ By default it uses the `http://localhost:8091/pools/default/buckets/default`
35
+ as the endpoint. The client will automatically adjust configuration when
36
+ the cluster will rebalance its nodes when nodes are added or deleted
37
+ therefore this client is "smart".
38
+
39
+ c = Couchbase.connect
40
+
41
+ This is equivalent to following forms:
42
+
43
+ c = Couchbase.connect("http://localhost:8091/pools/default/buckets/default")
44
+ c = Couchbase.connect("http://localhost:8091/pools/default")
45
+ c = Couchbase.connect("http://localhost:8091")
46
+ c = Couchbase.connect(:hostname => "localhost")
47
+ c = Couchbase.connect(:hostname => "localhost", :port => 8091)
48
+ c = Couchbase.connect(:pool => "default", :bucket => "default")
49
+
50
+ The hash parameters take precedence on string URL.
51
+
52
+ If you worry about state of your nodes or not sure what node is alive,
53
+ you can pass the list of nodes and the library will iterate over it
54
+ until finds the working one. From that moment it won't use **your**
55
+ list, because node list from cluster config is more actual.
56
+
57
+ c = Couchbase.connect(:bucket => "mybucket",
58
+ :node_list => ['example.com:8091', example.net'])
59
+
60
+ There is also handy method `Couchbase.bucket` which uses thread local
61
+ storage to keep the reference to default connection. You can set the
62
+ connection options via `Couchbase.connection_options`:
63
+
64
+ Couchbase.connection_options = {:bucket => 'blog'}
65
+ Couchbase.bucket.name #=> "blog"
66
+ Couchbase.bucket.set("foo", "bar") #=> 3289400178357895424
67
+
68
+ The library supports both synchronous and asynchronous mode. In
69
+ asynchronous mode all operations will return control to caller
70
+ without blocking current thread. You can pass the block to method and it
71
+ will be called with result when the operation will be completed. You
72
+ need to run event loop when you scheduled your operations:
73
+
74
+ c = Couchbase.connect
75
+ c.run do |conn|
76
+ conn.get("foo") {|ret| puts ret.value}
77
+ conn.set("bar", "baz")
78
+ end
79
+
80
+ The handlers could be nested
81
+
82
+ c.run do |conn|
83
+ conn.get("foo") do |ret|
84
+ conn.incr(ret.value, :initial => 0)
85
+ end
86
+ end
87
+
88
+ The asynchronous callback receives instance of `Couchbase::Result` which
89
+ responds to several methods to figure out what was happened:
90
+
91
+ * `success?`. Returns `true` if operation succed.
92
+
93
+ * `error`. Returns `nil` or exception object (subclass of
94
+ `Couchbase::Error::Base`) if something went wrong.
95
+
96
+ * `key`
97
+
98
+ * `value`
99
+
100
+ * `flags`
101
+
102
+ * `cas`. The CAS version tag.
103
+
104
+ * `node`. Node address. It is used in flush and stats commands.
105
+
106
+ * `operation`. The symbol, representing an operation.
107
+
108
+
109
+ To handle global errors in async mode `#on_error` callback should be
110
+ used. It can be set in following fashions:
111
+
112
+ c.on_error do |opcode, key, exc|
113
+ # ...
114
+ end
115
+
116
+ handler = lambda {|opcode, key, exc| }
117
+ c.on_error = handler
118
+
119
+ By default connection uses `:quiet` mode. This mean it won't raise
120
+ exceptions when the given key is not exists:
121
+
122
+ c.get("missing-key") #=> nil
123
+
124
+ It could be useful when you are trying to make you code a bit efficient
125
+ by avoiding exception handling. (See `#add` and `#replace` operations).
126
+ You can turn on these exception by passing `:quiet => false` when you
127
+ are instantiating the connection or change corresponding attribute:
128
+
129
+ c.quiet = false
130
+ c.get("missing-key") #=> raise Couchbase::Error::NotFound
131
+ c.get("missing-key", :quiet => true) #=> nil
132
+
133
+ The library supports three different formats for representing values:
134
+
135
+ * `:document` (default) format supports most of ruby types which could
136
+ be mapped to JSON data (hashes, arrays, string, numbers). A future
137
+ version will be able to run map/reduce queries on the values in the
138
+ document form (hashes)
139
+
140
+ * `:plain` This format avoids any conversions to be applied to your
141
+ data, but your data should be passed as String. This is useful for
142
+ building custom algorithms or formats. For example to implement a set:
143
+ http://dustin.github.com/2011/02/17/memcached-set.html
144
+
145
+ * `:marshal` Use this format if you'd like to transparently serialize your
146
+ ruby object with standard `Marshal.dump` and `Marshal.load` methods
147
+
148
+ The couchbase API is the superset of [Memcached binary protocol][5], so
149
+ you can use its operations.
150
+
151
+ ### Get
152
+
153
+ val = c.get("foo")
154
+ val, flags, cas = c.get("foo", :extended => true)
155
+
156
+ Get and touch
157
+
158
+ val = c.get("foo", :ttl => 10)
159
+
160
+ Get multiple values. In quiet mode will put `nil` values on missing
161
+ positions:
162
+
163
+ vals = c.get("foo", "bar", "baz")
164
+ val_foo, val_bar, val_baz = c.get("foo", "bar", "baz")
165
+ c.run do
166
+ c.get("foo") do |ret|
167
+ ret.success?
168
+ ret.error
169
+ ret.key
170
+ ret.value
171
+ ret.flags
172
+ ret.cas
173
+ end
174
+ end
175
+
176
+ Get multiple values with extended information. The result will
177
+ represented by hash with tuples `[value, flags, cas]` as a value.
178
+
179
+ vals = c.get("foo", "bar", "baz", :extended => true)
180
+ vals.inspect #=> {"baz"=>["3", 0, 4784582192793125888],
181
+ "foo"=>["1", 0, 8835713818674332672],
182
+ "bar"=>["2", 0, 10805929834096100352]}
183
+
184
+ Hash-like syntax
185
+
186
+ c["foo"]
187
+ c["foo", "bar", "baz"]
188
+ c["foo", {:extended => true}]
189
+ c["foo", :extended => true] # for ruby 1.9.x only
190
+
191
+ ### Touch
192
+
193
+ c.touch("foo") # use :default_ttl
194
+ c.touch("foo", 10)
195
+ c.touch("foo", :ttl => 10)
196
+ c.touch("foo" => 10, "bar" => 20)
197
+ c.touch("foo" => 10, "bar" => 20){|key, success| }
198
+
199
+ ### Set
200
+
201
+ c.set("foo", "bar")
202
+ c.set("foo", "bar", :flags => 0x1000, :ttl => 30, :format => :plain)
203
+ c["foo"] = "bar"
204
+ c["foo", {:flags => 0x1000, :format => :plain}] = "bar"
205
+ c["foo", :flags => 0x1000] = "bar" # for ruby 1.9.x only
206
+ c.set("foo", "bar", :cas => 8835713818674332672)
207
+ c.set("foo", "bar"){|cas, key, operation| }
208
+
209
+ ### Add
210
+
211
+ Add command will fail if the key already exists. It accepts the same
212
+ options as set command above.
213
+
214
+ c.add("foo", "bar")
215
+ c.add("foo", "bar", :flags => 0x1000, :ttl => 30, :format => :plain)
216
+
217
+ ### Replace
218
+
219
+ The replace command will fail if the key already exists. It accepts the same
220
+ options as set command above.
221
+
222
+ c.replace("foo", "bar")
223
+
224
+ ### Prepend/Append
225
+
226
+ These commands are meaningful when you are using the `:plain` value format,
227
+ because the concatenation is performed by server which has no idea how
228
+ to merge to JSON values or values in ruby Marshal format. You may receive
229
+ an `Couchbase::Error::ValueFormat` error.
230
+
231
+ c.set("foo", "world")
232
+ c.append("foo", "!")
233
+ c.prepend("foo", "Hello, ")
234
+ c.get("foo") #=> "Hello, world!"
235
+
236
+ ### Increment/Decrement
237
+
238
+ These commands increment the value assigned to the key. It will raise
239
+ Couchbase::Error::DeltaBadval if the delta or value is not a number.
240
+
241
+ c.set("foo", 1)
242
+ c.incr("foo") #=> 2
243
+ c.incr("foo", :delta => 2) #=> 4
244
+ c.incr("foo", 4) #=> 8
245
+ c.incr("foo", -1) #=> 7
246
+ c.incr("foo", -100) #=> 0
247
+ c.run do
248
+ c.incr("foo") do |ret|
249
+ ret.success?
250
+ ret.value
251
+ ret.cas
252
+ end
253
+ end
254
+
255
+ c.set("foo", 10)
256
+ c.decr("foo", 1) #=> 9
257
+ c.decr("foo", 100) #=> 0
258
+ c.run do
259
+ c.decr("foo") do |ret|
260
+ ret.success?
261
+ ret.value
262
+ ret.cas
263
+ end
264
+ end
265
+
266
+ c.incr("missing1", :initial => 10) #=> 10
267
+ c.incr("missing1", :initial => 10) #=> 11
268
+ c.incr("missing2", :create => true) #=> 0
269
+ c.incr("missing2", :create => true) #=> 1
270
+
271
+ Note that it isn't the same as increment/decrement in ruby, which is
272
+ performed on client side with following `set` operation:
273
+
274
+ c["foo"] = 10
275
+ c["foo"] -= 20 #=> -10
276
+
277
+ ### Delete
278
+
279
+ c.delete("foo")
280
+ c.delete("foo", :cas => 8835713818674332672)
281
+ c.delete("foo", 8835713818674332672)
282
+ c.run do
283
+ c.delete do |ret|
284
+ ret.success?
285
+ ret.key
286
+ end
287
+ end
288
+
289
+ ### Flush
290
+
291
+ Flush the items in the cluster.
292
+
293
+ c.flush
294
+ c.run do
295
+ c.flush do |ret|
296
+ ret.success?
297
+ ret.node
298
+ end
299
+ end
300
+
301
+ ### Stats
302
+
303
+ Return statistics from each node in the cluster
304
+
305
+ c.stats
306
+ c.stats(:memory)
307
+ c.run do
308
+ c.stats do |ret|
309
+ ret.success?
310
+ ret.node
311
+ ret.key
312
+ ret.value
313
+ end
314
+ end
315
+
316
+ The result is represented as a hash with the server node address as
317
+ the key and stats as key-value pairs.
318
+
319
+ {
320
+ "threads"=>
321
+ {
322
+ "172.16.16.76:12008"=>"4",
323
+ "172.16.16.76:12000"=>"4",
324
+ # ...
325
+ },
326
+ "connection_structures"=>
327
+ {
328
+ "172.16.16.76:12008"=>"22",
329
+ "172.16.16.76:12000"=>"447",
330
+ # ...
331
+ },
332
+ "ep_max_txn_size"=>
333
+ {
334
+ "172.16.16.76:12008"=>"1000",
335
+ "172.16.16.76:12000"=>"1000",
336
+ # ...
337
+ },
338
+ # ...
339
+ }
340
+
341
+ ## Contributing
342
+
343
+ 1. Fork it
344
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
345
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
346
+ 4. Push to the branch (`git push origin my-new-feature`)
347
+ 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,30 @@
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 'active_support'
29
+ s.add_development_dependency 'pry'
30
+ 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