hot_bunnies 2.0.0.pre1-java → 2.0.0.pre2-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,6 +21,22 @@ module HotBunnies
21
21
 
22
22
  def handleCancel(consumer_tag)
23
23
  @cancelled.set(true)
24
+ @channel.unregister_consumer(consumer_tag)
25
+
26
+ if f = @opts[:on_cancellation]
27
+ case f.arity
28
+ when 0 then
29
+ f.call
30
+ when 1 then
31
+ f.call(self)
32
+ when 2 then
33
+ f.call(@channel, self)
34
+ when 3 then
35
+ f.call(@channel, self, consumer_tag)
36
+ else
37
+ f.call(@channel, self, consumer_tag)
38
+ end
39
+ end
24
40
  end
25
41
 
26
42
  def handleCancelOk(consumer_tag)
@@ -70,9 +86,10 @@ module HotBunnies
70
86
  end
71
87
 
72
88
  class AsyncCallbackConsumer < CallbackConsumer
73
- def initialize(channel, callback, executor)
89
+ def initialize(channel, opts, callback, executor)
74
90
  super(channel, callback)
75
91
  @executor = executor
92
+ @opts = opts
76
93
  end
77
94
 
78
95
  def deliver(headers, message)
@@ -90,7 +107,13 @@ module HotBunnies
90
107
  def cancel
91
108
  super
92
109
 
93
- maybe_shut_down_executor
110
+ gracefully_shutdown
111
+ end
112
+
113
+ def handleCancel(consumer_tag)
114
+ super(consumer_tag)
115
+
116
+ gracefully_shutdown
94
117
  end
95
118
 
96
119
  def shutdown!
@@ -100,6 +123,7 @@ module HotBunnies
100
123
 
101
124
  def gracefully_shut_down
102
125
  unless @executor.await_termination(1, JavaConcurrent::TimeUnit::SECONDS)
126
+ puts "Shutting down the executor.."
103
127
  @executor.shutdown_now
104
128
  end
105
129
  end
@@ -110,13 +134,15 @@ module HotBunnies
110
134
  class BlockingCallbackConsumer < CallbackConsumer
111
135
  include JavaConcurrent
112
136
 
113
- def initialize(channel, buffer_size, callback)
137
+ def initialize(channel, buffer_size, opts, callback)
114
138
  super(channel, callback)
115
139
  if buffer_size
116
140
  @internal_queue = ArrayBlockingQueue.new(buffer_size)
117
141
  else
118
142
  @internal_queue = LinkedBlockingQueue.new
119
143
  end
144
+
145
+ @opts = opts
120
146
  end
121
147
 
122
148
  def start
@@ -49,9 +49,9 @@ module HotBunnies
49
49
 
50
50
  def subscribe(opts = {}, &block)
51
51
  consumer = if opts[:block] || opts[:blocking]
52
- BlockingCallbackConsumer.new(@channel, opts[:buffer_size], block)
52
+ BlockingCallbackConsumer.new(@channel, opts[:buffer_size], opts, block)
53
53
  else
54
- AsyncCallbackConsumer.new(@channel, block, opts.fetch(:executor, JavaConcurrent::Executors.new_single_thread_executor))
54
+ AsyncCallbackConsumer.new(@channel, opts, block, opts.fetch(:executor, JavaConcurrent::Executors.new_single_thread_executor))
55
55
  end
56
56
 
57
57
  @consumer_tag = @channel.basic_consume(@name, !(opts[:ack] || opts[:manual_ack]), consumer)
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module HotBunnies
4
- VERSION = '2.0.0.pre1'
4
+ VERSION = "2.0.0.pre2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hot_bunnies
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre1
4
+ version: 2.0.0.pre2
5
5
  prerelease: 6
6
6
  platform: java
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-29 00:00:00.000000000 Z
13
+ date: 2013-05-31 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: RabbitMQ client for JRuby built around the official RabbitMQ Java client
16
16
  email: