krakow 0.3.6 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c4b142c9d4c137f48a3f4c863185346d6111e37
4
- data.tar.gz: 56732c8b17e13d4e9d0b77880ac6658642e8cac6
3
+ metadata.gz: 58808267d1e6b93d05a47f6c3a1caaf0f7199e32
4
+ data.tar.gz: c8f9d22593eae52540d0b5aa66ef2f4f58b33312
5
5
  SHA512:
6
- metadata.gz: c8eff9207bbb250463f617befeb032f3a609744d0341f44d797dae80d0eb934ee27a630e7472d0ac6c08ed41b5c5c8cad5fc832dae26cd932a9d0e80909b1bd0
7
- data.tar.gz: 8cb47618a5ba19cf26b3194c9a983f7b4e399ea387d8fd0258b0eb2361f39313c1b8e04c10c14d412ac9c32e310d53bd7d5051a3f7741b16fa8187f915399e96
6
+ metadata.gz: 498a16a7bd795a5d06de3cc3ba8c82aff77947f3e293f61d2c86e08779d00883a49e60297744465722b74618807ea9eaed88f82778317b8994a4846d31193d54
7
+ data.tar.gz: cb9d189af74350e55643b31227588eb0ae114c7e35d6f78c1e143c6b573b6ba44a6c2dc508630cb1edc73b7bd57761e44e740df8289925878572ff7fabf10c14
@@ -1,3 +1,7 @@
1
+ ## v0.3.8
2
+ * Remove locks and move logic to connection access
3
+ * Check for result within response prior to access (prevent slaying actor)
4
+
1
5
  ## v0.3.6
2
6
  * Allow `:options` key within `Producer` to set low level connection settings
3
7
  * Make snappy an optional dependency
@@ -50,7 +50,10 @@ module Krakow
50
50
  # @return [Socket-ish] underlying socket like instance
51
51
  attr_reader :socket
52
52
 
53
- attr_reader :connector, :reconnector, :reconnect_notifier, :responder, :running
53
+ # set exclusive methods
54
+ exclusive :init!
55
+
56
+ attr_reader :reconnect_notifier, :running
54
57
 
55
58
  # @!group Attributes
56
59
 
@@ -95,9 +98,6 @@ module Krakow
95
98
  # @option args [Hash] :feature_args options for connection features
96
99
  def initialize(args={})
97
100
  super
98
- @connector = Mutex.new
99
- @reconnector = Mutex.new
100
- @responder = Mutex.new
101
101
  @reconnect_notifier = Celluloid::Signals.new
102
102
  @socket_retries = 0
103
103
  @socket_max_retries = 10
@@ -120,9 +120,7 @@ module Krakow
120
120
  #
121
121
  # @return [nil]
122
122
  def init!
123
- connector.synchronize do
124
- connect!
125
- end
123
+ connect!
126
124
  nil
127
125
  end
128
126
 
@@ -147,27 +145,25 @@ module Krakow
147
145
  # @param message [Krakow::Message] message to send
148
146
  # @return [Krakow::FrameType] response
149
147
  def transmit_with_response(message, wait_time)
150
- responder.synchronize do
151
- safe_socket{|socket| socket.write(message.to_line) }
152
- responses.clear
153
- response = nil
154
- (wait_time / response_interval).to_i.times do |i|
155
- response = responses.pop unless responses.empty?
156
- break if response
157
- sleep(response_interval)
148
+ safe_socket{|socket| socket.write(message.to_line) }
149
+ responses.clear
150
+ response = nil
151
+ (wait_time / response_interval).to_i.times do |i|
152
+ response = responses.pop unless responses.empty?
153
+ break if response
154
+ sleep(response_interval)
155
+ end
156
+ if(response)
157
+ message.response = response
158
+ if(message.error?(response))
159
+ res = Error::BadResponse.new "Message transmission failed #{message}"
160
+ res.result = response
161
+ abort res
158
162
  end
