hot_bunnies 2.0.0.pre12-java → 2.0.0.pre13-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -118,10 +118,9 @@ module HotBunnies
118
118
  attr_reader :consumers
119
119
 
120
120
  # @private
121
- def initialize(session, delegate, thread_pool)
121
+ def initialize(session, delegate)
122
122
  @connection = session
123
123
  @delegate = delegate
124
- @thread_pool = thread_pool
125
124
 
126
125
  @exchanges = JavaConcurrent::ConcurrentHashMap.new
127
126
  @queues = JavaConcurrent::ConcurrentHashMap.new
@@ -403,7 +402,7 @@ module HotBunnies
403
402
  # @see http://hotbunnies.info/articles/queues.html Queues and Consumers guide
404
403
  # @see http://hotbunnies.info/articles/extensions.html RabbitMQ Extensions guide
405
404
  def queue(name, options={})
406
- dq = Queue.new(self, name, @thread_pool, options).tap do |q|
405
+ dq = Queue.new(self, name, options).tap do |q|
407
406
  q.declare!
408
407
  end
409
408
 
@@ -1,4 +1,2 @@
1
- require "hot_bunnies/thread_pools"
2
-
3
1
  require "hot_bunnies/consumers/base"
4
2
  require "hot_bunnies/consumers/blocking"
@@ -28,10 +28,9 @@ module HotBunnies
28
28
  # @see HotBunnies::Channel#queue
29
29
  # @see http://hotbunnies.info/articles/queues.html Queues and Consumers guide
30
30
  # @see http://hotbunnies.info/articles/extensions.html RabbitMQ Extensions guide
31
- def initialize(channel, name, thread_pool, options={})
31
+ def initialize(channel, name, options={})
32
32
  @channel = channel
33
33
  @name = name
34
- @thread_pool = thread_pool
35
34
  @options = {:durable => false, :exclusive => false, :auto_delete => false, :passive => false, :arguments => Hash.new}.merge(options)
36
35
 
37
36
  @durable = @options[:durable]
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "hot_bunnies/shutdown_listener"
3
3
  require "set"
4
+ require "hot_bunnies/thread_pools"
4
5
 
5
6
  module HotBunnies
6
7
  java_import com.rabbitmq.client.ConnectionFactory
@@ -73,13 +74,10 @@ module HotBunnies
73
74
 
74
75
  # @private
75
76
  def initialize(connection_factory, opts = {})
76
- @cf = connection_factory
77
+ @cf = connection_factory
77
78
  @executor_factory = opts[:executor_factory]
78
- @connection = converting_rjc_exceptions_to_ruby do
79
- self.new_connection
80
- end
81
- @channels = JavaConcurrent::ConcurrentHashMap.new
82
- @thread_pool = ThreadPools.dynamically_growing
79
+ @connection = self.new_connection
80
+ @channels = JavaConcurrent::ConcurrentHashMap.new
83
81
 
84
82
  # should automatic recovery from network failures be used?
85
83
  @automatically_recover = if opts[:automatically_recover].nil? && opts[:automatic_recovery].nil?
@@ -110,7 +108,7 @@ module HotBunnies
110
108
  @connection.create_channel
111
109
  end
112
110
 
113
- ch = Channel.new(self, jc, @thread_pool)
111
+ ch = Channel.new(self, jc)
114
112
  register_channel(ch)
115
113
 
116
114
  ch
@@ -126,11 +124,6 @@ module HotBunnies
126
124
  ch.close
127
125
  end
128
126
 
129
- @thread_pool.shutdown
130
- unless @thread_pool.await_termination(5, JavaConcurrent::TimeUnit::SECONDS)
131
- @thread_pool.shutdown_now
132
- end
133
-
134
127
  @connection.close
135
128
  end
136
129
 
@@ -171,11 +164,14 @@ module HotBunnies
171
164
  # Begins automatic connection recovery (typically only used internally
172
165
  # to recover from network failures)
173
166
  def automatically_recover
167
+ ms = @network_recovery_interval * 1000
174
168
  # recovering immediately makes little sense. Wait a bit first. MK.
175
- java.lang.Thread.sleep(@network_recovery_interval * 1000)
169
+ java.lang.Thread.sleep(ms)
176
170
 
177
171
  @connection = converting_rjc_exceptions_to_ruby do
178
- self.new_connection
172
+ reconnecting_on_network_failures(ms) do
173
+ self.new_connection
174
+ end
179
175
  end
180
176
  @thread_pool = ThreadPools.dynamically_growing
181
177
  self.recover_shutdown_hooks
@@ -326,12 +322,22 @@ module HotBunnies
326
322
  end
327
323
  end
328
324
 
325
+ # @private
326
+ def reconnecting_on_network_failures(interval_in_ms, &fn)
327
+ begin
328
+ fn.call
329
+ rescue IOError, HotBunnies::ConnectionRefused, java.io.IOException => e
330
+ java.lang.Thread.sleep(interval_in_ms)
331
+
332
+ retry
333
+ end
334
+ end
335
+
329
336
  # @private
330
337
  def new_connection
331
338
  converting_rjc_exceptions_to_ruby do
332
339
  if @executor_factory
333
- ex = @executor_factory.call
334
- @cf.new_connection(ex)
340
+ @cf.new_connection(@executor_factory.call)
335
341
  else
336
342
  @cf.new_connection
337
343
  end
@@ -1,3 +1,5 @@
1
+ require "hot_bunnies/juc"
2
+
1
3
  module HotBunnies
2
4
  # A slighly more Ruby developer-friendly way of instantiating various
3
5
  # JDK executors (thread pools).
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module HotBunnies
4
- VERSION = "2.0.0.pre12"
4
+ VERSION = "2.0.0.pre13"
5
5
  end
data/lib/hot_bunnies.rb CHANGED
@@ -6,7 +6,6 @@ require 'ext/rabbitmq-client'
6
6
 
7
7
  require 'hot_bunnies/version'
8
8
  require 'hot_bunnies/exceptions'
9
- require 'hot_bunnies/thread_pools'
10
9
  require 'hot_bunnies/session'
11
10
 
12
11
  # HotBunnies is a JRuby client for RabbitMQ built on top of the official Java client.
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.pre12
4
+ version: 2.0.0.pre13
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-08-27 00:00:00.000000000 Z
13
+ date: 2013-09-02 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: