Class: RSMP::Proxy

Inherits:
Object
  • Object
show all
Includes:
Inspect, Logging, Notifier, Task
Defined in:
lib/rsmp/proxy.rb

Direct Known Subclasses

SiteProxy, SupervisorProxy

Constant Summary collapse

WRAPPING_DELIMITER =
"\f"

Instance Attribute Summary collapse

Attributes included from Task

#task

Attributes included from Notifier

#listeners

Attributes included from Logging

#logger

Instance Method Summary collapse

Methods included from Task

#initialize_task, #restart, #run, #start, #stop, #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

#initialize_logging

Constructor Details

#initialize(options) ⇒ Proxy

Returns a new instance of Proxy.



18
19
20
21
22
23
24
25
26
# File 'lib/rsmp/proxy.rb', line 18

def initialize options
  @node = options[:node]
  initialize_logging options
  initialize_distributor
  initialize_task
  setup options
  clear
  @state = :disconnected
end

Instance Attribute Details

#archiveObject (readonly)

Returns the value of attribute archive.



16
17
18
# File 'lib/rsmp/proxy.rb', line 16

def archive
  @archive
end

#collectorObject (readonly)

Returns the value of attribute collector.



16
17
18
# File 'lib/rsmp/proxy.rb', line 16

def collector
  @collector
end

#connection_infoObject (readonly)

Returns the value of attribute connection_info.



16
17
18
# File 'lib/rsmp/proxy.rb', line 16

def connection_info
  @connection_info
end

#ipObject (readonly)

Returns the value of attribute ip.



16
17
18
# File 'lib/rsmp/proxy.rb', line 16

def ip
  @ip
end

#nodeObject (readonly)

Returns the value of attribute node.



16
17
18
# File 'lib/rsmp/proxy.rb', line 16

def node
  @node
end

#portObject (readonly)

Returns the value of attribute port.



16
17
18
# File 'lib/rsmp/proxy.rb', line 16

def port
  @port
end

#stateObject (readonly)

Returns the value of attribute state.



16
17
18
# File 'lib/rsmp/proxy.rb', line 16

def state
  @state
end

#sxlObject (readonly)

Returns the value of attribute sxl.



16
17
18
# File 'lib/rsmp/proxy.rb', line 16

def sxl
  @sxl
end

Instance Method Details

#acknowledge(original) ⇒ Object

Raises:

  • (InvalidArgument)


480
481
482
483
484
485
486
# File 'lib/rsmp/proxy.rb', line 480

def acknowledge original
  raise InvalidArgument unless original
  ack = MessageAck.build_from(original)
  ack.original = original.clone
  send_message ack, "for #{ack.original.type} #{original.m_id_short}"
  check_ingoing_acknowledged original
end

#acknowledged_first_ingoing(message) ⇒ Object



553
554
# File 'lib/rsmp/proxy.rb', line 553

def acknowledged_first_ingoing message
end

#acknowledged_first_outgoing(message) ⇒ Object



550
551
# File 'lib/rsmp/proxy.rb', line 550

def acknowledged_first_outgoing message
end

#authorObject



623
624
625
# File 'lib/rsmp/proxy.rb', line 623

def author
  @node.site_id
end

#buffer_message(message) ⇒ Object



344
345
346
347
# File 'lib/rsmp/proxy.rb', line 344

def buffer_message message
  # TODO
  #log "Cannot send #{message.type} because the connection is closed.", message: message, level: :error
end

#check_ack_timeout(now) ⇒ Object



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/rsmp/proxy.rb', line 280

def check_ack_timeout now
  timeout = @site_settings['timeouts']['acknowledgement']
  # hash cannot be modify during iteration, so clone it
  @awaiting_acknowledgement.clone.each_pair do |m_id, message|
    latest = message.timestamp + timeout
    if now > latest
      str = "No acknowledgements for #{message.type} #{message.m_id_short} within #{timeout} seconds"
      log str, level: :error
      begin
        close
      ensure
        notify_error MissingAcknowledgment.new(str)
      end
    end
  end
end

#check_ingoing_acknowledged(message) ⇒ Object



543
544
545
546
547
548
# File 'lib/rsmp/proxy.rb', line 543

def check_ingoing_acknowledged message
  unless @ingoing_acknowledged[message.type]
    @ingoing_acknowledged[message.type] = true
    acknowledged_first_ingoing message
  end
