couchbase-jruby-client 0.1.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +203 -0
- data/README.md +347 -0
- data/Rakefile +10 -0
- data/couchbase-jruby-client.gemspec +30 -0
- data/lib/couchbase/async/callback.rb +19 -0
- data/lib/couchbase/async/queue.rb +26 -0
- data/lib/couchbase/async.rb +139 -0
- data/lib/couchbase/bucket.rb +663 -0
- data/lib/couchbase/cluster.rb +105 -0
- data/lib/couchbase/constants.rb +12 -0
- data/lib/couchbase/error.rb +28 -0
- data/lib/couchbase/jruby/couchbase_client.rb +22 -0
- data/lib/couchbase/jruby/future.rb +8 -0
- data/lib/couchbase/operations/arithmetic.rb +301 -0
- data/lib/couchbase/operations/delete.rb +104 -0
- data/lib/couchbase/operations/get.rb +298 -0
- data/lib/couchbase/operations/stats.rb +16 -0
- data/lib/couchbase/operations/store.rb +468 -0
- data/lib/couchbase/operations/touch.rb +123 -0
- data/lib/couchbase/operations/utils.rb +49 -0
- data/lib/couchbase/operations.rb +23 -0
- data/lib/couchbase/result.rb +43 -0
- data/lib/couchbase/transcoder.rb +83 -0
- data/lib/couchbase/utils.rb +62 -0
- data/lib/couchbase/version.rb +3 -0
- data/lib/couchbase/view.rb +506 -0
- data/lib/couchbase/view_row.rb +272 -0
- data/lib/couchbase.rb +177 -0
- data/lib/jars/commons-codec-1.5.jar +0 -0
- data/lib/jars/couchbase-client-1.2.0-javadoc.jar +0 -0
- data/lib/jars/couchbase-client-1.2.0-sources.jar +0 -0
- data/lib/jars/couchbase-client-1.2.0.jar +0 -0
- data/lib/jars/httpcore-4.1.1.jar +0 -0
- data/lib/jars/httpcore-nio-4.1.1.jar +0 -0
- data/lib/jars/jettison-1.1.jar +0 -0
- data/lib/jars/netty-3.5.5.Final.jar +0 -0
- data/lib/jars/spymemcached-2.10.0-javadoc.jar +0 -0
- data/lib/jars/spymemcached-2.10.0-sources.jar +0 -0
- data/lib/jars/spymemcached-2.10.0.jar +0 -0
- data/test/profile/.gitignore +1 -0
- data/test/profile/Gemfile +6 -0
- data/test/profile/benchmark.rb +195 -0
- data/test/setup.rb +201 -0
- data/test/test_arithmetic.rb +177 -0
- data/test/test_async.rb +324 -0
- data/test/test_bucket.rb +213 -0
- data/test/test_cas.rb +78 -0
- data/test/test_couchbase.rb +29 -0
- data/test/test_couchbase_rails_cache_store.rb +341 -0
- data/test/test_delete.rb +125 -0
- data/test/test_errors.rb +82 -0
- data/test/test_format.rb +161 -0
- data/test/test_get.rb +417 -0
- data/test/test_stats.rb +57 -0
- data/test/test_store.rb +216 -0
- data/test/test_timer.rb +42 -0
- data/test/test_touch.rb +97 -0
- data/test/test_unlock.rb +119 -0
- data/test/test_utils.rb +58 -0
- data/test/test_version.rb +52 -0
- metadata +226 -0
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'couchbase/async/callback'
|
2
|
+
require 'couchbase/async/queue'
|
3
|
+
|
4
|
+
module Couchbase
|
5
|
+
module Async
|
6
|
+
|
7
|
+
def async?
|
8
|
+
!!async
|
9
|
+
end
|
10
|
+
|
11
|
+
def async
|
12
|
+
Thread.current[:bucket_async] ||= @async
|
13
|
+
end
|
14
|
+
|
15
|
+
def async=(val)
|
16
|
+
Thread.current[:bucket_async] = val
|
17
|
+
end
|
18
|
+
|
19
|
+
def running?
|
20
|
+
!!running
|
21
|
+
end
|
22
|
+
|
23
|
+
def running
|
24
|
+
Thread.current[:bucket_running] ||= false
|
25
|
+
end
|
26
|
+
|
27
|
+
def running=(val)
|
28
|
+
Thread.current[:bucket_running] = val
|
29
|
+
end
|
30
|
+
|
31
|
+
def async_queue
|
32
|
+
Thread.current[:bucket_async_queue] ||= Couchbase::Async::Queue.new(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
def end_async_queue
|
36
|
+
Thread.current[:bucket_async_queue] = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
public
|
40
|
+
|
41
|
+
# Run the event loop.
|
42
|
+
#
|
43
|
+
# @since 1.0.0
|
44
|
+
#
|
45
|
+
# @param [Hash] options The options for operation for connection
|
46
|
+
# @option options [Fixnum] :send_threshold (0) if the internal command
|
47
|
+
# buffer will exceeds this value, then the library will start network
|
48
|
+
# interaction and block the current thread until all scheduled commands
|
49
|
+
# will be completed.
|
50
|
+
#
|
51
|
+
# @yieldparam [Bucket] bucket the bucket instance
|
52
|
+
#
|
53
|
+
# @example Use block to run the loop
|
54
|
+
# c = Couchbase.new
|
55
|
+
# c.run do
|
56
|
+
# c.get("foo") {|ret| puts ret.value}
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# @example Use lambda to run the loop
|
60
|
+
# c = Couchbase.new
|
61
|
+
# operations = lambda do |c|
|
62
|
+
# c.get("foo") {|ret| puts ret.value}
|
63
|
+
# end
|
64
|
+
# c.run(&operations)
|
65
|
+
#
|
66
|
+
# @example Use threshold to send out commands automatically
|
67
|
+
# c = Couchbase.connect
|
68
|
+
# sent = 0
|
69
|
+
# c.run(:send_threshold => 8192) do # 8Kb
|
70
|
+
# c.set("foo1", "x" * 100) {|r| sent += 1}
|
71
|
+
# # 128 bytes buffered, sent is 0 now
|
72
|
+
# c.set("foo2", "x" * 10000) {|r| sent += 1}
|
73
|
+
# # 10028 bytes added, sent is 2 now
|
74
|
+
# c.set("foo3", "x" * 100) {|r| sent += 1}
|
75
|
+
# end
|
76
|
+
# # all commands were executed and sent is 3 now
|
77
|
+
#
|
78
|
+
# @example Use {Couchbase::Bucket#run} without block for async connection
|
79
|
+
# c = Couchbase.new(:async => true)
|
80
|
+
# c.run # ensure that instance connected
|
81
|
+
# c.set("foo", "bar"){|r| puts r.cas}
|
82
|
+
# c.run
|
83
|
+
#
|
84
|
+
# @return [nil]
|
85
|
+
#
|
86
|
+
# @raise [Couchbase::Error::Connect] if connection closed (see {Bucket#reconnect})
|
87
|
+
#
|
88
|
+
def run(options = {})
|
89
|
+
do_async_setup(block_given?)
|
90
|
+
yield(self)
|
91
|
+
async_queue.join
|
92
|
+
|
93
|
+
# TODO: deal with exceptions
|
94
|
+
nil
|
95
|
+
ensure
|
96
|
+
do_async_ensure
|
97
|
+
end
|
98
|
+
|
99
|
+
def run_async(options = {})
|
100
|
+
do_async_setup(block_given?)
|
101
|
+
yield(self)
|
102
|
+
nil
|
103
|
+
ensure
|
104
|
+
do_async_ensure
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def do_async_setup(block_given)
|
110
|
+
raise LocalJumpError.new('block required for async run') unless block_given
|
111
|
+
# TODO: check for connection
|
112
|
+
raise Error::Invalid.new('nested #run') if running?
|
113
|
+
# TOOD: deal with thresholds
|
114
|
+
|
115
|
+
self.async = true
|
116
|
+
self.running = true
|
117
|
+
end
|
118
|
+
|
119
|
+
def do_async_ensure
|
120
|
+
self.async = false
|
121
|
+
self.running = false
|
122
|
+
end_async_queue
|
123
|
+
end
|
124
|
+
|
125
|
+
def register_future(future, options, &block)
|
126
|
+
if async_queue
|
127
|
+
async_queue.add_future(future, options, &block)
|
128
|
+
else
|
129
|
+
register_callback(future, &block)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def register_callback(future, &block)
|
134
|
+
callback = Couchbase::Callback.new(:set, &block)
|
135
|
+
future.addListener(callback)
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
end
|