159
- if(response)
160
- message.response = response
161
- if(message.error?(response))
162
- res = Error::BadResponse.new "Message transmission failed #{message}"
163
- res.result = response
164
- abort res
165
- end
166
- response
167
- else
168
- unless(Command.response_for(message) == :error_only)
169
- abort Error::BadResponse::NoResponse.new "No response provided for message #{message}"
170
- end
163
+ response
164
+ else
165
+ unless(Command.response_for(message) == :error_only)
166
+ abort Error::BadResponse::NoResponse.new "No response provided for message #{message}"
171
167
  end
172
168
  end
173
169
  end
@@ -233,7 +229,7 @@ module Krakow
233
229
  if(message)
234
230
  debug "Adding message to queue #{message}"
235
231
  queue << message
236
- notifier.signal(message) if notifier
232
+ notifier.broadcast(message) if notifier
237
233
  end
238
234
  rescue Error::ConnectionUnavailable => e
239
235
  warn "Failed to receive message: #{e.class} - #{e}"
@@ -440,30 +436,24 @@ module Krakow
440
436
  #
441
437
  # @return [nil]
442
438
  def reconnect!
443
- if(reconnector.try_lock)
444
- begin
445
- if(@socket_max_retries <= @socket_retries)
446
- abort ConnectionFailure.new "Failed to re-establish connection after #{@socket_retries} tries."
447
- end
448
- pause_interval = @reconnect_pause * @socket_retries
449
- @socket_retries += 1
450
- warn "Pausing for #{pause_interval} seconds before reconnect"
451
- sleep(pause_interval)
452
- init!
453
- @socket_retries = 0
454
- rescue Celluloid::Error => e
455
- warn "Internal error encountered. Allowing exception to bubble. #{e.class}: #{e}"
456
- abort e
457
- rescue SystemCallError, IOError => e
458
- error "Reconnect error encountered: #{e.class} - #{e}"
459
- retry
439
+ begin
440
+ if(@socket_max_retries <= @socket_retries)
441
+ abort ConnectionFailure.new "Failed to re-establish connection after #{@socket_retries} tries."
460
442
  end
461
- callback_for(:reconnect)
462
- reconnect_notifier.broadcast(:connected)
463
- reconnector.unlock
464
- else
465
- reconnect_notifier.wait(:connected)
443
+ pause_interval = @reconnect_pause * @socket_retries
444
+ @socket_retries += 1
445
+ warn "Pausing for #{pause_interval} seconds before reconnect"
446
+ sleep(pause_interval)
447
+ init!
448
+ @socket_retries = 0
449
+ rescue Celluloid::Error => e
450
+ warn "Internal error encountered. Allowing exception to bubble. #{e.class}: #{e}"
451
+ abort e
452
+ rescue SystemCallError, IOError => e
453
+ error "Reconnect error encountered: #{e.class} - #{e}"
454
+ retry
466
455
  end
456
+ callback_for(:reconnect)
467
457
  nil
468
458
  end
469
459
 
@@ -202,7 +202,7 @@ module Krakow
202
202
  distribution.add_connection(connection)
203
203
  true
204
204
  rescue Error::BadResponse => e
205
- debug "Failed to establish connection: #{e.result.error}"
205
+ debug "Failed to establish connection: #{e.result ? e.result.error : '<No Response!>'}"
206
206
  connection.terminate
207
207
  false
208
208
  end
@@ -16,6 +16,9 @@ module Krakow
16
16
  trap_exit :connection_failure
17
17
  finalizer :goodbye_my_love!
18
18
 
19
+ # set exclusive methods
20
+ exclusive :write
21
+
19
22
  attr_reader :connection
20
23
 
21
24
  # @!group Attributes
@@ -1,4 +1,4 @@
1
1
  module Krakow
2
2
  # Current version
3
- VERSION = Gem::Version.new('0.3.6')
3
+ VERSION = Gem::Version.new('0.3.8')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krakow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-07 00:00:00.000000000 Z
11
+ date: 2014-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid-io