Class: RSMP::SiteProxy
- Includes:
- Components, Modules::AggregatedStatus, Modules::Alarms, Modules::Commands, Modules::Status
- 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.
Direct Known Subclasses
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
#archive, #collector, #connection_info, #core_version, #ip, #port, #state, #sxl
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
- #check_sxl_version(message) ⇒ Object
- #find_site_settings(_site_id) ⇒ Object
- #handled_by_parent?(message) ⇒ Boolean
- #handshake_complete ⇒ Object
- #infer_component_type(_component_id) ⇒ Object
-
#initialize(options) ⇒ SiteProxy
constructor
A new instance of SiteProxy.
- #inspect ⇒ Object
- #node ⇒ Object
- #process_message(message) ⇒ Object
- #process_version(message) ⇒ Object
- #receive_error(error, options = {}) ⇒ Object
- #revive(options) ⇒ Object
-
#run ⇒ Object
handle communication when we’re created, the socket is already open.
- #setup_site_settings ⇒ Object
- #site_ids_changed ⇒ Object
- #sxl_version ⇒ Object
- #validate_ready(action) ⇒ Object
- #version_accepted(message) ⇒ Object
- #version_acknowledged ⇒ Object
- #watchdog_interval=(interval) ⇒ Object
Methods included from Modules::Commands
#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, #find_component, #initialize_components, #setup_components
Methods inherited from Proxy
#author, #clear, #clock, #close, #close_socket, #close_stream, #connected?, #disconnect, #disconnected?, #log, #now, #ready?, #schemas, #setup, #state_changed, #stop_reader, #stop_subtasks, #stop_task, #stop_timer, 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, #core_versions, #extraneous_version, #send_version, version_meets_requirement?
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
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, #start, #stop, #stop_subtasks, #stop_task, #task_status, #wait, #wait_for_condition
Methods included from Inspect
Methods included from Distributor
#add_receiver, #clear_deferred_distribution, #distribute, #distribute_error, #distribute_immediately, #distribute_queued, #initialize_distributor, #remove_receiver, #with_deferred_distribution
Methods included from Logging
#author, #initialize_logging, #log
Constructor Details
#initialize(options) ⇒ SiteProxy
Returns a new instance of SiteProxy.
12 13 14 15 16 17 18 19 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 12 def initialize() super(.merge(node: [:supervisor])) initialize_components @supervisor = [:supervisor] @settings = @supervisor.supervisor_settings.clone @site_id = [:site_id] @status_subscriptions = {} end |
Instance Attribute Details
#site_id ⇒ Object (readonly)
Returns the value of attribute site_id.
10 11 12 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 10 def site_id @site_id end |
#supervisor ⇒ Object (readonly)
Returns the value of attribute supervisor.
10 11 12 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 10 def supervisor @supervisor end |
Instance Method Details
#acknowledged_first_ingoing(message) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 96 def acknowledged_first_ingoing() case .type when 'Watchdog' send_watchdog end end |
#acknowledged_first_outgoing(message) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 103 def acknowledged_first_outgoing() case .type when 'Watchdog' handshake_complete end end |
#build_component(id:, type:, settings: {}) ⇒ Object
195 196 197 198 199 200 201 202 203 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 195 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
153 154 155 156 157 158 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 153 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 @supervisor.check_site_id site_id site_ids_changed end |
#check_sxl_version(message) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 124 def check_sxl_version() # check that we have a schema for specified sxl type and version # note that the type comes from the site config, while the version # comes from the Version message send by the site type = @site_settings['sxl'] version = .attribute 'SXL' RSMP::Schema.find_schema! type, version, lenient: true # store sxl version requested by site # TODO should check agaist site settings @site_sxl_version = .attribute 'SXL' rescue RSMP::Schema::UnknownSchemaError => e dont_acknowledge , "Rejected #{.type} message,", e.to_s end |
#find_site_settings(_site_id) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 160 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 |
#handled_by_parent?(message) ⇒ Boolean
84 85 86 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 84 def handled_by_parent?() .is_a?(CommandRequest) || .is_a?(StatusRequest) || .is_a?(StatusSubscribe) end |
#handshake_complete ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 51 def handshake_complete super sanitized_sxl_version = RSMP::Schema.sanitize_version(@site_sxl_version) log "Connection to site #{@site_id} established, using core #{@core_version}, #{@sxl} #{sanitized_sxl_version}", level: :info start_watchdog end |
#infer_component_type(_component_id) ⇒ Object
205 206 207 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 205 def infer_component_type(_component_id) ComponentProxy end |
#inspect ⇒ Object
41 42 43 44 45 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 41 def inspect "#<#{self.class.name}:#{object_id}, #{inspector( :@acknowledgements, :@settings, :@site_settings, :@components )}>" end |
#node ⇒ Object
47 48 49 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 47 def node supervisor end |
#process_message(message) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 59 def () return super if handled_by_parent?() case when StatusUnsubscribe, AggregatedStatusRequest will_not_handle when AggregatedStatus process_aggregated_status when AlarmIssue, AlarmSuspended, AlarmResumed, AlarmAcknowledged process_alarm when CommandResponse process_command_response when StatusResponse process_status_response when StatusUpdate process_status_update 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
145 146 147 148 149 150 151 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 145 def process_version() return extraneous_version if @version_determined check_site_ids check_sxl_version version_accepted end |
#receive_error(error, options = {}) ⇒ Object
190 191 192 193 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 190 def receive_error(error, = {}) @supervisor&.receive_error error, distribute_error error, end |
#revive(options) ⇒ Object
35 36 37 38 39 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 35 def revive() super @supervisor = [:supervisor] @settings = @supervisor.supervisor_settings.clone end |
#run ⇒ Object
handle communication when we’re created, the socket is already open
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 23 def run self.state = :connected start_reader wait_for_reader # run until disconnected rescue RSMP::ConnectionError => e log e, level: :error rescue StandardError => e distribute_error e, level: :internal ensure close end |
#setup_site_settings ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 180 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 , 'Rejected', "No config found for site #{@site_id}" end end |
#site_ids_changed ⇒ Object
116 117 118 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 116 def site_ids_changed @supervisor.site_ids_changed end |
#sxl_version ⇒ Object
139 140 141 142 143 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 139 def sxl_version # a supervisor does not maintain it's own sxl version # instead we use what the site requests @site_sxl_version end |
#validate_ready(action) ⇒ Object
110 111 112 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 110 def validate_ready(action) raise NotReady, "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/proxy/site/site_proxy.rb', line 88 def version_accepted() log "Received Version message for site #{@site_id}", message: , level: :log start_timer acknowledge send_version @site_id, core_versions @version_determined = true end |
#version_acknowledged ⇒ Object
114 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 114 def version_acknowledged; end |
#watchdog_interval=(interval) ⇒ Object
120 121 122 |
# File 'lib/rsmp/proxy/site/site_proxy.rb', line 120 def watchdog_interval=(interval) @settings['intervals']['watchdog'] = interval end |