rsmp 0.8.2 → 0.8.3

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
  SHA256:
3
- metadata.gz: 49e4aee9252ad888e831e5ce0738eff5bba57fdd6f2ec2220d7e74936e0e8177
4
- data.tar.gz: 5866b23cb324d0732de17f995abec6304f50673e9cfcaa7b440dea6858102cd8
3
+ metadata.gz: f54121873905da2e5ffa4914f4f454fc4b59c7283e482b6b89b4035d686b7779
4
+ data.tar.gz: 523d2e310ebec8f4df07592fcb501d91f604ba8ea1c4625482c7d8d011340a6f
5
5
  SHA512:
6
- metadata.gz: 0ff9a48cde72b3fb3963c421a321c4bd08c0edfb9afcd7b4b919e2e92aa37624259a5124c81f4bd0189cc6a3596414edc75a305fb19b0c348fadc4e836bdf7cf
7
- data.tar.gz: 490aa51f0a4a5b9a6a197c0f6bbe11b8ae16934e5eecd76a486b6e4e34786ebbb334d4ddabf7340c9f13d4946cad4e162db49205a3fbf04fa064938bf6029e0f
6
+ metadata.gz: 807d2283a18f4a9c4e45594d4ae85e75464cde3792eb941342a825e8765a00d21f7d541fac03191680e28eb7e4af4c6624cb6ce80486da191cf3bc2b3f2d6431
7
+ data.tar.gz: 6adc50becc91e2deab2c8099808a492a2440d072188227147742bd51ec1310f8a1075e3bed72f2989581ba11125b9beeda8134704d8a42e131ac1dac9a76eca1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.8.2)
4
+ rsmp (0.8.3)
5
5
  async (~> 1.29.1)
6
6
  async-io (~> 1.32.1)
7
7
  colorize (~> 0.8.1)
@@ -157,7 +157,7 @@ task.wait # wait for collection task to complete (or time out)
157
157
  ```
158
158
 
159
159
  ### With collection
160
- If you provide `:collect` options, it will be used to construct a StatusUpdateCollector for collecting the relevant status messages. When collection completes the collector is returned in the `:collector` key:
160
+ If you provide `:collect` options, it will be used to construct a StatusCollector for collecting the relevant status messages. When collection completes the collector is returned in the `:collector` key:
161
161
 
162
162
  ```ruby
