freddy 0.3.1 → 0.3.2

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: e21020f1717f322384deb6ab9ce33231c59a7d82
4
- data.tar.gz: 6efdccf186349f3f874dee8889bda4a4a269b40b
3
+ metadata.gz: cca77c9b3fbbe1d36a577b1f83dac5403d622951
4
+ data.tar.gz: 173f636703aa687c57ab451739736aa55e082021
5
5
  SHA512:
6
- metadata.gz: b69c2cb81573afc359da3aaa8e1387d479224716e3e49d75ea09781e85895d89891f91617873cd8a2c01dafdaaa958d4241b62d2fc50655e8f104933efb33f92
7
- data.tar.gz: 813043fcd1e6d2adfdd16c5c379f9d8ba7b9df8d82db1365547760f8a827dfac4e970bbd850918e85cc401c4daf43f873f1fbb7a4a8974e5dae05ae8841ba16e
6
+ metadata.gz: 6eb122206afd0ed15c142b8b70a63f68501033be27e54cc4c459f7f028daf03bf9b697efd46bea521348ce38e04c5f59b936d0e0174cda572499b26456e0116c
7
+ data.tar.gz: 388f18d7af6a373c9952a4a36b2e4a32ccefa78ff160511993da9b18f6b4b06a527036ab648f63230d06bdf36ee644be5b2a4bf6fb0f9444bcc6f7595acc56ed
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- freddy (0.3.0)
4
+ freddy (0.3.2)
5
5
  bunny (= 1.6.3)
6
6
  hamster (~> 1.0.1.pre.rc3)
7
7
  symbolizer
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "freddy"
7
- spec.version = '0.3.1'
7
+ spec.version = '0.3.2'
8
8
  spec.authors = ["Urmas Talimaa"]
9
9
  spec.email = ["urmas.talimaa@gmail.com"]
10
10
  spec.description = %q{Messaging API}
@@ -3,6 +3,7 @@ require_relative 'consumer'
3
3
  require_relative 'request_manager'
4
4
  require_relative 'sync_response_container'
5
5
  require_relative 'message_handlers'
6
+ require 'thread'
6
7
  require 'securerandom'
7
8
  require 'hamster/mutable_hash'
8
9
 
@@ -19,7 +20,6 @@ class Freddy
19
20
  def initialize(channel, logger)
20
21
  @channel, @logger = channel, logger
21
22
  @producer, @consumer = Producer.new(channel, logger), Consumer.new(channel, logger)
22
- @listening_for_responses = false
23
23
  @request_map = Hamster.mutable_hash
24
24
  @request_manager = RequestManager.new @request_map, @logger
25
25
 
@@ -28,6 +28,9 @@ class Freddy
28
28
  @request_manager.no_route(properties[:correlation_id])
29
29
  end
30
30
  end
31
+
32
+ @listening_for_responses_lock = Mutex.new
33
+ @response_queue_lock = Mutex.new
31
34
  end
32
35
 
33
36
  def sync_request(destination, payload, opts)
@@ -43,7 +46,7 @@ class Freddy
43
46
  options.delete(:timeout)
44
47
  options.delete(:delete_on_timeout)
45
48
 
46
- listen_for_responses unless @listening_for_responses
49
+ ensure_listening_to_responses
47
50
 
48
51
  correlation_id = SecureRandom.uuid
49
52
  @request_map.store(correlation_id, callback: block, destination: destination, timeout: Time.now + timeout)
@@ -62,7 +65,8 @@ class Freddy
62
65
 
63
66
  def respond_to(destination, &block)
64
67
  raise EmptyResponder unless block
65
- @response_queue = create_response_queue unless @response_queue
68
+
69
+ ensure_response_queue_exists
66
70
  @logger.debug "Listening for requests on #{destination}"
67
71
 
68
72
  responder_handler = @consumer.consume destination do |payload, delivery|
@@ -98,14 +102,25 @@ class Freddy
98
102
  Freddy.notify_exception(e, destination: request[:destination], correlation_id: correlation_id)
99
103
  end
100
104
 
101
- def listen_for_responses
102
- @listening_for_responses = true
103
- @response_queue = create_response_queue unless @response_queue
104
- @request_manager.start
105
- @consumer.consume_from_queue @response_queue do |payload, delivery|
106
- handle_response payload, delivery
105
+ def ensure_response_queue_exists
106
+ @response_queue_lock.synchronize do
107
+ @response_queue ||= create_response_queue
107
108
  end
108
109
  end
109
110
 
111
+ def ensure_listening_to_responses
112
+ @listening_for_responses_lock.synchronize do
113
+ if @listening_for_responses
114
+ true
115
+ else
116
+ ensure_response_queue_exists
117
+ @request_manager.start
118
+ @consumer.consume_from_queue @response_queue do |payload, delivery|
119
+ handle_response payload, delivery
120
+ end
121
+ @listening_for_responses = true
122
+ end
123
+ end
124
+ end
110
125
  end
111
126
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Urmas Talimaa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-10 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.4.2
139
+ rubygems_version: 2.2.2
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: API for inter-application messaging supporting acknowledgements and request-response