rsmp 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5316c50ad6cd09d30e7d1baab78e717fac4656c06178272ef4adc1c6647fb544
4
- data.tar.gz: 6ef4d635b42f3eac19b94b68bbcb05c59ce94de96e0e27f1f5c7a6deefd4e470
3
+ metadata.gz: 49e4aee9252ad888e831e5ce0738eff5bba57fdd6f2ec2220d7e74936e0e8177
4
+ data.tar.gz: 5866b23cb324d0732de17f995abec6304f50673e9cfcaa7b440dea6858102cd8
5
5
  SHA512:
6
- metadata.gz: 1947906505e532d0d47d93f1d9fe2c8c3199ff58d378b9be3df18865339e966a6ad5f74512aa168ee4a5d641624cf7b0f170436d2c11e4f495bd7d6b88be502f
7
- data.tar.gz: ee0ecbb229637276d6cec21ccacc6414199ad7f0392324633231cb4a8632a8b64b1aa2ba5abd979a7699ed6721a5a40b9d9c531f45dc0f59345149662e608b12
6
+ metadata.gz: 0ff9a48cde72b3fb3963c421a321c4bd08c0edfb9afcd7b4b919e2e92aa37624259a5124c81f4bd0189cc6a3596414edc75a305fb19b0c348fadc4e836bdf7cf
7
+ data.tar.gz: 490aa51f0a4a5b9a6a197c0f6bbe11b8ae16934e5eecd76a486b6e4e34786ebbb334d4ddabf7340c9f13d4946cad4e162db49205a3fbf04fa064938bf6029e0f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.8.1)
4
+ rsmp (0.8.2)
5
5
  async (~> 1.29.1)
6
6
  async-io (~> 1.32.1)
7
7
  colorize (~> 0.8.1)
data/config/tlc.yaml CHANGED
@@ -21,10 +21,10 @@ signal_plans:
21
21
  1: 0
22
22
  2: 5
23
23
  states:
24
- A1: '11NBBB'
25
- A2: '1NBBBB'
26
- B1: 'BBB11N'
27
- B2: 'BBB1NB'
24
+ A1: '123efg'
25
+ A2: '123efg'
26
+ B1: '123efg'
27
+ B2: '123efg'
28
28
  2:
29
29
  states:
30
30
  A1: '111NBB'
@@ -80,7 +80,7 @@ module RSMP
80
80
  wait
81
81
  @status
82
82
  ensure
83
- @notifier.remove_listener self
83
+ @notifier.remove_listener self if @notifier
84
84
  end
85
85
 
86
86
  # Collect message
@@ -151,28 +151,26 @@ module RSMP
151
151
  # Handle message. and return true when we're done collecting
152
152
  def notify message
153
153
  raise ArgumentError unless message
154
- raise RuntimeError.new("can't process message when done") unless ready? || collecting?
155
- unless reject_not_ack(message)
156
- perform_match message
157
- end
154
+ raise RuntimeError.new("can't process message when status is :#{@status}, title: #{@title}, desc: #{describe}") unless ready? || collecting?
155
+ perform_match message
158
156
  @status
159
157
  end
160
158
 
159
+ def describe
160
+ end
161
+
161
162
  # Match message against our collection criteria
162
163
  def perform_match message
163
- return unless type_match?(message)
164
+ return false if reject_not_ack(message)
165
+ return false unless type_match?(message)
164
166
  if @block
165
167
  status = [@block.call(message)].flatten
168
+ return unless collecting?
166
169
  keep message if status.include?(:keep)
167
- if status.include?(:cancel)
168
- cancel('Cancelled by block')
169
- else
170
- complete if done?
171
- end
172
170
  else
173
171
  keep message
174
- complete if done?
175
172
  end
173
+ complete if done?
176
174
  end
177
175
 
178
176
  # Have we collected the required number of messages?
@@ -224,7 +222,7 @@ module RSMP
224
222
  end
225
223
 
226
224
  # Abort collection
227
- def cancel error
225
+ def cancel error=nil
228
226
  @error = error
229
227
  @status = :cancelled
230
228
  do_stop
@@ -14,7 +14,7 @@ module RSMP
14
14
 
15
15
  # Get items, in our case the return values
16
16
  def get_items message
17
- message.attributes['rvs']
17
+ message.attributes['rvs'] || []
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,31 @@
1
+ module RSMP
2
+
3
+ # Filter messages based on type, direction and component id.
4
+ # Used by Collectors.
5
+ class Filter
6
+ def initialize ingoing:true, outgoing:true, type:, component:nil
7
+ @ingoing = ingoing
8
+ @outgoing = outgoing
9
+ @type = type
10
+ @component = component
11
+ end
12
+
13
+ # Check a message against our match criteria
14
+ # Return true if there's a match, false if not
15
+ def accept? message
16
+ return false if message.direction == :in && @ingoing == false
17
+ return false if message.direction == :out && @outgoing == false
18
+ if @type
19
+ if @type.is_a? Array
20
+ return false unless @type.include? message.type
21
+ else
22
+ return false unless message.type == @type
23
+ end
24
+ end
25
+ if @component
26
+ return false if message.attributes['cId'] && message.attributes['cId'] != @component
27
+ end
28
+ true
29
+ end
30
+ end
31
+ end
@@ -19,13 +19,5 @@ module RSMP
19
19
 