163
163
  options = {
@@ -6,8 +6,8 @@ module RSMP
6
6
  class Collector < Listener
7
7
  attr_reader :condition, :messages, :status, :error, :task
8
8
 
9
- def initialize proxy, options={}
10
- super proxy, options
9
+ def initialize notifier, options={}
10
+ super notifier, options
11
11
  @options = {
12
12
  cancel: {
13
13
  schema_error: true,
@@ -18,7 +18,15 @@ module RSMP
18
18
  @outgoing = options[:outgoing] == nil ? false : options[:outgoing]
19
19
  @condition = Async::Notification.new
20
20
  @title = options[:title] || [@options[:type]].flatten.join('/')
21
- @task = options[:task]
21
+ if options[:task]
22
+ @task = options[:task]
23
+ else
24
+ # if notifier is a Proxy, or some other object that implements task(),
25
+ # then try to get the task that way
26
+ if notifier.respond_to? 'task'
27
+ @task = notifier.task
28
+ end
29
+ end
22
30
  reset
23
31
  end
24
32
 
@@ -192,8 +200,8 @@ module RSMP
192
200
  @condition.signal
193
201
  end
194
202
 
195
- # The proxy experienced some error.
196
- # Check if this should cause us to cancel.
203
+ # An error occured upstream.
204
+ # Check if we should cancel.
197
205
  def notify_error error, options={}
198
206
  case error
199
207
  when RSMP::SchemaError
@@ -1,8 +1,11 @@
1
1
  module RSMP
2
2
  # Base class for waiting for status updates or responses
3
- class StatusUpdateOrResponseCollector < StateCollector
3
+ class StatusCollector < StateCollector
4
4
  def initialize proxy, want, options={}
5
- super proxy, want, options.merge(outgoing: false)
5
+ super proxy, want, options.merge(title: 'status response', type:['MessageNotAck'])
6
+
7
+ @options[:type] << 'StatusUpdate' unless options[:updates] == false
8
+ @options[:type] << 'StatusResponse' unless options[:reponses] == false
6
9
  end
7
10
 
8
11
  def build_query want
data/lib/rsmp/node.rb CHANGED
@@ -15,7 +15,6 @@ module RSMP
15
15
  @clock = Clock.new
16
16
  @error_queue = Async::Queue.new
17
17
  @ignore_errors = []
18
- options[:collector]
19
18
  @collect = options[:collect]
20
19
  end
21
20
 
data/lib/rsmp/proxy.rb CHANGED
@@ -52,12 +52,6 @@ module RSMP
52
52
  node.clock
53
53
  end
54
54
 
55
- def collect options, &block
56
- collector = RSMP::Collector.new self, options.merge(task: @task)
57
- collector.collect &block
58
- collector
59
- end
60
-
61
55
  def run
62
56
  start
63
57
  @reader.wait if @reader
@@ -579,25 +573,27 @@ module RSMP
579
573
  end
580
574
 
581
575
  def wait_for_acknowledgement parent_task, options={}, m_id
582
- collect(parent_task,options.merge({
583
- type: ['MessageAck','MessageNotAck'],
584
- num: 1
585
- })) do |message|
576
+ collector = Collector.new self, options.merge(task: parent_task, type: ['MessageAck','MessageNotAck'])
577
+ collector.collect do |message|
586
578
  if message.is_a?(MessageNotAck)
587
579
  if message.attribute('oMId') == m_id
588
- # set result to an exception, but don't raise it.
589
- # this will be returned by the task and stored as the task result
590
- # when the parent task call wait() on the task, the exception
591
- # will be raised in the parent task, and caught by rspec.
592
- # rspec will then show the error and record the test as failed
593
580
  m_id_short = RSMP::Message.shorten_m_id m_id, 8
594
- result = RSMP::MessageRejected.new "Aggregated status request #{m_id_short} was rejected with '#{message.attribute('rea')}'"
595
- next true # done, no more messages wanted
581
+ raise RSMP::MessageRejected.new "Aggregated status request #{m_id_short} was rejected with '#{message.attribute('rea')}'"
596
582
  end
597
583
  elsif message.is_a?(MessageAck)
598
- next true if message.attribute('oMId') == m_id
584
+ collector.complete if message.attribute('oMId') == m_id
599
585
  end
600
- false
586
+ end
587
+ end
588
+
589
+ def send_and_optionally_collect message, options, &block
590
+ if options[:collect]
591
+ task = @task.async { |task| yield task }
592
+ send_message message, validate: options[:validate]
593
+ { sent: message, collector: task.wait }
594
+ else
595
+ send_message message, validate: options[:validate]
596
+ return { sent: message }
601
597
  end
602
598
  end
603
599
  end
data/lib/rsmp/site.rb CHANGED
@@ -95,7 +95,8 @@ module RSMP
95
95
  ip: supervisor_settings['ip'],
96
96
  port: supervisor_settings['port'],
97
97
  logger: @logger,
98
- archive: @archive
98
+ archive: @archive,
99
+ collect: @collect
99
100
  })
100
101
  @proxies << proxy
101
102
  @proxies_condition.signal
@@ -101,8 +101,13 @@ module RSMP
101
101
  "cId" => component,
102
102
  "mId" => m_id
103
103
  })
104
- send_and_collect_if_needed message, options do |task|
105
- collect_aggregated_status task, options[:collect].merge(m_id: m_id, num:1)
104
+ send_and_optionally_collect message, options do |task|
105
+ collector = AggregatedStatusCollector.new(
106
+ self,
107
+ options[:collect].merge(task:@task,m_id: m_id, num:1)
108
+ )
109
+ collector.collect
110
+ collector
106
111
  end
107
112
  end
108
113
 
@@ -174,8 +179,14 @@ module RSMP
174
179
  "sS" => request_list,
175
180
  "mId" => m_id
176
181
  })
177
- send_and_collect_if_needed message, options do |task|
178
- collect_status_responses task, status_list, options[:collect].merge(m_id: m_id)
182
+ send_and_optionally_collect message, options do |task|
183
+ collector = StatusCollector.new(
184
+ self,
185
+ status_list,
186
+ options[:collect].merge(task:@task,m_id: m_id)
187
+ )
188
+ collector.collect
189
+ collector
179
190
  end
180
191
  end
181
192
 
@@ -186,17 +197,6 @@ module RSMP
186
197
  acknowledge message
187
198
  end
188
199
 
189
- def send_and_collect_if_needed message, options, &block
190
- if options[:collect]
191
- task = @task.async { |task| yield task }
192
- send_message message, validate: options[:validate]
193
- { sent: message, collector: task.wait }
194
- else
195
- send_message message, validate: options[:validate]
196
- return { sent: message }
197
- end
198
- end
199
-
200
200
  def subscribe_to_status component_id, status_list, options={}
201
201
  validate_ready 'subscribe to status'
202
202
  m_id = options[:m_id] || RSMP::Message.make_m_id
@@ -215,8 +215,14 @@ module RSMP
215
215
  "sS" => subscribe_list,
216
216
  'mId' => m_id
217
217
  })
218
- send_and_collect_if_needed message, options do |task|
219
- collect_status_updates task, status_list, options[:collect].merge(m_id: m_id)
218
+ send_and_optionally_collect message, options do |task|
219
+ collector = StatusCollector.new(
220
+ self,
221
+ status_list,
222
+ options[:collect].merge(task:@task,m_id: m_id)
223
+ )
224
+ collector.collect
225
+ collector
220
226
  end
221
227
  end
222
228
 