end

#check_outgoing_acknowledged(message) ⇒ Object

TODO this might be better handled by a proper event machine using e.g. the EventMachine gem



536
537
538
539
540
541
# File 'lib/rsmp/proxy.rb', line 536

def check_outgoing_acknowledged message
  unless @outgoing_acknowledged[message.type]
    @outgoing_acknowledged[message.type] = true
    acknowledged_first_outgoing message
  end
end

#check_rsmp_version(message) ⇒ Object



466
467
468
469
470
471
472
473
474
475
# File 'lib/rsmp/proxy.rb', line 466

def check_rsmp_version message
  versions = rsmp_versions
  # find versions that both we and the client support
  candidates = message.versions & versions
  if candidates.any?
    @rsmp_version = candidates.sort_by { |v| Gem::Version.new(v) }.last  # pick latest version
  else
    raise HandshakeError.new "RSMP versions [#{message.versions.join(',')}] requested, but only [#{versions.join(',')}] supported."
  end
end

#check_watchdog_timeout(now) ⇒ Object



297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/rsmp/proxy.rb', line 297

def check_watchdog_timeout now
  timeout = @site_settings['timeouts']['watchdog']
  latest = @latest_watchdog_received + timeout
  left = latest - now
  if left < 0
    str = "No Watchdog within #{timeout} seconds"
    log str, level: :error
      begin
        close                                   # this will stop the current task (ourself)
      ensure
        notify_error MissingWatchdog.new(str)   # but ensure block will still be reached
      end
  end
end

#clearObject



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/rsmp/proxy.rb', line 139

def clear
  @awaiting_acknowledgement = {}
  @latest_watchdog_received = nil
  @watchdog_started = false
  @version_determined = false
  @ingoing_acknowledged = {}
  @outgoing_acknowledged = {}
  @latest_watchdog_send_at = nil

  @state_condition = Async::Notification.new
  @acknowledgements = {}
  @acknowledgement_condition = Async::Notification.new
end

#clockObject



123
124
125
# File 'lib/rsmp/proxy.rb', line 123

def clock
  @node.clock
end

#closeObject

close connection, but keep our main task running so we can reconnect



38
39
40
41
42
43
44
45
# File 'lib/rsmp/proxy.rb', line 38

def close
  log "Closing connection", level: :warning
  close_stream
  close_socket
  set_state :disconnected
  notify_error DisconnectError.new("Connection was closed")
  stop_timer
end

#close_socketObject



72
73
74
75
76
# File 'lib/rsmp/proxy.rb', line 72

def close_socket
  return unless @socket
  @socket.close
  @socket = nil
end

#close_streamObject



66
67
68
69
70
# File 'lib/rsmp/proxy.rb', line 66

def close_stream
  return unless @stream
  @stream.close
  @stream = nil
end

#connected?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/rsmp/proxy.rb', line 131

def connected?
  @state == :connected || @state == :ready
end

#disconnectObject



28
29
# File 'lib/rsmp/proxy.rb', line 28

def disconnect
end

#disconnected?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/rsmp/proxy.rb', line 135

def disconnected?
  @state == :disconnected
end

#dont_acknowledge(original, prefix = nil, reason = nil) ⇒ Object

Raises:

  • (InvalidArgument)


488
489
490
491
492
493
494
495
496
497
498
# File 'lib/rsmp/proxy.rb', line 488

def dont_acknowledge original, prefix=nil, reason=nil
  raise InvalidArgument unless original
  str = [prefix,reason].join(' ')
  log str, message: original, level: :warning if reason
  message = MessageNotAck.new({
    "oMId" => original.m_id,
    "rea" => reason || "Unknown reason"
  })
  message.original = original.clone
  send_message message, "for #{original.type} #{original.m_id_short}"
end

#dont_expect_acknowledgement(message) ⇒ Object



452
453
454
# File 'lib/rsmp/proxy.rb', line 452

def dont_expect_acknowledgement message
  @awaiting_acknowledgement.delete message.attribute("oMId")
end

#expect_acknowledgement(message) ⇒ Object



446
447
448
449
450
# File 'lib/rsmp/proxy.rb', line 446

