simplepubsub 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: 5bcf845ea9121b3f64cfa371a9848290a3e96b12
4
- data.tar.gz: 983d1e48ec5d9a4298ac917a3d4f6b48d6162f65
3
+ metadata.gz: cb9c522f87754fb3b35dc8beabcdae04ac78e1ca
4
+ data.tar.gz: f36a883a542bfe73c180a51e279983fff2ae88d6
5
5
  SHA512:
6
- metadata.gz: f901f2ae9edcae7ebca6105706a21a706b37d3fa29d4437e21f3ce5104c1714aca0932deb2016d8befd62f613abbdde658ac6e0b71f8033db38ed712dce6cad1
7
- data.tar.gz: 1d724b8c5fcea4debe992c8b79ca5124c23644118ff258b2f446137f7f7c1d0d6fed840b0ae2920641a84d857b3bb3f3ae442c26cc69a21b4c21e615d3e7e4c2
6
+ metadata.gz: 11d4d4e480eb0edde819cc69fd8b98496ef6ccd013ef3d0212c56b795f92e711bc61de51c68f2d2f80a36dde69dbcdc10dfe1becd2d5cbfb406292095a3324d7
7
+ data.tar.gz: ac85bf1eb757ac9ec648e791e2e4f8b7d7f127954775d21b25d2836f99b0d3d2730b8b5636f37e12dbd838ff1952590fc776a2fb6da5431d9be4c5b69a60ca64
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/simplepubsub.rb CHANGED
@@ -7,7 +7,7 @@ require 'drb'
7
7
  require 'dws-registry'
8
8
 
9
9
 
10
- USER_AGENT = 'SimplePubSub client 0.3.1'
10
+ USER_AGENT = 'SimplePubSub client 0.3.2'
11
11
 
12
12
  module SimplePubSub
13
13
 
@@ -67,7 +67,8 @@ module SimplePubSub
67
67
  # try to read the subscribers
68
68
  topics = @reg.get_key 'hkey_apps/simplepubsub/subscription_topics'
69
69
 
70
- @subscribers = {'#' => []}
70
+ @hostname = hostname
71
+ @subscribers, @bridges = {'#' => []}, {'#' => {}}
71
72
 
72
73
  if topics then
73
74
  topics.elements.each do |topic_element|
@@ -76,10 +77,34 @@ module SimplePubSub
76
77
  @subscribers[topic] = topic_element.elements[0].elements.map(&:value)
77
78
  end
78
79
  end
80
+
81
+
82
+ all_topics = @reg.get_key 'hkey_apps/simplepubsub/subscription_all_topics'
83
+
84
+ if all_topics then
85
+ @subscribers['#'] = all_topics.elements[0].elements.map(&:value)
86
+ end
87
+
88
+
89
+ bridge_topics = @reg.get_key 'hkey_apps/simplepubsub/bridge_topics'
79
90
 
80
- @hostname = hostname
91
+ if bridge_topics then
92
+ bridge_topics.elements.each do |topic_element|
93
+ topic = topic_element.name
94
+ @bridges[topic] = topic_element.elements[0].elements.inject({}) do |r,x|
95
+ r.merge({x.name.to_s => x.text('address')})
96
+ end
97
+ end
98
+ end
81
99
 
82
- @bridges = {'#' => []}
100
+ bridge_all_topics = @reg.get_key 'hkey_apps/simplepubsub/bridge_all_topics'
101
+
102
+ if bridge_all_topics then
103
+ @bridges['#'] = bridge_all_topics.elements[0].elements.inject({}) do |r,x|
104
+ r.merge({x.name.to_s => x.text('address')})
105
+ end
106
+ end
107
+ 'done'
83
108
  end
84
109
 
85
110
  def subscribe(topic, uri)
@@ -119,10 +144,19 @@ module SimplePubSub
119
144
  begin
120
145
  echo.message topic, msg
121
146
  rescue DRb::DRbConnError => e
147
+
122
148
  @subscribers[topic].delete uri
123
- key = "hkey_apps/simplepubsub/subscription_topics/%s/subscribers/%s" % \
124
- [topic, uri[/[^\/]+$/].sub(':','')]
149
+
150
+ if @subscribers[topic].empty? then
151
+ @subscribers.delete topic
152
+ key = "hkey_apps/simplepubsub/subscription_topics/%s" % [topic]
153
+ else
154
+ key = "hkey_apps/simplepubsub/subscription_topics/%s/subscribers/%s" % \
155
+ [topic, uri[/[^\/]+$/].sub(':','')]
156
+ end
157
+
125
158
  @reg.delete_key key
159
+
126
160
  end
127
161
 
128
162
  end
@@ -134,16 +168,48 @@ module SimplePubSub
134
168
 
135
169
  begin
136
170
  echo.message topic, msg
137
- rescue DRb::DRbConnError => e
171
+ rescue DRb::DRbConnError => e
172
+
138
173
  @subscribers['#'].delete uri
174
+ key = "hkey_apps/simplepubsub/subscription_all_topics/subscribers/%s" % \
175
+ [uri[/[^\/]+$/].sub(':','')]
176
+ @reg.delete_key key
139
177
  end
140
178
 
141
179
  end
142
180
  end
143
181
 
144
182
  def add_bridge(topic, hostname, address)
145
- @bridges[topic] ||= {}
146
- @bridges[topic].merge!(hostname => address)
183
+
184
+ if topic == '#' then
185
+
186
+ key = "hkey_apps/simplepubsub/bridge_all_topics/webserver/%s/address" % \
187
+ [hostname]
188
+ else
189
+ topic.sub!('/','_')
190
+ @bridges[topic] ||= {}
191
+
192
+ key = "hkey_apps/simplepubsub/bridge_topics/%s/webserver/%s/address" % \
193
+ [topic, hostname]
194
+ end
195
+
196
+ @bridges[topic].merge!(hostname => address)
197
+ @reg.set_key key, address
198
+ end
199
+
200
+ def delete_bridge(topic, hostname)
201
+
202
+ @bridges[topic].delete hostname
203
+
204
+ if @bridges[topic].empty? and topic != '#' then
205
+ @bridges.delete_key(topic)
206
+ key = "hkey_apps/simplepubsub/bridge_topics/%s" % [topic]
207
+ else
208
+ key = "hkey_apps/simplepubsub/bridge_topics/%s/webserver/%s/address" % \
209
+ [topic, hostname]
210
+ end
211
+
212
+ @reg.delete_key key
147
213
  end
148
214
 
149
215
  def bridge_deliver(topic, message, excluded_host=nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplepubsub
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
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  i0PBE6fLwlIMk8jNNUcX3J1csSMgLNTwE8CwrlSZE8sueHj0pQzICM7lF0gGREO6
32
32
  hQHD0LljU3MusQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2013-06-26 00:00:00.000000000 Z
34
+ date: 2013-06-27 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: dws-registry
metadata.gz.sig CHANGED
Binary file