rsmp 0.37.0 → 0.38.0
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 +4 -4
- data/.devcontainer/devcontainer.json +22 -0
- data/.github/workflows/rubocop.yaml +17 -0
- data/.gitignore +5 -6
- data/.rubocop.yml +80 -0
- data/Gemfile +13 -1
- data/Gemfile.lock +34 -1
- data/Rakefile +3 -3
- data/lib/rsmp/cli.rb +147 -124
- data/lib/rsmp/collect/ack_collector.rb +8 -7
- data/lib/rsmp/collect/aggregated_status_collector.rb +4 -4
- data/lib/rsmp/collect/alarm_collector.rb +31 -23
- data/lib/rsmp/collect/alarm_matcher.rb +3 -3
- data/lib/rsmp/collect/collector/logging.rb +17 -0
- data/lib/rsmp/collect/collector/reporting.rb +44 -0
- data/lib/rsmp/collect/collector/status.rb +34 -0
- data/lib/rsmp/collect/collector.rb +69 -150
- data/lib/rsmp/collect/command_matcher.rb +19 -6
- data/lib/rsmp/collect/command_response_collector.rb +7 -7
- data/lib/rsmp/collect/distributor.rb +14 -11
- data/lib/rsmp/collect/filter.rb +31 -15
- data/lib/rsmp/collect/matcher.rb +7 -11
- data/lib/rsmp/collect/queue.rb +4 -4
- data/lib/rsmp/collect/receiver.rb +10 -12
- data/lib/rsmp/collect/state_collector.rb +116 -77
- data/lib/rsmp/collect/status_collector.rb +6 -6
- data/lib/rsmp/collect/status_matcher.rb +17 -7
- data/lib/rsmp/{alarm_state.rb → component/alarm_state.rb} +76 -37
- data/lib/rsmp/{component.rb → component/component.rb} +15 -15
- data/lib/rsmp/component/component_base.rb +89 -0
- data/lib/rsmp/component/component_proxy.rb +75 -0
- data/lib/rsmp/component/components.rb +63 -0
- data/lib/rsmp/convert/export/json_schema.rb +116 -110
- data/lib/rsmp/convert/import/yaml.rb +21 -18
- data/lib/rsmp/{rsmp.rb → helpers/clock.rb} +5 -6
- data/lib/rsmp/{deep_merge.rb → helpers/deep_merge.rb} +2 -1
- data/lib/rsmp/helpers/error.rb +71 -0
- data/lib/rsmp/{inspect.rb → helpers/inspect.rb} +6 -10
- data/lib/rsmp/log/archive.rb +98 -0
- data/lib/rsmp/log/colorization.rb +41 -0
- data/lib/rsmp/log/filtering.rb +54 -0
- data/lib/rsmp/log/logger.rb +206 -0
- data/lib/rsmp/{logging.rb → log/logging.rb} +5 -7
- data/lib/rsmp/message.rb +159 -148
- data/lib/rsmp/{node.rb → node/node.rb} +19 -17
- data/lib/rsmp/{protocol.rb → node/protocol.rb} +5 -3
- data/lib/rsmp/node/site/site.rb +195 -0
- data/lib/rsmp/node/supervisor/modules/configuration.rb +59 -0
- data/lib/rsmp/node/supervisor/modules/connection.rb +140 -0
- data/lib/rsmp/node/supervisor/modules/sites.rb +64 -0
- data/lib/rsmp/node/supervisor/supervisor.rb +72 -0
- data/lib/rsmp/{task.rb → node/task.rb} +12 -14
- data/lib/rsmp/proxy/modules/acknowledgements.rb +144 -0
- data/lib/rsmp/proxy/modules/receive.rb +119 -0
- data/lib/rsmp/proxy/modules/send.rb +76 -0
- data/lib/rsmp/proxy/modules/state.rb +25 -0
- data/lib/rsmp/proxy/modules/tasks.rb +105 -0
- data/lib/rsmp/proxy/modules/versions.rb +69 -0
- data/lib/rsmp/proxy/modules/watchdogs.rb +66 -0
- data/lib/rsmp/proxy/proxy.rb +199 -0
- data/lib/rsmp/proxy/site/modules/aggregated_status.rb +52 -0
- data/lib/rsmp/proxy/site/modules/alarms.rb +27 -0
- data/lib/rsmp/proxy/site/modules/commands.rb +31 -0
- data/lib/rsmp/proxy/site/modules/status.rb +110 -0
- data/lib/rsmp/proxy/site/site_proxy.rb +205 -0
- data/lib/rsmp/proxy/supervisor/modules/aggregated_status.rb +47 -0
- data/lib/rsmp/proxy/supervisor/modules/alarms.rb +73 -0
- data/lib/rsmp/proxy/supervisor/modules/commands.rb +53 -0
- data/lib/rsmp/proxy/supervisor/modules/status.rb +204 -0
- data/lib/rsmp/proxy/supervisor/supervisor_proxy.rb +178 -0
- data/lib/rsmp/tlc/detector_logic.rb +18 -34
- data/lib/rsmp/tlc/input_states.rb +126 -0
- data/lib/rsmp/tlc/modules/detector_logics.rb +50 -0
- data/lib/rsmp/tlc/modules/display.rb +78 -0
- data/lib/rsmp/tlc/modules/helpers.rb +41 -0
- data/lib/rsmp/tlc/modules/inputs.rb +173 -0
- data/lib/rsmp/tlc/modules/modes.rb +253 -0
- data/lib/rsmp/tlc/modules/outputs.rb +30 -0
- data/lib/rsmp/tlc/modules/plans.rb +218 -0
- data/lib/rsmp/tlc/modules/signal_groups.rb +109 -0
- data/lib/rsmp/tlc/modules/startup_sequence.rb +22 -0
- data/lib/rsmp/tlc/modules/system.rb +140 -0
- data/lib/rsmp/tlc/modules/traffic_data.rb +49 -0
- data/lib/rsmp/tlc/signal_group.rb +37 -41
- data/lib/rsmp/tlc/signal_plan.rb +14 -11
- data/lib/rsmp/tlc/signal_priority.rb +39 -35
- data/lib/rsmp/tlc/startup_sequence.rb +59 -0
- data/lib/rsmp/tlc/traffic_controller.rb +38 -1010
- data/lib/rsmp/tlc/traffic_controller_site.rb +58 -57
- data/lib/rsmp/version.rb +1 -1
- data/lib/rsmp.rb +82 -48
- data/rsmp.gemspec +24 -31
- metadata +79 -139
- data/lib/rsmp/archive.rb +0 -76
- data/lib/rsmp/collect/message_matchers.rb +0 -0
- data/lib/rsmp/component_base.rb +0 -87
- data/lib/rsmp/component_proxy.rb +0 -57
- data/lib/rsmp/components.rb +0 -65
- data/lib/rsmp/error.rb +0 -71
- data/lib/rsmp/logger.rb +0 -216
- data/lib/rsmp/proxy.rb +0 -693
- data/lib/rsmp/site.rb +0 -188
- data/lib/rsmp/site_proxy.rb +0 -389
- data/lib/rsmp/supervisor.rb +0 -302
- data/lib/rsmp/supervisor_proxy.rb +0 -510
- data/lib/rsmp/tlc/inputs.rb +0 -134
data/lib/rsmp/message.rb
CHANGED
|
@@ -5,69 +5,64 @@ module RSMP
|
|
|
5
5
|
class Message
|
|
6
6
|
include Inspect
|
|
7
7
|
|
|
8
|
-
attr_reader :now, :attributes, :out
|
|
9
|
-
attr_reader :timestamp # this is an internal timestamp recording when we receive/send
|
|
8
|
+
attr_reader :now, :attributes, :out, :timestamp # this is an internal timestamp recording when we receive/send
|
|
10
9
|
attr_accessor :json, :direction
|
|
11
10
|
|
|
12
11
|
def self.make_m_id
|
|
13
|
-
SecureRandom.uuid
|
|
12
|
+
SecureRandom.uuid
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
def self.parse_attributes
|
|
15
|
+
def self.parse_attributes(json)
|
|
17
16
|
raise ArgumentError unless json
|
|
17
|
+
|
|
18
18
|
JSON.parse json
|
|
19
19
|
rescue JSON::ParserError
|
|
20
20
|
raise InvalidPacket, bin_to_chars(json)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def self.build
|
|
23
|
+
def self.build(attributes, json)
|
|
24
24
|
validate_message_type attributes
|
|
25
|
-
|
|
26
|
-
when "MessageAck"
|
|
27
|
-
message = MessageAck.new attributes
|
|
28
|
-
when "MessageNotAck"
|
|
29
|
-
message = MessageNotAck.new attributes
|
|
30
|
-
when "Version"
|
|
31
|
-
message = Version.new attributes
|
|
32
|
-
when "AggregatedStatus"
|
|
33
|
-
message = AggregatedStatus.new attributes
|
|
34
|
-
when "AggregatedStatusRequest"
|
|
35
|
-
message = AggregatedStatusRequest.new attributes
|
|
36
|
-
when "Watchdog"
|
|
37
|
-
message = Watchdog.new attributes
|
|
38
|
-
when "Alarm"
|
|
39
|
-
message = self.build_alarm attributes
|
|
40
|
-
when "CommandRequest"
|
|
41
|
-
message = CommandRequest.new attributes
|
|
42
|
-
when "CommandResponse"
|
|
43
|
-
message = CommandResponse.new attributes
|
|
44
|
-
when "StatusRequest"
|
|
45
|
-
message = StatusRequest.new attributes
|
|
46
|
-
when "StatusResponse"
|
|
47
|
-
message = StatusResponse.new attributes
|
|
48
|
-
when "StatusSubscribe"
|
|
49
|
-
message = StatusSubscribe.new attributes
|
|
50
|
-
when "StatusUnsubscribe"
|
|
51
|
-
message = StatusUnsubscribe.new attributes
|
|
52
|
-
when "StatusUpdate"
|
|
53
|
-
message = StatusUpdate.new attributes
|
|
54
|
-
else
|
|
55
|
-
message = Unknown.new attributes
|
|
56
|
-
end
|
|
25
|
+
message = create_message_instance(attributes)
|
|
57
26
|
message.json = json
|
|
58
27
|
message.direction = :in
|
|
59
28
|
message
|
|
60
29
|
end
|
|
61
30
|
|
|
62
|
-
def self.
|
|
63
|
-
|
|
31
|
+
def self.message_types
|
|
32
|
+
{
|
|
33
|
+
'MessageAck' => MessageAck,
|
|
34
|
+
'MessageNotAck' => MessageNotAck,
|
|
35
|
+
'Version' => Version,
|
|
36
|
+
'AggregatedStatus' => AggregatedStatus,
|
|
37
|
+
'AggregatedStatusRequest' => AggregatedStatusRequest,
|
|
38
|
+
'Watchdog' => Watchdog,
|
|
39
|
+
'CommandRequest' => CommandRequest,
|
|
40
|
+
'CommandResponse' => CommandResponse,
|
|
41
|
+
'StatusRequest' => StatusRequest,
|
|
42
|
+
'StatusResponse' => StatusResponse,
|
|
43
|
+
'StatusSubscribe' => StatusSubscribe,
|
|
44
|
+
'StatusUnsubscribe' => StatusUnsubscribe,
|
|
45
|
+
'StatusUpdate' => StatusUpdate
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.create_message_instance(attributes)
|
|
50
|
+
type = attributes['type']
|
|
51
|
+
return build_alarm(attributes) if type == 'Alarm'
|
|
52
|
+
|
|
53
|
+
klass = message_types[type] || Unknown
|
|
54
|
+
klass.new(attributes)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.build_alarm(attributes)
|
|
58
|
+
case attributes['aSp']
|
|
64
59
|
when /^Issue$/i
|
|
65
60
|
AlarmIssue.new attributes
|
|
66
61
|
when /^Request$/i
|
|
67
62
|
AlarmRequest.new attributes
|
|
68
63
|
when /^Acknowledge$/i
|
|
69
64
|
if attributes['ack'] =~ /^acknowledged$/i
|
|
70
|
-
|
|
65
|
+
AlarmAcknowledged.new attributes
|
|
71
66
|
else
|
|
72
67
|
AlarmAcknowledge.new attributes
|
|
73
68
|
end
|
|
@@ -87,84 +82,97 @@ module RSMP
|
|
|
87
82
|
end
|
|
88
83
|
|
|
89
84
|
def type
|
|
90
|
-
@attributes[
|
|
85
|
+
@attributes['type']
|
|
91
86
|
end
|
|
92
87
|
|
|
93
88
|
def m_id
|
|
94
|
-
@attributes[
|
|
89
|
+
@attributes['mId']
|
|
95
90
|
end
|
|
96
91
|
|
|
97
|
-
def self.shorten_m_id
|
|
98
|
-
m_id[0..length-1]
|
|
92
|
+
def self.shorten_m_id(m_id, length = 4)
|
|
93
|
+
m_id[0..(length - 1)]
|
|
99
94
|
end
|
|
100
95
|
|
|
101
96
|
def m_id_short
|
|
102
|
-
Message.shorten_m_id @attributes[
|
|
97
|
+
Message.shorten_m_id @attributes['mId']
|
|
103
98
|
end
|
|
104
99
|
|
|
105
|
-
def attribute
|
|
106
|
-
unless @attributes.key? key #
|
|
107
|
-
maybe = @attributes.find { |k,
|
|
108
|
-
if maybe
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
end
|
|
100
|
+
def attribute(key)
|
|
101
|
+
unless @attributes.key? key # NOTE: that this is not the same as @attributes[key] when
|
|
102
|
+
maybe = @attributes.find { |k, _v| k.downcase == key.downcase }
|
|
103
|
+
raise MissingAttribute, "attribute '#{maybe.first}' should be named '#{key}'" if maybe
|
|
104
|
+
|
|
105
|
+
raise MissingAttribute, "missing attribute '#{key}'"
|
|
106
|
+
|
|
113
107
|
end
|
|
114
108
|
@attributes[key]
|
|
115
109
|
end
|
|
116
110
|
|
|
117
|
-
def self.bin_to_chars(
|
|
118
|
-
out =
|
|
111
|
+
def self.bin_to_chars(str)
|
|
112
|
+
out = str.gsub(/[^[:print:]]/i, '.')
|
|
119
113
|
max = 120
|
|
120
114
|
if out.size <= max
|
|
121
115
|
out
|
|
122
116
|
else
|
|
123
|
-
mid =
|
|
124
|
-
length = (max-mid.size)/2 - 1
|
|
125
|
-
"#{out[0..length]} ... #{out[-length-1
|
|
117
|
+
mid = ' ... '
|
|
118
|
+
length = ((max - mid.size) / 2) - 1
|
|
119
|
+
"#{out[0..length]} ... #{out[(-length - 1)..]}"
|
|
126
120
|
end
|
|
127
121
|
end
|
|
128
122
|
|
|
129
|
-
def self.validate_message_type
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
raise MalformedMessage.new("'mType' must be 'rSMsg', got '#{attributes["mType"]}'") unless attributes["mType"] == "rSMsg"
|
|
134
|
-
raise MalformedMessage.new("'type' is missing") unless attributes["type"]
|
|
135
|
-
raise MalformedMessage.new("'type' must be a String, got #{attributes["type"].class}") unless attributes["type"].is_a? String
|
|
123
|
+
def self.validate_message_type(attributes)
|
|
124
|
+
validate_attributes_structure(attributes)
|
|
125
|
+
validate_mtype_field(attributes)
|
|
126
|
+
validate_type_field(attributes)
|
|
136
127
|
end
|
|
137
128
|
|
|
138
|
-
def
|
|
139
|
-
|
|
140
|
-
|
|
129
|
+
def self.validate_attributes_structure(attributes)
|
|
130
|
+
raise MalformedMessage, "JSON must be a Hash, got #{attributes.class} " unless attributes.is_a?(Hash)
|
|
131
|
+
end
|
|
141
132
|
|
|
142
|
-
|
|
133
|
+
def self.validate_mtype_field(attributes)
|
|
134
|
+
mtype = attributes['mType']
|
|
135
|
+
raise MalformedMessage, "'mType' is missing" unless mtype
|
|
136
|
+
raise MalformedMessage, "'mType' must be a String, got #{mtype.class}" unless mtype.is_a?(String)
|
|
137
|
+
raise MalformedMessage, "'mType' must be 'rSMsg', got '#{mtype}'" unless mtype == 'rSMsg'
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def self.validate_type_field(attributes)
|
|
141
|
+
type = attributes['type']
|
|
142
|
+
raise MalformedMessage, "'type' is missing" unless type
|
|
143
|
+
raise MalformedMessage, "'type' must be a String, got #{type.class}" unless type.is_a?(String)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def initialize(attributes = {})
|
|
147
|
+
@timestamp = Time.now # this timestamp is for internal use, and does not use the clock
|
|
148
|
+
# in the node, which can be set by an rsmp supervisor
|
|
149
|
+
|
|
150
|
+
@attributes = { 'mType' => 'rSMsg' }.merge attributes
|
|
143
151
|
|
|
144
152
|
ensure_message_id
|
|
145
153
|
end
|
|
146
154
|
|
|
147
155
|
def ensure_message_id
|
|
148
156
|
# if message id is empty, generate a new one
|
|
149
|
-
@attributes[
|
|
157
|
+
@attributes['mId'] ||= Message.make_m_id
|
|
150
158
|
end
|
|
151
159
|
|
|
152
|
-
def validate
|
|
160
|
+
def validate(schemas)
|
|
153
161
|
errors = RSMP::Schema.validate attributes, schemas
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
162
|
+
return unless errors
|
|
163
|
+
|
|
164
|
+
error_string = errors.map { |item| item.reject { |e| e == '' } }.compact.join(', ').strip
|
|
165
|
+
err = SchemaError.new error_string.to_s
|
|
166
|
+
err.schemas = schemas
|
|
167
|
+
raise err
|
|
160
168
|
end
|
|
161
169
|
|
|
162
|
-
def validate_type
|
|
163
|
-
@attributes[
|
|
170
|
+
def validate_type?
|
|
171
|
+
@attributes['mType'] == 'rSMsg'
|
|
164
172
|
end
|
|
165
173
|
|
|
166
|
-
def validate_id
|
|
167
|
-
|
|
174
|
+
def validate_id?
|
|
175
|
+
!(@attributes['mId'] =~ /[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}/i).nil?
|
|
168
176
|
end
|
|
169
177
|
|
|
170
178
|
def valid?
|
|
@@ -181,26 +189,27 @@ module RSMP
|
|
|
181
189
|
}
|
|
182
190
|
@json = JSON.generate @attributes, options
|
|
183
191
|
end
|
|
184
|
-
|
|
185
192
|
end
|
|
186
193
|
|
|
187
194
|
class Malformed < Message
|
|
188
|
-
|
|
195
|
+
# rubocop:disable Lint/MissingSuper
|
|
196
|
+
def initialize(attributes = {})
|
|
189
197
|
# don't call super, just copy (potentially invalid) attributes
|
|
190
198
|
@attributes = {}
|
|
191
199
|
@invalid_attributes = attributes
|
|
192
200
|
end
|
|
201
|
+
# rubocop:enable Lint/MissingSuper
|
|
193
202
|
end
|
|
194
203
|
|
|
195
204
|
class Version < Message
|
|
196
|
-
def initialize
|
|
205
|
+
def initialize(attributes = {})
|
|
197
206
|
super({
|
|
198
|
-
|
|
207
|
+
'type' => 'Version'
|
|
199
208
|
}.merge attributes)
|
|
200
209
|
end
|
|
201
210
|
|
|
202
211
|
def versions
|
|
203
|
-
attribute(
|
|
212
|
+
attribute('RSMP').map { |item| item['vers'] }
|
|
204
213
|
end
|
|
205
214
|
end
|
|
206
215
|
|
|
@@ -208,111 +217,113 @@ module RSMP
|
|
|
208
217
|
end
|
|
209
218
|
|
|
210
219
|
class AggregatedStatus < Message
|
|
211
|
-
def initialize
|
|
220
|
+
def initialize(attributes = {})
|
|
212
221
|
super({
|
|
213
|
-
|
|
222
|
+
'type' => 'AggregatedStatus'
|
|
214
223
|
}.merge attributes)
|
|
215
224
|
end
|
|
216
225
|
end
|
|
217
226
|
|
|
218
227
|
class AggregatedStatusRequest < Message
|
|
219
|
-
def initialize
|
|
228
|
+
def initialize(attributes = {})
|
|
220
229
|
super({
|
|
221
|
-
|
|
230
|
+
'type' => 'AggregatedStatusRequest'
|
|
222
231
|
}.merge attributes)
|
|
223
232
|
end
|
|
224
233
|
end
|
|
225
234
|
|
|
226
235
|
class Alarm < Message
|
|
227
|
-
def initialize
|
|
236
|
+
def initialize(attributes = {})
|
|
228
237
|
super({
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
238
|
+
'type' => 'Alarm',
|
|
239
|
+
'ntsOId' => '',
|
|
240
|
+
'xNId' => '',
|
|
241
|
+
'xACId' => '',
|
|
242
|
+
'xNACId' => ''
|
|
234
243
|
}.merge attributes)
|
|
235
244
|
end
|
|
236
245
|
|
|
237
|
-
def differ?
|
|
238
|
-
%w
|
|
246
|
+
def differ?(from)
|
|
247
|
+
%w[aSp aCId ack aS sS aTs cat pri].each do |key|
|
|
239
248
|
return true if attribute(key).downcase != from.attribute(key).downcase
|
|
240
249
|
end
|
|
241
250
|
return true if attribute('rvs') != from.attribute('rvs')
|
|
251
|
+
|
|
242
252
|
false
|
|
243
253
|
end
|
|
244
254
|
end
|
|
245
255
|
|
|
246
256
|
class AlarmIssue < Alarm
|
|
247
|
-
def initialize
|
|
257
|
+
def initialize(attributes = {})
|
|
248
258
|
super({
|
|
249
|
-
|
|
259
|
+
'aSp' => 'Issue'
|
|
250
260
|
}.merge attributes)
|
|
251
261
|
end
|
|
252
262
|
end
|
|
253
263
|
|
|
254
264
|
class AlarmRequest < Alarm
|
|
255
|
-
def initialize
|
|
265
|
+
def initialize(attributes = {})
|
|
256
266
|
super({
|
|
257
|
-
|
|
267
|
+
'aSp' => 'Request'
|
|
258
268
|
}.merge attributes)
|
|
259
269
|
end
|
|
260
270
|
end
|
|
261
271
|
|
|
262
272
|
class AlarmAcknowledge < Alarm
|
|
263
|
-
def initialize
|
|
273
|
+
def initialize(attributes = {})
|
|
264
274
|
super({
|
|
265
|
-
|
|
275
|
+
'aSp' => 'Acknowledge'
|
|
266
276
|
}.merge attributes)
|
|
267
277
|
end
|
|
268
278
|
end
|
|
269
279
|
|
|
270
280
|
class AlarmAcknowledged < Alarm
|
|
271
|
-
def initialize
|
|
281
|
+
def initialize(attributes = {})
|
|
272
282
|
super({
|
|
273
|
-
|
|
274
|
-
|
|
283
|
+
'aSp' => 'Acknowledge',
|
|
284
|
+
'ack' => 'acknowledged'
|
|
275
285
|
}.merge attributes)
|
|
276
286
|
end
|
|
277
287
|
end
|
|
288
|
+
|
|
278
289
|
class AlarmSuspend < Alarm
|
|
279
|
-
def initialize
|
|
290
|
+
def initialize(attributes = {})
|
|
280
291
|
super({
|
|
281
|
-
|
|
292
|
+
'aSp' => 'Suspend'
|
|
282
293
|
}.merge attributes)
|
|
283
294
|
end
|
|
284
295
|
end
|
|
285
296
|
|
|
286
297
|
class AlarmSuspended < Alarm
|
|
287
|
-
def initialize
|
|
298
|
+
def initialize(attributes = {})
|
|
288
299
|
super({
|
|
289
|
-
|
|
290
|
-
|
|
300
|
+
'aSp' => 'Suspend',
|
|
301
|
+
'sS' => 'Suspended'
|
|
291
302
|
}.merge attributes)
|
|
292
303
|
end
|
|
293
304
|
end
|
|
294
305
|
|
|
295
306
|
class AlarmResume < Alarm
|
|
296
|
-
def initialize
|
|
307
|
+
def initialize(attributes = {})
|
|
297
308
|
super({
|
|
298
|
-
|
|
309
|
+
'aSp' => 'Resume'
|
|
299
310
|
}.merge attributes)
|
|
300
311
|
end
|
|
301
312
|
end
|
|
302
313
|
|
|
303
314
|
class AlarmResumed < Alarm
|
|
304
|
-
def initialize
|
|
315
|
+
def initialize(attributes = {})
|
|
305
316
|
super({
|
|
306
|
-
|
|
307
|
-
|
|
317
|
+
'aSp' => 'Suspend',
|
|
318
|
+
'sS' => 'notSuspended'
|
|
308
319
|
}.merge attributes)
|
|
309
320
|
end
|
|
310
321
|
end
|
|
311
322
|
|
|
312
323
|
class Watchdog < Message
|
|
313
|
-
def initialize
|
|
324
|
+
def initialize(attributes = {})
|
|
314
325
|
super({
|
|
315
|
-
|
|
326
|
+
'type' => 'Watchdog'
|
|
316
327
|
}.merge attributes)
|
|
317
328
|
end
|
|
318
329
|
end
|
|
@@ -320,26 +331,27 @@ module RSMP
|
|
|
320
331
|
class MessageAcking < Message
|
|
321
332
|
attr_reader :original
|
|
322
333
|
|
|
323
|
-
def self.build_from
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
334
|
+
def self.build_from(message)
|
|
335
|
+
new({
|
|
336
|
+
'oMId' => message.attributes['mId']
|
|
337
|
+
})
|
|
327
338
|
end
|
|
328
339
|
|
|
329
|
-
def original=
|
|
340
|
+
def original=(message)
|
|
330
341
|
raise InvalidArgument unless message
|
|
342
|
+
|
|
331
343
|
@original = message
|
|
332
344
|
end
|
|
333
345
|
|
|
334
|
-
def validate_id
|
|
346
|
+
def validate_id?
|
|
335
347
|
true
|
|
336
348
|
end
|
|
337
349
|
end
|
|
338
350
|
|
|
339
351
|
class MessageAck < MessageAcking
|
|
340
|
-
def initialize
|
|
352
|
+
def initialize(attributes = {})
|
|
341
353
|
super({
|
|
342
|
-
|
|
354
|
+
'type' => 'MessageAck'
|
|
343
355
|
}.merge attributes)
|
|
344
356
|
end
|
|
345
357
|
|
|
@@ -349,69 +361,68 @@ module RSMP
|
|
|
349
361
|
end
|
|
350
362
|
|
|
351
363
|
class MessageNotAck < MessageAcking
|
|
352
|
-
def initialize
|
|
364
|
+
def initialize(attributes = {})
|
|
353
365
|
super({
|
|
354
|
-
|
|
355
|
-
|
|
366
|
+
'type' => 'MessageNotAck',
|
|
367
|
+
'rea' => 'Unknown reason'
|
|
356
368
|
}.merge attributes)
|
|
357
|
-
@attributes.delete
|
|
358
|
-
|
|
369
|
+
@attributes.delete 'mId'
|
|
370
|
+
end
|
|
359
371
|
end
|
|
360
372
|
|
|
361
373
|
class CommandRequest < Message
|
|
362
|
-
def initialize
|
|
374
|
+
def initialize(attributes = {})
|
|
363
375
|
super({
|
|
364
|
-
|
|
376
|
+
'type' => 'CommandRequest'
|
|
365
377
|
}.merge attributes)
|
|
366
378
|
end
|
|
367
379
|
end
|
|
368
380
|
|
|
369
381
|
class CommandResponse < Message
|
|
370
|
-
def initialize
|
|
382
|
+
def initialize(attributes = {})
|
|
371
383
|
super({
|
|
372
|
-
|
|
384
|
+
'type' => 'CommandResponse'
|
|
373
385
|
}.merge attributes)
|
|
374
386
|
end
|
|
375
387
|
end
|
|
376
388
|
|
|
377
389
|
class StatusRequest < Message
|
|
378
|
-
def initialize
|
|
390
|
+
def initialize(attributes = {})
|
|
379
391
|
super({
|
|
380
|
-
|
|
392
|
+
'type' => 'StatusRequest'
|
|
381
393
|
}.merge attributes)
|
|
382
394
|
end
|
|
383
395
|
end
|
|
384
396
|
|
|
385
397
|
class StatusResponse < Message
|
|
386
|
-
def initialize
|
|
398
|
+
def initialize(attributes = {})
|
|
387
399
|
super({
|
|
388
|
-
|
|
400
|
+
'type' => 'StatusResponse'
|
|
389
401
|
}.merge attributes)
|
|
390
402
|
end
|
|
391
403
|
end
|
|
392
404
|
|
|
393
405
|
class StatusSubscribe < Message
|
|
394
|
-
def initialize
|
|
406
|
+
def initialize(attributes = {})
|
|
395
407
|
super({
|
|
396
|
-
|
|
408
|
+
'type' => 'StatusSubscribe'
|
|
397
409
|
}.merge attributes)
|
|
398
410
|
end
|
|
399
411
|
end
|
|
400
412
|
|
|
401
413
|
class StatusUnsubscribe < Message
|
|
402
|
-
def initialize
|
|
414
|
+
def initialize(attributes = {})
|
|
403
415
|
super({
|
|
404
|
-
|
|
416
|
+
'type' => 'StatusUnsubscribe'
|
|
405
417
|
}.merge attributes)
|
|
406
418
|
end
|
|
407
419
|
end
|
|
408
420
|
|
|
409
421
|
class StatusUpdate < Message
|
|
410
|
-
def initialize
|
|
422
|
+
def initialize(attributes = {})
|
|
411
423
|
super({
|
|
412
|
-
|
|
424
|
+
'type' => 'StatusUpdate'
|
|
413
425
|
}.merge attributes)
|
|
414
426
|
end
|
|
415
427
|
end
|
|
416
|
-
|
|
417
|
-
end
|
|
428
|
+
end
|
|
@@ -8,7 +8,7 @@ module RSMP
|
|
|
8
8
|
|
|
9
9
|
attr_reader :archive, :logger, :task, :deferred, :error_queue, :clock, :collector
|
|
10
10
|
|
|
11
|
-
def initialize
|
|
11
|
+
def initialize(options = {})
|
|
12
12
|
initialize_logging options
|
|
13
13
|
initialize_task
|
|
14
14
|
@deferred = []
|
|
@@ -24,55 +24,57 @@ module RSMP
|
|
|
24
24
|
|
|
25
25
|
# stop proxies, then call super
|
|
26
26
|
def stop_subtasks
|
|
27
|
-
@proxies.each
|
|
27
|
+
@proxies.each(&:stop)
|
|
28
28
|
@proxies.clear
|
|
29
29
|
super
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def ignore_errors
|
|
33
|
-
was
|
|
32
|
+
def ignore_errors(classes)
|
|
33
|
+
was = @ignore_errors
|
|
34
|
+
@ignore_errors = [classes].flatten
|
|
34
35
|
yield
|
|
35
36
|
ensure
|
|
36
37
|
@ignore_errors = was
|
|
37
38
|
end
|
|
38
39
|
|
|
39
|
-
def distribute_error
|
|
40
|
-
return if @ignore_errors.find { |klass|
|
|
40
|
+
def distribute_error(error, options = {})
|
|
41
|
+
return if @ignore_errors.find { |klass| error.is_a? klass }
|
|
42
|
+
|
|
41
43
|
if options[:level] == :internal
|
|
42
|
-
log ["#{
|
|
44
|
+
log ["#{error} in task: #{Async::Task.current}", error.backtrace].flatten.join("\n"),
|
|
45
|
+
level: :error
|
|
43
46
|
end
|
|
44
|
-
@error_queue.enqueue
|
|
47
|
+
@error_queue.enqueue error
|
|
45
48
|
end
|
|
46
49
|
|
|
47
|
-
def defer
|
|
50
|
+
def defer(key, item = nil)
|
|
48
51
|
@deferred << [key, item]
|
|
49
52
|
end
|
|
50
53
|
|
|
51
54
|
def process_deferred
|
|
52
|
-
cloned = @deferred.clone
|
|
55
|
+
cloned = @deferred.clone # clone in case do_deferred restarts the current task
|
|
53
56
|
@deferred.clear
|
|
54
57
|
cloned.each do |pair|
|
|
55
58
|
do_deferred pair.first, pair.last
|
|
56
59
|
end
|
|
57
60
|
end
|
|
58
61
|
|
|
59
|
-
def do_deferred
|
|
60
|
-
end
|
|
62
|
+
def do_deferred(key, item = nil); end
|
|
61
63
|
|
|
62
64
|
def clear_deferred
|
|
63
65
|
@deferred.clear
|
|
64
66
|
end
|
|
65
67
|
|
|
66
|
-
def check_required_settings
|
|
67
|
-
raise ArgumentError
|
|
68
|
+
def check_required_settings(settings, required)
|
|
69
|
+
raise ArgumentError, 'Settings is empty' unless settings
|
|
70
|
+
|
|
68
71
|
required.each do |setting|
|
|
69
|
-
raise ArgumentError
|
|
72
|
+
raise ArgumentError, "Missing setting: #{setting}" unless settings.include? setting.to_s
|
|
70
73
|
end
|
|
71
74
|
end
|
|
72
75
|
|
|
73
76
|
def author
|
|
74
77
|
site_id
|
|
75
78
|
end
|
|
76
|
-
|
|
77
79
|
end
|
|
78
|
-
end
|
|
80
|
+
end
|
|
@@ -16,7 +16,7 @@ module RSMP
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def peek_line
|
|
19
|
-
@peeked
|
|
19
|
+
@peeked ||= read
|
|
20
20
|
@peeked
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -24,12 +24,14 @@ module RSMP
|
|
|
24
24
|
@stream.write(data + RSMP::Proxy::WRAPPING_DELIMITER)
|
|
25
25
|
@stream.flush unless @stream.closed?
|
|
26
26
|
end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
protected
|
|
29
|
+
|
|
29
30
|
def read
|
|
30
31
|
line = @stream.gets(RSMP::Proxy::WRAPPING_DELIMITER)
|
|
31
32
|
return nil unless line
|
|
33
|
+
|
|
32
34
|
line.chomp(RSMP::Proxy::WRAPPING_DELIMITER)
|
|
33
35
|
end
|
|
34
36
|
end
|
|
35
|
-
end
|
|
37
|
+
end
|