def expect_acknowledgement message
  unless message.is_a?(MessageAck) || message.is_a?(MessageNotAck)
    @awaiting_acknowledgement[message.m_id] = message
  end
end

#expect_version_message(message) ⇒ Object



610
611
612
613
614
# File 'lib/rsmp/proxy.rb', line 610

def expect_version_message message
  unless message.is_a?(Version) || message.is_a?(MessageAck) || message.is_a?(MessageNotAck)
    raise HandshakeError.new "Version must be received first"
  end
end

#extraneous_version(message) ⇒ Object



456
457
458
# File 'lib/rsmp/proxy.rb', line 456

def extraneous_version message
  dont_acknowledge message, "Received", "extraneous Version message"
end

#find_original_for_message(message) ⇒ Object



531
532
533
# File 'lib/rsmp/proxy.rb', line 531

def find_original_for_message message
   @awaiting_acknowledgement[ message.attribute("oMId") ]
end

#get_schemasObject



316
317
318
319
320
321
322
323
324
# File 'lib/rsmp/proxy.rb', line 316

def get_schemas
  # normally we have an sxl, but during connection, it hasn't been established yet
  # at these times we only validate against the core schema
  # TODO
  # what schema should we use to validate the intial Version and MessageAck messages?
  schemas = { core: '3.1.5' }
  schemas[sxl] = RSMP::Schemer.sanitize_version(sxl_version) if sxl && sxl_version
  schemas
end

#handshake_completeObject



616
617
618
# File 'lib/rsmp/proxy.rb', line 616

def handshake_complete
  set_state :ready
end

#inspectObject



117
118
119
120
121
# File 'lib/rsmp/proxy.rb', line 117

def inspect
  "#<#{self.class.name}:#{self.object_id}, #{inspector(
    :@acknowledgements,:@settings,:@site_settings
    )}>"
end

#log(str, options = {}) ⇒ Object



312
313
314
# File 'lib/rsmp/proxy.rb', line 312

def log str, options={}
  super str, options.merge(ip: @ip, port: @port, site_id: @site_id)
end

#log_acknowledgement_for_original(message, original) ⇒ Object



589
590
591
592
593
594
595
596
597
598
# File 'lib/rsmp/proxy.rb', line 589

def log_acknowledgement_for_original message, original
  str = "Received #{message.type} for #{original.type} #{message.attribute("oMId")[0..3]}"
  if message.type == 'MessageNotAck'
    reason = message.attributes["rea"]
    str = "#{str}: #{reason}" if reason
    log str, message: message, level: :warning
  else
    log str, message: message, level: :log
  end
end

#log_acknowledgement_for_unknown(message) ⇒ Object



600
601
602
# File 'lib/rsmp/proxy.rb', line 600

def log_acknowledgement_for_unknown message
  log "Received #{message.type} for unknown message #{message.attribute("oMId")[0..3]}", message: message, level: :warning
end

#log_send(message, reason = nil) ⇒ Object



349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/rsmp/proxy.rb', line 349

def log_send message, reason=nil
  if reason
    str = "Sent #{message.type} #{reason}"
  else
    str = "Sent #{message.type}"
  end

  if message.type == "MessageNotAck"
    log str, message: message, level: :warning
  else
    log str, message: message, level: :log
  end
end

#notify_error(e, options = {}) ⇒ Object



206
207
208
# File 'lib/rsmp/proxy.rb', line 206

def notify_error e, options={}
  @node.notify_error e, options
end

#process_ack(message) ⇒ Object



556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/rsmp/proxy.rb', line 556

def process_ack message
  original = find_original_for_message message
  if original
    dont_expect_acknowledgement message
    message.original = original
    log_acknowledgement_for_original message, original

    if original.type == "Version"
      version_acknowledged
    end

    check_outgoing_acknowledged original

    @acknowledgements[ original.m_id ] = message
    @acknowledgement_condition.signal message
  else
    log_acknowledgement_for_unknown message
  end
end

#process_deferredObject



371
372
373
# File 'lib/rsmp/proxy.rb', line 371

def process_deferred
  @node.process_deferred
end

#process_message(message) ⇒ Object



425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/rsmp/proxy.rb', line 425

def process_message message
  case message
    when MessageAck
      process_ack message
    when MessageNotAck
      process_not_ack message
    when Version
      process_version message
    when Watchdog
      process_watchdog message
    else
      dont_acknowledge message, "Received", "unknown message (#{message.type})"
  end
