rsmp 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/config/tlc.yaml +4 -4
- data/lib/rsmp/collect/collector.rb +11 -13
- data/lib/rsmp/collect/command_response_collector.rb +1 -1
- data/lib/rsmp/collect/filter.rb +31 -0
- data/lib/rsmp/collect/listener.rb +0 -8
- data/lib/rsmp/collect/query.rb +16 -6
- data/lib/rsmp/collect/state_collector.rb +18 -7
- data/lib/rsmp/collect/status_update_or_response_collector.rb +2 -2
- data/lib/rsmp/supervisor_proxy.rb +1 -1
- data/lib/rsmp/version.rb +1 -1
- data/lib/rsmp.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49e4aee9252ad888e831e5ce0738eff5bba57fdd6f2ec2220d7e74936e0e8177
|
4
|
+
data.tar.gz: 5866b23cb324d0732de17f995abec6304f50673e9cfcaa7b440dea6858102cd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff9a48cde72b3fb3963c421a321c4bd08c0edfb9afcd7b4b919e2e92aa37624259a5124c81f4bd0189cc6a3596414edc75a305fb19b0c348fadc4e836bdf7cf
|
7
|
+
data.tar.gz: 490aa51f0a4a5b9a6a197c0f6bbe11b8ae16934e5eecd76a486b6e4e34786ebbb334d4ddabf7340c9f13d4946cad4e162db49205a3fbf04fa064938bf6029e0f
|
data/Gemfile.lock
CHANGED
data/config/tlc.yaml
CHANGED
@@ -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
|
155
|
-
|
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
|
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
|
@@ -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
|
data/lib/rsmp/collect/query.rb
CHANGED
@@ -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
|
-
@
|
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
|
-
|
25
|
-
|
26
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
data/lib/rsmp/version.rb
CHANGED
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.
|
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-
|
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
|