20
20
  def notify_error error, options={}
21
21
  end
22
-
23
- def listen &block
24
- @notifier.add_listener self
25
- yield
26
- ensure
27
- @notifier.remove_listener self
28
- end
29
-
30
22
  end
31
23
  end
@@ -8,26 +8,36 @@ module RSMP
8
8
  @want = want
9
9
  @got = nil
10
10
  @message = nil
11
- @done = false
12
11
  end
13
12
 
14
13
  # Are we done, i.e. did the last checked item match?
15
14
  def done?
16
- @done
15
+ @got != nil
17
16
  end
18
17
 
19
18
  # Check an item and set @done to true if it matches
20
19
  # Store the item and corresponding message if there's a positive or negative match
21
- def perform_match item, message
20
+ def perform_match item, message, block
22
21
  matched = match? item
23
22
  if matched != nil
24
- @message = message
25
- @got = item
26
- @done = matched
23
+ if block
24
+ status = block.call(nil,item)
25
+ matched = status if status == true || status == false
26
+ end
27
27
  end
28
28
  matched
29
29
  end
30
30
 
31
+ def keep message, item
32
+ @message = message
33
+ @got = item
34
+ end
35
+
36
+ def forget
37
+ @message = nil
38
+ @got = nil
39
+ end
40
+
31
41
  def match? item
32
42
  end
33
43
  end
@@ -61,7 +61,7 @@ module RSMP
61
61
 
62
62
  # Get messages from results
63
63
  def messages
64
- @queries.map { |query| query.message }.uniq
64
+ @queries.map { |query| query.message }.uniq.compact
65
65
  end
66
66
 
67
67
  # Return progress as completes queries vs. total number of queries
@@ -90,22 +90,33 @@ module RSMP
90
90
  # Check if a messages matches our criteria.
91
91
  # Match each query against each item in the message
92
92
  def perform_match message
93
- return unless type_match?(message)
93
+ return false if super(message) == false
94
+ return unless collecting?
94
95
  @queries.each do |query| # look through queries
95
96
  get_items(message).each do |item| # look through items in message
96
- matched = query.perform_match(item,message)
97
- if matched == true
98
- matched = @block.call(message,item) if @block
99
- end
97
+ matched = query.perform_match(item,message,@block)
98
+ return unless collecting?
100
99
  if matched != nil
101
100
  type = {true=>'match',false=>'mismatch'}[matched]
102
101
  @notifier.log "#{@title.capitalize} #{message.m_id_short} collect #{type} #{query.want}, item #{item}", level: :debug
103
- break
102
+ if matched == true
103
+ query.keep message, item
104
+ elsif matched == false
105
+ query.forget
106
+ end
104
107
  end
105
108
  end
106
109
  end
107
110
  complete if done?
108
111
  @notifier.log "#{@title.capitalize} collect reached #{summary}", level: :debug
109
112
  end
113
+
114
+ # don't collect anything. Query will collect them instead
115
+ def keep message
116
+ end
117
+
118
+ def describe
119
+ @queries.map {|q| q.want.to_s }
120
+ end
110
121
  end
111
122
  end
@@ -2,7 +2,7 @@ module RSMP
2
2
  # Base class for waiting for status updates or responses
3
3
  class StatusUpdateOrResponseCollector < StateCollector
4
4
  def initialize proxy, want, options={}
5
- super proxy, want, options.merge
5
+ super proxy, want, options.merge(outgoing: false)
6
6
  end
7
7
 
8
8
  def build_query want
@@ -11,7 +11,7 @@ module RSMP
11
11
 
12
12
  # Get items, in our case status values
13
13
  def get_items message
14
- message.attributes['sS']
14
+ message.attributes['sS'] || []
15
15
  end
16
16
  end
17
17
  end
@@ -282,7 +282,7 @@ module RSMP
282
282
  end
283
283
 
284
284
  def fetch_last_sent_status component, code, name
285
- @last_status_sent.dig component, code, name
285
+ @last_status_sent.dig component, code, name if @last_status_sent
286
286
  end
287
287
 
288
288
  def store_last_sent_status message
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
data/lib/rsmp.rb CHANGED
@@ -21,6 +21,7 @@ require 'rsmp/collect/notifier'
21
21
  require 'rsmp/collect/listener'
22
22
  require 'rsmp/collect/collector'
23
23
  require 'rsmp/collect/state_collector'
24
+ require 'rsmp/collect/filter'
24
25
  require 'rsmp/collect/query'
25
26
  require 'rsmp/collect/status_query'
26
27
  require 'rsmp/collect/command_query'
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.1
4
+ version: 0.8.2
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-07 00:00:00.000000000 Z
11
+ date: 2022-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -211,6 +211,7 @@ files:
211
211
  - lib/rsmp/collect/collector.rb
212
212
  - lib/rsmp/collect/command_query.rb
213
213
  - lib/rsmp/collect/command_response_collector.rb
214
+ - lib/rsmp/collect/filter.rb
214
215
  - lib/rsmp/collect/listener.rb
215
216
  - lib/rsmp/collect/message_matchers.rb
216
217
  - lib/rsmp/collect/notifier.rb