end

#process_not_ack(message) ⇒ Object



576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/rsmp/proxy.rb', line 576

def process_not_ack message
  original = find_original_for_message message
  if original
    dont_expect_acknowledgement message
    message.original = original
    log_acknowledgement_for_original message, original
    @acknowledgements[ original.m_id ] = message
    @acknowledgement_condition.signal message
  else
    log_acknowledgement_for_unknown message
  end
end

#process_packet(json) ⇒ Object



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/rsmp/proxy.rb', line 379

def process_packet json
  attributes = Message.parse_attributes json
  message = Message.build attributes, json
  message.validate(get_schemas) if should_validate_ingoing_message?(message)
  verify_sequence message
  deferred_notify do
    notify message
    process_message message
  end
  process_deferred
  message
rescue InvalidPacket => e
  str = "Received invalid package, must be valid JSON but got #{json.size} bytes: #{e.message}"
  notify_error e.exception(str)
  log str, level: :warning
  nil
rescue MalformedMessage => e
  str = "Received malformed message, #{e.message}"
  notify_error e.exception(str)
  log str, message: Malformed.new(attributes), level: :warning
  # cannot send NotAcknowledged for a malformed message since we can't read it, just ignore it
  nil
rescue SchemaError, RSMP::Schemer::Error => e
  reason = "schema errors: #{e.message}"
  str = "Received invalid #{message.type}, #{reason}"
  log str, message: message, level: :warning
  notify_error e.exception(str), message: message
  dont_acknowledge message, str, reason
  message
rescue InvalidMessage => e
  reason = "#{e.message}"
  str = "Received invalid #{message.type},"
  notify_error e.exception("#{str} #{message.json}"), message: message
  dont_acknowledge message, str, reason
  message
rescue FatalError => e
  reason = e.message
  str = "Rejected #{message.type},"
  notify_error e.exception(str), message: message
  dont_acknowledge message, str, reason
  close
  message
ensure
  @node.clear_deferred
end

#process_version(message) ⇒ Object



477
478
# File 'lib/rsmp/proxy.rb', line 477

def process_version message
end

#process_watchdog(message) ⇒ Object



604
605
606
607
608
# File 'lib/rsmp/proxy.rb', line 604

def process_watchdog message
  log "Received #{message.type}", message: message, level: :log
  @latest_watchdog_received = Clock.now
  acknowledge message
end

#read_lineObject



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/rsmp/proxy.rb', line 184

def read_line
  json = @protocol.read_line
  beginning = Time.now
  message = process_packet json
  duration = Time.now - beginning
  ms = (duration*1000).round(4)
  if duration > 0
    per_second = (1.0 / duration).round
  else
    per_second = Float::INFINITY
  end
  if message
    type = message.type
    m_id = Logger.shorten_message_id(message.m_id)
  else
    type = 'Unknown'
    m_id = nil
  end
  str = [type,m_id,"processed in #{ms}ms, #{per_second}req/s"].compact.join(' ')
  log str, level: :statistics
end

#ready?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/rsmp/proxy.rb', line 127

def ready?
  @state == :ready
end

#revive(options) ⇒ Object

revive after a reconnect



97
98
99
# File 'lib/rsmp/proxy.rb', line 97

def revive options
  setup options
end

#rsmp_versionsObject



460
461
462
463
464
# File 'lib/rsmp/proxy.rb', line 460

def rsmp_versions
  return ['3.1.5'] if @site_settings["rsmp_versions"] == 'latest'
  return ['3.1.1','3.1.2','3.1.3','3.1.4','3.1.5'] if @site_settings["rsmp_versions"] == 'all'
  @site_settings["rsmp_versions"]
end

#run_readerObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/rsmp/proxy.rb', line 161

def run_reader
  @stream ||= Async::IO::Stream.new(@socket)
  @protocol ||= Async::IO::Protocol::Line.new(@stream,WRAPPING_DELIMITER) # rsmp messages are json terminated with a form-feed
  loop do
    read_line
  end
rescue Restart
  log "Closing connection", level: :warning
  raise
rescue Async::Wrapper::Cancelled
  # ignore exceptions raised when a wait is aborted because a task is stopped
rescue EOFError, Async::Stop
  log "Connection closed", level: :warning
