Class: RSMP::SiteProxy
- Includes:
- Components, Modules::AggregatedStatus, Modules::Alarms, Modules::Commands, Modules::Status, SiteProxyConnection, SiteSxlSelection
- Defined in:
- lib/rsmp/proxy/site/site_proxy.rb,
lib/rsmp/proxy/site/modules/alarms.rb,
lib/rsmp/proxy/site/modules/status.rb,
lib/rsmp/proxy/site/modules/commands.rb,
lib/rsmp/proxy/site/modules/aggregated_status.rb
Overview
Handles a supervisor-side proxy for a connected site.
Defined Under Namespace
Modules: Modules
Constant Summary
Constants inherited from Proxy
Instance Attribute Summary collapse
-
#site_id ⇒ Object
readonly
Returns the value of attribute site_id.
-
#supervisor ⇒ Object
readonly
Returns the value of attribute supervisor.
Attributes included from Components
Attributes inherited from Proxy
#accepted_sxls, #archive, #collector, #connection_info, #core_version, #ip, #port, #rejected_sxls, #site_settings, #state, #sxl_interfaces, #sxls
Attributes included from Task
Attributes included from Distributor
Attributes included from Logging
Instance Method Summary collapse
- #acknowledged_first_ingoing(message) ⇒ Object
- #acknowledged_first_outgoing(message) ⇒ Object
- #build_component(id:, type:, settings: {}) ⇒ Object
- #check_site_ids(message) ⇒ Object
- #find_site_settings(_site_id) ⇒ Object
- #handle_interface_message(message) ⇒ Object
- #handled_by_parent?(message) ⇒ Boolean
- #handshake_complete ⇒ Object
- #infer_component_type(_component_id) ⇒ Object
-
#initialize(options) ⇒ SiteProxy
constructor
A new instance of SiteProxy.
- #node ⇒ Object
- #process_component_list(message) ⇒ Object
- #process_message(message) ⇒ Object
- #process_version(message) ⇒ Object
- #rebuild_components_from_list(items) ⇒ Object
- #receive_error(error, options = {}) ⇒ Object
- #record_interface_message(message) ⇒ Object
- #revive(options) ⇒ Object
- #setup_site_settings ⇒ Object
- #site_ids_changed ⇒ Object
- #validate_ready(action) ⇒ Object
- #version_accepted(message) ⇒ Object
- #version_acknowledged ⇒ Object
- #watchdog_interval=(interval) ⇒ Object
Methods included from SiteSxlSelection
#check_sxl_version, #rejected_sxl, #select_legacy_sxl, #select_sxl, #select_sxls
Methods included from SiteProxyConnection
#connect, #open_socket, #reconnect_delay?, #run, #run_accepted_connection, #run_outbound_connection
Methods included from Modules::Commands
#command_collector_list, #process_command_response, #send_command, #send_command_and_collect
Methods included from Modules::Alarms
#process_alarm, #resume_alarm, #send_alarm_acknowledgement, #suspend_alarm
Methods included from Modules::AggregatedStatus
#aggregated_status_changed, #process_aggregated_status, #request_aggregated_status, #request_aggregated_status_and_collect, #validate_aggregated_status
Methods included from Modules::Status
#ensure_subscription_path, #process_status_response, #process_status_update, #remove_subscription_item, #request_status, #request_status_and_collect, #subscribe_to_status, #subscribe_to_status_and_collect, #unsubscribe_from_all, #unsubscribe_to_status, #update_subscription
Methods included from Components
#add_component, #aggregated_status_changed, #check_main_component, #clear_alarm_timestamps, #component_list, #find_component, #initialize_components, #natural_sort_key, #setup_components
Methods inherited from Proxy
#author, #build_sxl_interfaces, #clear, #clock, #close, #close_socket, #close_stream, #command_codes, #command_items, #connected?, #disconnect, #disconnected?, #inspect, #log, #multiple_command_codes?, #now, #primary_sxl, #ready?, #receive_alarms?, #reject_multiple_command_codes, #schemas, #setup, #state_changed, #stop_reader, #stop_subtasks, #stop_task, #stop_timer, #sxl, #sxl_interface, #sxl_interface_for, #sxl_version, #tlc, version_meets_requirement?, #wait_for_reader
Methods included from Proxy::Modules::Tasks
#read_line, #run_reader, #run_timer, #start_reader, #start_timer, #timer
Methods included from Proxy::Modules::Versions
#check_core_version, #component_list_acknowledged, #configured_sxls, #core_3_3?, #core_versions, #extraneous_version, #normalized_core_versions, #primary_configured_sxl, #send_version, #send_version_message, #send_version_request, #send_version_response, #site_id_items, #sxl_request_items, #version_items, version_meets_requirement?, #version_meets_requirement?, #version_message_attributes, #version_request_attributes, #version_response_sxls
Methods included from Proxy::Modules::Receive
#expect_version_message, #handle_fatal_error, #handle_invalid_message, #handle_invalid_packet, #handle_malformed_message, #handle_schema_error, #process_deferred, #process_packet, #should_validate_ingoing_message?, #verify_sequence, #will_not_handle
Methods included from Proxy::Modules::Send
#apply_nts_message_attributes, #buffer_message, #handle_send_schema_error, #log_send, #send_message, #send_message_and_collect, #with_send_ready, #write_message
Methods included from Proxy::Modules::Acknowledgements
#acknowledge, #check_ack_timeout, #check_ingoing_acknowledged, #check_outgoing_acknowledged, #dont_acknowledge, #dont_expect_acknowledgement, #expect_acknowledgement, #find_original_for_message, #log_acknowledgement_for_original, #log_acknowledgement_for_unknown, #process_ack, #process_not_ack, #status_subscribe_acknowledged
Methods included from Proxy::Modules::Watchdogs
#check_watchdog_timeout, #process_watchdog, #send_watchdog, #start_watchdog, #stop_watchdog, #watchdog_send_timer, #with_watchdog_disabled
Methods included from Proxy::Modules::State
Methods included from Task
#initialize_task, #restart, #run, #start, #stop, #stop_subtasks, #stop_task, #task_status, #wait, #wait_for_condition
Methods included from Distributor
#add_receiver, #clear_deferred_distribution, #distribute, #distribute_error, #distribute_immediately, #distribute_queued, #initialize_distributor, #inspect, #remove_receiver, #with_deferred_distribution
Methods included from Logging
#author, #initialize_logging, #log
Constructor Details
#initialize(options) ⇒ SiteProxy
Returns a new instance of SiteProxy.
14 15 16 17 18 19 20 21 22 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 14 def initialize() super(.merge(node: [:supervisor])) initialize_components @supervisor = [:supervisor] @settings = @supervisor.supervisor_settings.clone @site_id = [:site_id] @configured_site_settings = [:site_settings] @status_subscriptions = {} end |
Instance Attribute Details
#site_id ⇒ Object (readonly)
Returns the value of attribute site_id.
12 13 14 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 12 def site_id @site_id end |
#supervisor ⇒ Object (readonly)
Returns the value of attribute supervisor.
12 13 14 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 12 def supervisor @supervisor end |
Instance Method Details
#acknowledged_first_ingoing(message) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 98 def acknowledged_first_ingoing() case .type when 'Watchdog' send_watchdog end end |
#acknowledged_first_outgoing(message) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 105 def acknowledged_first_outgoing() case .type when 'Watchdog' if core_3_3? @outgoing_watchdog_acknowledged = true handshake_complete if @component_list_received else handshake_complete end end end |
#build_component(id:, type:, settings: {}) ⇒ Object
212 213 214 215 216 217 218 219 220 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 212 def build_component(id:, type:, settings: {}) settings ||= {} if type == 'main' ComponentProxy.new id: id, node: self, type: type, name: settings['name'], grouped: true, ntsoid: settings['ntsOId'], xnid: settings['xNId'] else ComponentProxy.new id: id, node: self, type: type, name: settings['name'], grouped: false end end |
#check_site_ids(message) ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 167 def check_site_ids() # RSMP support multiple site ids. we don't support this yet. instead we use the first id only site_id = .attribute('siteId').map { |item| item['sId'] }.first @site_id ||= site_id @supervisor.check_site_id site_id site_ids_changed end |
#find_site_settings(_site_id) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 175 def find_site_settings(_site_id) base = @settings['default'] || {} if @settings['sites'] site_specific = @settings['sites'][@site_id] || @settings['sites']['default'] if site_specific label = @settings['sites'][@site_id] ? "site id #{@site_id}" : 'default' log "Using #{label} site settings", level: :debug return base.deep_merge(site_specific) end end unless base.empty? log 'Using default site settings', level: :debug return base end nil end |
#handle_interface_message(message) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 69 def () interface = sxl_interface_for interface. interface. end |
#handled_by_parent?(message) ⇒ Boolean
65 66 67 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 65 def handled_by_parent?() .is_a?(CommandRequest) || .is_a?(StatusRequest) || .is_a?(StatusSubscribe) end |
#handshake_complete ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 35 def handshake_complete super sxl_summary = accepted_sxls.map { |item| "#{item['name']} #{item['version']}" }.join(', ') log "Connection to site #{@site_id} established, using core #{@core_version}, SXLs [#{sxl_summary}]", level: :info start_watchdog end |
#infer_component_type(_component_id) ⇒ Object
222 223 224 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 222 def infer_component_type(_component_id) ComponentProxy end |
#node ⇒ Object
31 32 33 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 31 def node supervisor end |
#process_component_list(message) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 123 def process_component_list() log "Received #{.type}", message: , level: :log rebuild_components_from_list .attributes['components'] build_sxl_interfaces acknowledge @component_list_received = true handshake_complete if @outgoing_watchdog_acknowledged end |
#process_message(message) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 43 def () return super if handled_by_parent?() case when StatusUnsubscribe, AggregatedStatusRequest will_not_handle when ComponentList process_component_list when AggregatedStatus process_aggregated_status when AlarmIssue, AlarmSuspended, AlarmResumed, AlarmAcknowledged, CommandResponse, StatusResponse, StatusUpdate else super end rescue RSMP::RepeatedAlarmError, RSMP::RepeatedStatusError, RSMP::TimestampError => e str = "Rejected #{.type} message," dont_acknowledge , str, e.to_s distribute_error e.exception("#{str}#{e.} #{.json}") end |
#process_version(message) ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 158 def process_version() return extraneous_version if @version_determined check_site_ids check_core_version check_sxl_version version_accepted end |
#rebuild_components_from_list(items) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 132 def rebuild_components_from_list(items) main_id = @site_settings.dig('components', 'main')&.keys&.first @components = {} @main = nil items.each do |item| grouped = item['id'] == main_id component = ComponentProxy.new( id: item['id'], node: self, type: item['type'], name: item['name'], grouped: grouped ) @components[component.c_id] = component @main = component if grouped end end |
#receive_error(error, options = {}) ⇒ Object
207 208 209 210 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 207 def receive_error(error, = {}) @supervisor&.receive_error error, distribute_error error, end |
#record_interface_message(message) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 76 def () case when AlarmIssue, AlarmSuspended, AlarmResumed, AlarmAcknowledged process_alarm when CommandResponse process_command_response when StatusResponse process_status_response when StatusUpdate process_status_update end end |
#revive(options) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 24 def revive() super @supervisor = [:supervisor] @settings = @supervisor.supervisor_settings.clone @configured_site_settings = [:site_settings] end |
#setup_site_settings ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 195 def setup_site_settings @site_settings = @configured_site_settings || find_site_settings(@site_id) if @site_settings @sxls = configured_sxls @accepted_sxls = @sxls.dup build_sxl_interfaces setup_components @site_settings['components'] else dont_acknowledge , 'Rejected', "No config found for site #{@site_id}" end end |
#site_ids_changed ⇒ Object
150 151 152 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 150 def site_ids_changed @supervisor.site_ids_changed end |
#validate_ready(action) ⇒ Object
117 118 119 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 117 def validate_ready(action) raise NotReady, "Can't #{action} because connection is not ready. (Currently #{@state})" unless ready? end |
#version_accepted(message) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 89 def version_accepted() log "Received Version message for site #{@site_id}", message: , level: :log start_timer acknowledge response_id = core_3_3? ? (@supervisor.site_id || @site_id) : @site_id send_version_response response_id, core_versions @version_determined = true end |
#version_acknowledged ⇒ Object
121 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 121 def version_acknowledged; end |
#watchdog_interval=(interval) ⇒ Object
154 155 156 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 154 def watchdog_interval=(interval) @settings['intervals']['watchdog'] = interval end |