@@ -261,8 +267,14 @@ module RSMP
261
267
  "arg" => command_list,
262
268
  "mId" => m_id
263
269
  })
264
- send_and_collect_if_needed message, options do |task|
265
- collect_command_responses task, command_list, options[:collect].merge(m_id: m_id)
270
+ send_and_optionally_collect message, options do |task|
271
+ collector = CommandResponseCollector.new(
272
+ self,
273
+ command_list,
274
+ options[:collect].merge(task:@task,m_id: m_id)
275
+ )
276
+ collector.collect
277
+ collector
266
278
  end
267
279
  end
268
280
 
@@ -339,37 +351,13 @@ module RSMP
339
351
  distribute_error e, options
340
352
  end
341
353
 
342
- def collect_alarms parent_task, options={}
343
- collect(parent_task,options.merge(type: "Alarm")) do |alarm|
354
+ def collect_alarms options={}
355
+ collect(@task,options.merge(type: "Alarm")) do |alarm|
344
356
  next if options[:aCId] && options[:aCId] != alarm.attribute("aCId")
345
357
  next if options[:aSp] && options[:aSp] != alarm.attribute("aSp")
346
358
  next if options[:aS] && options[:aS] != alarm.attribute("aS")
347
- true
359
+ :keep
348
360
  end
349
361
  end
350
-
351
- def collect_status_updates task, status_list, options
352
- collector = StatusUpdateCollector.new(self, status_list, options.merge(task:task))
353
- collector.collect
354
- collector
355
- end
356
-
357
- def collect_status_responses task, status_list, options
358
- collector = StatusResponseCollector.new(self, status_list, options.merge(task:task))
359
- collector.collect
360
- collector
361
- end
362
-
363
- def collect_command_responses task, command_list, options
364
- collector = CommandResponseCollector.new(self, command_list, options.merge(task:task))
365
- collector.collect
366
- collector
367
- end
368
-
369
- def collect_aggregated_status task, options
370
- collector = AggregatedStatusCollector.new(self, options.merge(task:task))
371
- collector.collect
372
- collector
373
- end
374
362
  end
375
363
  end
@@ -138,16 +138,8 @@ module RSMP
138
138
  "mId" => m_id,
139
139
  })
140
140
 
141
- if options[:collect]
142
- result = nil
143
- task = @task.async do |task|
144
- wait_for_acknowledgement task, options[:collect], m_id
145
- end
146
- send_message message, validate: options[:validate]
147
- return message, task.wait
148
- else
149
- send_message message, validate: options[:validate]
150
- message
141
+ send_and_optionally_collect message, options do |task|
142
+ wait_for_acknowledgement task, options[:collect], m_id
151
143
  end
152
144
  end
153
145
 
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.8.2"
2
+ VERSION = "0.8.3"
3
3
  end
data/lib/rsmp.rb CHANGED
@@ -25,9 +25,7 @@ require 'rsmp/collect/filter'
25
25
  require 'rsmp/collect/query'
26
26
  require 'rsmp/collect/status_query'
27
27
  require 'rsmp/collect/command_query'
28
- require 'rsmp/collect/status_update_or_response_collector'
29
- require 'rsmp/collect/status_response_collector'
30
- require 'rsmp/collect/status_update_collector'
28
+ require 'rsmp/collect/status_collector'
31
29
  require 'rsmp/collect/command_response_collector'
32
30
  require 'rsmp/collect/aggregated_status_collector'
33
31
  require 'rsmp/component'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-10 00:00:00.000000000 Z
11
+ date: 2022-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -217,10 +217,8 @@ files:
217
217
  - lib/rsmp/collect/notifier.rb
218
218
  - lib/rsmp/collect/query.rb
219
219
  - lib/rsmp/collect/state_collector.rb
220
+ - lib/rsmp/collect/status_collector.rb
220
221
  - lib/rsmp/collect/status_query.rb
221
- - lib/rsmp/collect/status_response_collector.rb
222
- - lib/rsmp/collect/status_update_collector.rb
223
- - lib/rsmp/collect/status_update_or_response_collector.rb
224
222
  - lib/rsmp/component.rb
225
223
  - lib/rsmp/components.rb
226
224
  - lib/rsmp/convert/export/json_schema.rb
@@ -1,11 +0,0 @@
1
- module RSMP
2
- # Class for waiting for specific status responses
3
- class StatusResponseCollector < StatusUpdateOrResponseCollector
4
- def initialize proxy, want, options={}
5
- super proxy, want, options.merge(
6
- type: ['StatusResponse','MessageNotAck'],
7
- title: 'status response'
8
- )
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module RSMP
2
- # Class for waiting for specific status responses
3
- class StatusUpdateCollector < StatusUpdateOrResponseCollector
4
- def initialize proxy, want, options={}
5
- super proxy, want, options.merge(
6
- type: ['StatusUpdate','MessageNotAck'],
7
- title:'status update'
8
- )
9
- end
10
- end
11
- end