rescue IOError => e
  log "IOError: #{e}", level: :warning
rescue Errno::ECONNRESET
  log "Connection reset by peer", level: :warning
rescue Errno::EPIPE
  log "Broken pipe", level: :warning
rescue StandardError => e
  notify_error e, level: :internal
end

#run_timer(task, interval) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/rsmp/proxy.rb', line 227

def run_timer task, interval
  next_time = Time.now.to_f
  loop do
    begin
      now = Clock.now
      timer(now)
    rescue RSMP::Schemer::Error => e
      log "Timer: Schema error: #{e}", level: :warning
    rescue EOFError => e
      log "Timer: Connection closed: #{e}", level: :warning
    rescue IOError => e
      log "Timer: IOError", level: :warning
    rescue Errno::ECONNRESET
      log "Timer: Connection reset by peer", level: :warning
    rescue Errno::EPIPE => e
      log "Timer: Broken pipe", level: :warning
    rescue StandardError => e
      notify_error e, level: :internal
    end
  ensure
    next_time += interval
    duration = next_time - Time.now.to_f
    task.sleep duration
  end
end

#send_and_optionally_collect(message, options, &block) ⇒ Object



627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/rsmp/proxy.rb', line 627

def send_and_optionally_collect message, options, &block
  collect_options = options[:collect] || options[:collect!]
  if collect_options
    task = @task.async do |task|
      task.annotate 'send_and_optionally_collect'
      collector = yield collect_options     # call block to create collector
      collector.collect
      collector.ok! if options[:collect!]   # raise any errors if the bang version was specified
      collector
    end

    send_message message, validate: options[:validate]
    { sent: message, collector: task.wait }
  else
    send_message message, validate: options[:validate]
    return { sent: message }
  end
end

#send_message(message, reason = nil, validate: true) ⇒ Object



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/rsmp/proxy.rb', line 326

def send_message message, reason=nil, validate: true
  raise NotReady unless connected?
  raise IOError unless @protocol
  message.direction = :out
  message.generate_json
  message.validate get_schemas unless validate==false
  @protocol.write_lines message.json
  expect_acknowledgement message
  notify message
  log_send message, reason
rescue EOFError, IOError
  buffer_message message
rescue SchemaError, RSMP::Schemer::Error => e
  str = "Could not send #{message.type} because schema validation failed: #{e.message}"
  log str, message: message, level: :error
  notify_error e.exception("#{str} #{message.json}")
end

#send_version(site_id, rsmp_versions) ⇒ Object



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/rsmp/proxy.rb', line 511

def send_version site_id, rsmp_versions
  if rsmp_versions=='latest'
    versions = ['3.1.5']
  elsif rsmp_versions=='all'
    versions = ['3.1.1','3.1.2','3.1.3','3.1.4','3.1.5']
  else
    versions = [rsmp_versions].flatten
  end
  versions_array = versions.map {|v| {"vers" => v} }

  site_id_array = [site_id].flatten.map {|id| {"sId" => id} }

  version_response = Version.new({
    "RSMP"=>versions_array,
    "siteId"=>site_id_array,
    "SXL"=>sxl_version
  })
  send_message version_response
end

#send_watchdog(now = Clock.now) ⇒ Object



274
275
276
277
278
# File 'lib/rsmp/proxy.rb', line 274

def send_watchdog now=Clock.now
  message = Watchdog.new( {"wTs" => clock.to_s})
  send_message message
  @latest_watchdog_send_at = now
end

#set_state(state) ⇒ Object

change our state



84
85
86
87
88
# File 'lib/rsmp/proxy.rb', line 84

def set_state state
  return if state == @state
  @state = state
  state_changed
end

#setup(options) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/rsmp/proxy.rb', line 101

def setup options
  @settings = options[:settings]
  @socket = options[:socket]
  @stream = options[:stream]
  @protocol = options[:protocol]
  @ip = options[:ip]
  @port = options[:port]
  @connection_info = options[:info]
  @sxl = nil
  @site_settings = nil  # can't pick until we know the site id
  if options[:collect]
    @collector = RSMP::Collector.new self, options[:collect]
    @collector.start
  end
end

#should_validate_ingoing_message?(message) ⇒ Boolean

Returns:

  • (Boolean)


