Class: RSMP::SiteProxy
Constant Summary
Constants inherited
from Proxy
Proxy::WRAPPING_DELIMITER
Instance Attribute Summary collapse
Attributes included from Components
#components, #main
Attributes inherited from Proxy
#archive, #collector, #connection_info, #ip, #port, #state, #sxl
Attributes included from Task
#task
Attributes included from Notifier
#listeners
Attributes included from Logging
#archive, #logger
Instance Method Summary
collapse
-
#acknowledged_first_ingoing(message) ⇒ Object
-
#acknowledged_first_outgoing(message) ⇒ Object
-
#aggregated_status_changed(component, options = {}) ⇒ Object
-
#build_component(id:, type:, settings: {}) ⇒ Object
-
#check_site_ids(message) ⇒ Object
-
#check_sxl_version(message) ⇒ Object
-
#find_site_settings(site_id) ⇒ Object
-
#handshake_complete ⇒ Object
-
#infer_component_type(component_id) ⇒ Object
-
#initialize(options) ⇒ SiteProxy
constructor
A new instance of SiteProxy.
-
#inspect ⇒ Object
-
#node ⇒ Object
-
#notify_error(e, options = {}) ⇒ Object
-
#process_aggregated_status(message) ⇒ Object
-
#process_alarm(message) ⇒ Object
-
#process_command_response(message) ⇒ Object
-
#process_message(message) ⇒ Object
-
#process_status_response(message) ⇒ Object
-
#process_status_update(message) ⇒ Object
-
#process_version(message) ⇒ Object
-
#process_watchdog(message) ⇒ Object
-
#request_aggregated_status(component, options = {}) ⇒ Object
-
#request_status(component, status_list, options = {}) ⇒ Object
-
#revive(options) ⇒ Object
-
#run ⇒ Object
handle communication when we're created, the socket is already open.
-
#send_alarm_acknowledgement(component, alarm_code, options = {}) ⇒ Object
-
#send_command(component, command_list, options = {}) ⇒ Object
-
#set_watchdog_interval(interval) ⇒ Object
-
#setup_site_settings ⇒ Object
-
#site_ids_changed ⇒ Object
-
#subscribe_to_status(component_id, status_list, options = {}) ⇒ Object
-
#sxl_version ⇒ Object
-
#unsubscribe_to_status(component_id, status_list, options = {}) ⇒ Object
-
#validate_aggregated_status(message, se) ⇒ Object
-
#validate_ready(action) ⇒ Object
-
#version_accepted(message) ⇒ Object
-
#version_acknowledged ⇒ Object
Methods included from Components
#add_component, #check_main_component, #find_component, #initialize_components, #setup_components
Methods inherited from Proxy
#acknowledge, #author, #buffer_message, #check_ack_timeout, #check_ingoing_acknowledged, #check_outgoing_acknowledged, #check_rsmp_version, #check_watchdog_timeout, #clear, #clock, #close, #close_socket, #close_stream, #connected?, #disconnect, #disconnected?, #dont_acknowledge, #dont_expect_acknowledgement, #expect_acknowledgement, #expect_version_message, #extraneous_version, #find_original_for_message, #get_schemas, #log, #log_acknowledgement_for_original, #log_acknowledgement_for_unknown, #log_send, #process_ack, #process_deferred, #process_not_ack, #process_packet, #read_line, #ready?, #rsmp_versions, #run_reader, #run_timer, #send_and_optionally_collect, #send_message, #send_version, #send_watchdog, #set_nts_message_attributes, #set_state, #setup, #should_validate_ingoing_message?, #start_reader, #start_timer, #start_watchdog, #state_changed, #stop_reader, #stop_subtasks, #stop_task, #stop_timer, #timer, #verify_sequence, version_requirement_met?, #wait_for_reader, #wait_for_state, #watchdog_send_timer, #will_not_handle
Methods included from Task
#initialize_task, #restart, #start, #stop, #stop_subtasks, #stop_task, #task_status, #wait, #wait_for_condition
Methods included from Inspect
#inspector
Methods included from Notifier
#add_listener, #clear_deferred_notify, #deferred_notify, #dequeue_notify, #distribute_error, #initialize_distributor, #notify, #notify_without_defer, #remove_listener
Methods included from Logging
#author, #initialize_logging, #log
Constructor Details
#initialize(options) ⇒ SiteProxy
Returns a new instance of SiteProxy.
9
10
11
12
13
14
15
16
|
# File 'lib/rsmp/site_proxy.rb', line 9
def initialize options
super options.merge(node:options[:supervisor])
initialize_components
@supervisor = options[:supervisor]
@settings = @supervisor.supervisor_settings.clone
@site_id = options[:site_id]
@status_subscriptions = {}
end
|
Instance Attribute Details
#site_id ⇒ Object
Returns the value of attribute site_id.
7
8
9
|
# File 'lib/rsmp/site_proxy.rb', line 7
def site_id
@site_id
end
|
#supervisor ⇒ Object
Returns the value of attribute supervisor.
7
8
9
|
# File 'lib/rsmp/site_proxy.rb', line 7
def supervisor
@supervisor
end
|
Instance Method Details
#acknowledged_first_ingoing(message) ⇒ Object
96
97
98
99
100
101
|
# File 'lib/rsmp/site_proxy.rb', line 96
def acknowledged_first_ingoing message
case message.type
when "Watchdog"
send_watchdog
end
end
|
#acknowledged_first_outgoing(message) ⇒ Object
103
104
105
106
107
108
|
# File 'lib/rsmp/site_proxy.rb', line 103
def acknowledged_first_outgoing message
case message.type
when "Watchdog"
handshake_complete
end
end
|
#aggregated_status_changed(component, options = {}) ⇒ Object
154
155
156
|
# File 'lib/rsmp/site_proxy.rb', line 154
def aggregated_status_changed component, options={}
@supervisor.aggregated_status_changed self, component
end
|
#build_component(id:, type:, settings: {}) ⇒ Object
379
380
381
382
383
384
385
386
387
|
# File 'lib/rsmp/site_proxy.rb', line 379
def build_component id:, type:, settings:{}
settings ||= {}
if type == 'main'
ComponentProxy.new id:id, node: self, grouped: true,
ntsOId: settings['ntsOId'], xNId: settings['xNId']
else
ComponentProxy.new id:id, node: self, grouped: false
end
end
|
#check_site_ids(message) ⇒ Object
340
341
342
343
344
345
346
347
|
# File 'lib/rsmp/site_proxy.rb', line 340
def check_site_ids message
site_id = message.attribute("siteId").map { |item| item["sId"] }.first
@supervisor.check_site_id site_id
@site_id = site_id
setup_site_settings
site_ids_changed
end
|
#check_sxl_version(message) ⇒ Object
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
# File 'lib/rsmp/site_proxy.rb', line 310
def check_sxl_version message
type = 'tlc'
version = message.attribute 'SXL'
RSMP::Schema::find_schema! type, version, lenient: true
@site_sxl_version = message.attribute 'SXL'
rescue RSMP::Schema::UnknownSchemaError => e
dont_acknowledge message, "Rejected #{message.type} message,", "#{e}"
end
|
#find_site_settings(site_id) ⇒ Object
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
# File 'lib/rsmp/site_proxy.rb', line 349
def find_site_settings site_id
if @settings['sites'] && @settings['sites'][@site_id]
log "Using site settings for site id #{@site_id}", level: :debug
return @settings['sites'][@site_id]
end
settings = @settings['guest']
if @settings['guest']
log "Using site settings for guest", level: :debug
return @settings['guest']
end
nil
end
|
#handshake_complete ⇒ Object
48
49
50
51
52
53
|
# File 'lib/rsmp/site_proxy.rb', line 48
def handshake_complete
super
sanitized_sxl_version = RSMP::Schema.sanitize_version(@site_sxl_version)
log "Connection to site #{@site_id} established, using core #{@rsmp_version}, #{@sxl} #{sanitized_sxl_version}", level: :log
start_watchdog
end
|
#infer_component_type(component_id) ⇒ Object
389
390
391
|
# File 'lib/rsmp/site_proxy.rb', line 389
def infer_component_type component_id
ComponentProxy
end
|
#inspect ⇒ Object
38
39
40
41
42
|
# File 'lib/rsmp/site_proxy.rb', line 38
def inspect
"#<#{self.class.name}:#{self.object_id}, #{inspector(
:@acknowledgements,:@settings,:@site_settings,:@components
)}>"
end
|
#node ⇒ Object
44
45
46
|
# File 'lib/rsmp/site_proxy.rb', line 44
def node
supervisor
end
|
#notify_error(e, options = {}) ⇒ Object
374
375
376
377
|
# File 'lib/rsmp/site_proxy.rb', line 374
def notify_error e, options={}
@supervisor.notify_error e, options if @supervisor
distribute_error e, options
end
|
#process_aggregated_status(message) ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/rsmp/site_proxy.rb', line 138
def process_aggregated_status message
se = message.attribute("se")
validate_aggregated_status(message,se) == false
c_id = message.attributes["cId"]
component = find_component c_id
unless component
reason = "component #{c_id} not found"
dont_acknowledge message, "Ignoring #{message.type}:", reason
return
end
component.set_aggregated_status_bools se
log "Received #{message.type} status for component #{c_id} [#{component.aggregated_status.join(', ')}]", message: message
acknowledge message
end
|
#process_alarm(message) ⇒ Object
158
159
160
161
162
163
164
165
166
|
# File 'lib/rsmp/site_proxy.rb', line 158
def process_alarm message
component = find_component message.attribute("cId")
status = ["ack","aS","sS"].map { |key| message.attribute(key) }.join(',')
component.handle_alarm message
alarm_code = message.attribute("aCId")
asp = message.attribute("aSp")
log "Received #{message.type}, #{alarm_code} #{asp} [#{status}]", message: message, level: :log
acknowledge message
end
|
#process_command_response(message) ⇒ Object
83
84
85
86
|
# File 'lib/rsmp/site_proxy.rb', line 83
def process_command_response message
log "Received #{message.type}", message: message, level: :log
acknowledge message
end
|
#process_message(message) ⇒ Object
#process_status_response(message) ⇒ Object
202
203
204
205
206
207
|
# File 'lib/rsmp/site_proxy.rb', line 202
def process_status_response message
component = find_component message.attribute("cId")
component.store_status message
log "Received #{message.type}", message: message, level: :log
acknowledge message
end
|
#process_status_update(message) ⇒ Object
271
272
273
274
275
276
277
|
# File 'lib/rsmp/site_proxy.rb', line 271
def process_status_update message
component = find_component message.attribute("cId")
component.check_repeat_values message, @status_subscriptions
component.store_status message
log "Received #{message.type}", message: message, level: :log
acknowledge message
end
|
#process_version(message) ⇒ Object
332
333
334
335
336
337
338
|
# File 'lib/rsmp/site_proxy.rb', line 332
def process_version message
return message if @version_determined
check_site_ids message
check_rsmp_version message
check_sxl_version message
version_accepted message
end
|
#process_watchdog(message) ⇒ Object
171
172
173
|
# File 'lib/rsmp/site_proxy.rb', line 171
def process_watchdog message
super
end
|
#request_aggregated_status(component, options = {}) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/rsmp/site_proxy.rb', line 114
def request_aggregated_status component, options={}
validate_ready 'request aggregated status'
m_id = options[:m_id] || RSMP::Message.make_m_id
message = RSMP::AggregatedStatusRequest.new({
"cId" => component,
"mId" => m_id
})
set_nts_message_attributes message
send_and_optionally_collect message, options do |collect_options|
AggregatedStatusCollector.new(
self,
collect_options.merge(task:@task,m_id: m_id, num:1)
)
end
end
|
#request_status(component, status_list, options = {}) ⇒ Object
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/rsmp/site_proxy.rb', line 179
def request_status component, status_list, options={}
validate_ready 'request status'
m_id = options[:m_id] || RSMP::Message.make_m_id
request_list = status_list.map { |item| item.slice('sCI','n') }
message = RSMP::StatusRequest.new({
"cId" => component,
"sS" => request_list,
"mId" => m_id
})
set_nts_message_attributes message
send_and_optionally_collect message, options do |collect_options|
StatusCollector.new(
self,
status_list,
collect_options.merge(task:@task,m_id: m_id)
)
end
end
|
#revive(options) ⇒ Object
32
33
34
35
36
|
# File 'lib/rsmp/site_proxy.rb', line 32
def revive options
super options
@supervisor = options[:supervisor]
@settings = @supervisor.supervisor_settings.clone
end
|
#run ⇒ Object
handle communication when we're created, the socket is already open
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/rsmp/site_proxy.rb', line 20
def run
set_state :connected
start_reader
wait_for_reader rescue RSMP::ConnectionError => e
log e, level: :error
rescue StandardError => e
notify_error e, level: :internal
ensure
close
end
|
#send_alarm_acknowledgement(component, alarm_code, options = {}) ⇒ Object
279
280
281
282
283
284
285
286
|
# File 'lib/rsmp/site_proxy.rb', line 279
def send_alarm_acknowledgement component, alarm_code, options={}
message = RSMP::AlarmAcknowledged.new({
"cId" => component,
"aCId" => alarm_code,
})
send_message message, validate: options[:validate]
message
end
|
#send_command(component, command_list, options = {}) ⇒ Object
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
# File 'lib/rsmp/site_proxy.rb', line 288
def send_command component, command_list, options={}
validate_ready 'send command'
m_id = options[:m_id] || RSMP::Message.make_m_id
message = RSMP::CommandRequest.new({
"cId" => component,
"arg" => command_list,
"mId" => m_id
})
set_nts_message_attributes message
send_and_optionally_collect message, options do |collect_options|
CommandResponseCollector.new(
self,
command_list,
collect_options.merge(task:@task,m_id: m_id)
)
end
end
|
#set_watchdog_interval(interval) ⇒ Object
306
307
308
|
# File 'lib/rsmp/site_proxy.rb', line 306
def set_watchdog_interval interval
@settings['intervals']['watchdog'] = interval
end
|
#setup_site_settings ⇒ Object
364
365
366
367
368
369
370
371
372
|
# File 'lib/rsmp/site_proxy.rb', line 364
def setup_site_settings
@site_settings = find_site_settings @site_id
if @site_settings
@sxl = @site_settings['sxl']
setup_components @site_settings['components']
else
dont_acknowledge message, 'Rejected', "No config found for site #{@site_id}"
end
end
|
#site_ids_changed ⇒ Object
175
176
177
|
# File 'lib/rsmp/site_proxy.rb', line 175
def site_ids_changed
@supervisor.site_ids_changed
end
|
#subscribe_to_status(component_id, status_list, options = {}) ⇒ Object
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/rsmp/site_proxy.rb', line 209
def subscribe_to_status component_id, status_list, options={}
validate_ready 'subscribe to status'
m_id = options[:m_id] || RSMP::Message.make_m_id
subscribe_list = status_list.map { |item| item.slice('sCI','n','uRt','sOc') }
@status_subscriptions[component_id] ||= {}
subscribe_list.each do |item|
sCI = item["sCI"]
n = item["n"]
uRt = item["uRt"]
sOc = item["sOc"]
@status_subscriptions[component_id][sCI] ||= {}
@status_subscriptions[component_id][sCI][n] ||= {}
@status_subscriptions[component_id][sCI][n]['uRt'] = uRt
@status_subscriptions[component_id][sCI][n]['sOc'] = sOc
end
component = find_component component_id
component.allow_repeat_updates subscribe_list
message = RSMP::StatusSubscribe.new({
"cId" => component_id,
"sS" => subscribe_list,
'mId' => m_id
})
set_nts_message_attributes message
send_and_optionally_collect message, options do |collect_options|
StatusCollector.new(
self,
status_list,
collect_options.merge(task:@task,m_id: m_id)
)
end
end
|
#sxl_version ⇒ Object
326
327
328
329
330
|
# File 'lib/rsmp/site_proxy.rb', line 326
def sxl_version
@site_sxl_version
end
|
#unsubscribe_to_status(component_id, status_list, options = {}) ⇒ Object
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/rsmp/site_proxy.rb', line 248
def unsubscribe_to_status component_id, status_list, options={}
validate_ready 'unsubscribe to status'
status_list.each do |item|
sCI = item["sCI"]
n = item["n"]
if @status_subscriptions.dig(component_id,sCI,n)
@status_subscriptions[component_id][sCI].delete n
@status_subscriptions[component_id].delete(sCI) if @status_subscriptions[component_id][sCI].empty?
@status_subscriptions.delete(component_id) if @status_subscriptions[component_id].empty?
end
end
message = RSMP::StatusUnsubscribe.new({
"cId" => component_id,
"sS" => status_list
})
set_nts_message_attributes message
send_message message, validate: options[:validate]
message
end
|
#validate_aggregated_status(message, se) ⇒ Object
130
131
132
133
134
135
136
|
# File 'lib/rsmp/site_proxy.rb', line 130
def validate_aggregated_status message, se
unless se && se.is_a?(Array) && se.size == 8
reason = "invalid AggregatedStatus, 'se' must be an Array of size 8"
dont_acknowledge message, "Received", reaons
raise InvalidMessage
end
end
|
#validate_ready(action) ⇒ Object
110
111
112
|
# File 'lib/rsmp/site_proxy.rb', line 110
def validate_ready action
raise NotReady.new("Can't #{action} because connection is not ready. (Currently #{@state})") unless ready?
end
|
#version_accepted(message) ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/rsmp/site_proxy.rb', line 88
def version_accepted message
log "Received Version message for site #{@site_id}", message: message, level: :log
start_timer
acknowledge message
send_version @site_id, rsmp_versions
@version_determined = true
end
|
#version_acknowledged ⇒ Object
168
169
|
# File 'lib/rsmp/site_proxy.rb', line 168
def version_acknowledged
end
|