hot_bunnies 1.4.0.pre1-java → 1.4.0.pre2-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -115,7 +115,7 @@ module HotBunnies
115
115
 
116
116
  def setup_consumer(options, callback)
117
117
  if options.fetch(:blocking, true)
118
- @consumer = BlockingCallbackConsumer.new(@channel, callback)
118
+ @consumer = BlockingCallbackConsumer.new(@channel, options[:buffer_size], callback)
119
119
  else
120
120
  if options[:executor]
121
121
  @shut_down_executor = false
@@ -136,6 +136,7 @@ module HotBunnies
136
136
  @callback = callback
137
137
  @callback_arity = @callback.arity
138
138
  @cancelled = false
139
+ @cancelling = false
139
140
  end
140
141
 
141
142
  def handleDelivery(consumer_tag, envelope, properties, body)
@@ -157,6 +158,7 @@ module HotBunnies
157
158
 
158
159
  def cancel
159
160
  channel.basic_cancel(consumer_tag)
161
+ @cancelling = true
160
162
  end
161
163
 
162
164
  def deliver(headers, message)
@@ -176,24 +178,35 @@ module HotBunnies
176
178
  def initialize(channel, callback, executor)
177
179
  super(channel, callback)
178
180
  @executor = executor
181
+ @tasks = []
179
182
  end
180
183
 
181
184
  def deliver(headers, message)
182
- @executor.submit do
183
- callback(headers, message)
185
+ unless @executor.shutdown?
186
+ @executor.submit do
187
+ callback(headers, message)
188
+ end
184
189
  end
185
190
  end
186
191
  end
187
192
 
188
193
  class BlockingCallbackConsumer < CallbackConsumer
189
- def initialize(channel, callback)
194
+ import 'java.util.concurrent.LinkedBlockingQueue'
195
+ import 'java.util.concurrent.ArrayBlockingQueue'
196
+ import 'java.util.concurrent.TimeUnit'
197
+
198
+ def initialize(channel, buffer_size, callback)
190
199
  super(channel, callback)
191
- @internal_queue = java.util.concurrent.LinkedBlockingQueue.new
200
+ if buffer_size
201
+ @internal_queue = ArrayBlockingQueue.new(buffer_size)
202
+ else
203
+ @internal_queue = LinkedBlockingQueue.new
204
+ end
192
205
  end
193
206
 
194
207
  def start
195
208
  until @cancelled
196
- pair = @internal_queue.poll(1, java.util.concurrent.TimeUnit::SECONDS)
209
+ pair = @internal_queue.poll(1, TimeUnit::SECONDS)
197
210
  callback(*pair) if pair
198
211
  end
199
212
  while (pair = @internal_queue.poll)
@@ -202,7 +215,13 @@ module HotBunnies
202
215
  end
203
216
 
204
217
  def deliver(*pair)
205
- @internal_queue.add(pair)
218
+ if @cancelling || @cancelled
219
+ @internal_queue.offer(pair)
220
+ else
221
+ until @internal_queue.offer(pair, 1, TimeUnit::SECONDS)
222
+ break if @cancelling || @cancelled
223
+ end
224
+ end
206
225
  end
207
226
  end
208
227
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module HotBunnies
4
- VERSION = '1.4.0.pre1'
4
+ VERSION = '1.4.0.pre2'
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hot_bunnies
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.4.0.pre1
5
+ version: 1.4.0.pre2
6
6
  platform: java
7
7
  authors:
8
8
  - Theo Hultberg
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-06-25 00:00:00 Z
14
+ date: 2012-06-27 00:00:00 Z
15
15
  dependencies: []
16
16
 
17
17
  description: A object oriented interface to RabbitMQ that uses the Java driver under the hood