363
364
365
366
367
368
369
# File 'lib/rsmp/proxy.rb', line 363

def should_validate_ingoing_message? message
  return true unless @site_settings
  skip = @site_settings.dig('skip_validation')
  return true unless skip
  klass = message.class.name.split('::').last
  !skip.include?(klass)
end

#start_readerObject

run an async task that reads from @socket



154
155
156
157
158
159
# File 'lib/rsmp/proxy.rb', line 154

def start_reader
  @reader = @task.async do |task|
    task.annotate "reader"
    run_reader
  end
end

#start_timerObject



215
216
217
218
219
220
221
222
223
224
225
# File 'lib/rsmp/proxy.rb', line 215

def start_timer
  return if @timer
  name = "timer"
  interval = @site_settings['intervals']['timer'] || 1
  log "Starting #{name} with interval #{interval} seconds", level: :debug
  @latest_watchdog_received = Clock.now
  @timer = @task.async do |task|
    task.annotate "timer"
    run_timer task, interval
  end
end

#start_watchdogObject



210
211
212
213
# File 'lib/rsmp/proxy.rb', line 210

def start_watchdog
  log "Starting watchdog with interval #{@site_settings['intervals']['watchdog']} seconds", level: :debug
  @watchdog_started = true
end

#state_changedObject

the state changed override to to things like notifications



92
93
94
# File 'lib/rsmp/proxy.rb', line 92

def state_changed
  @state_condition.signal @state
end

#stop_readerObject



60
61
62
63
64
# File 'lib/rsmp/proxy.rb', line 60

def stop_reader
  return unless @reader
  @reader.stop
  @reader = nil
end

#stop_subtasksObject



47
48
49
50
51
52
# File 'lib/rsmp/proxy.rb', line 47

def stop_subtasks
  stop_timer
  stop_reader
  clear
  super
end

#stop_taskObject



78
79
80
81
# File 'lib/rsmp/proxy.rb', line 78

def stop_task
  close
  super
end

#stop_timerObject



54
55
56
57
58
# File 'lib/rsmp/proxy.rb', line 54

def stop_timer
  return unless @timer
  @timer.stop
  @timer = nil
end

#timer(now) ⇒ Object



253
254
255
256
257
# File 'lib/rsmp/proxy.rb', line 253

def timer now
  watchdog_send_timer now
  check_ack_timeout now
  check_watchdog_timeout now
end

#verify_sequence(message) ⇒ Object



375
376
377
# File 'lib/rsmp/proxy.rb', line 375

def verify_sequence message
  expect_version_message(message) unless @version_determined
end

#version_acknowledgedObject



620
621
# File 'lib/rsmp/proxy.rb', line 620

def version_acknowledged
end

#wait_for_readerObject

wait for the reader task to complete, which is not expected to happen before the connection is closed



33
34
35
# File 'lib/rsmp/proxy.rb', line 33

def wait_for_reader
  @reader.wait if @reader
end

#wait_for_state(state, timeout:) ⇒ Object



500
501
502
503
504
505
506
507
508
509
# File 'lib/rsmp/proxy.rb', line 500

def wait_for_state state, timeout:
  states = [state].flatten
  return if states.include?(@state)
  wait_for_condition(@state_condition,timeout: timeout) do
    states.include?(@state)
  end
  @state
rescue RSMP::TimeoutError
  raise RSMP::TimeoutError.new "Did not reach state #{state} within #{timeout}s"
end

#watchdog_send_timer(now) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/rsmp/proxy.rb', line 259

def watchdog_send_timer now
  return unless @watchdog_started
  return if @site_settings['intervals']['watchdog'] == :never
  if @latest_watchdog_send_at == nil
    send_watchdog now
  else
    # we add half the timer interval to pick the timer
    # event closes to the wanted wathcdog interval
    diff = now - @latest_watchdog_send_at
    if (diff + 0.5*@site_settings['intervals']['timer']) >= (@site_settings['intervals']['watchdog'])
      send_watchdog now
    end
  end
end

#will_not_handle(message) ⇒ Object



440
441
442
443
444
# File 'lib/rsmp/proxy.rb', line 440

def will_not_handle message
  reason = "since we're a #{self.class.name.downcase}" unless reason
  log "Ignoring #{message.type}, #{reason}", message: message, level: :warning
  dont_acknowledge message, nil, reason
end