Class: TacScribe::EventQueue
- Inherits:
-
TacviewClient::BaseProcessor
- Object
- TacviewClient::BaseProcessor
- TacScribe::EventQueue
- Defined in:
- lib/tac_scribe/event_queue.rb
Overview
Processes the events emitted by the Ruby Tacview Client
Instance Attribute Summary collapse
-
#reference_latitude ⇒ Object
Returns the value of attribute reference_latitude.
-
#reference_longitude ⇒ Object
Returns the value of attribute reference_longitude.
Instance Method Summary collapse
- #clear ⇒ Object
-
#delete_object(object_id) ⇒ Object
Process a delete event for an object.
- #get_event ⇒ Object
-
#initialize(verbose_logging:) ⇒ EventQueue
constructor
A new instance of EventQueue.
-
#set_property(property:, value:) ⇒ Object
Set a property.
-
#update_object(event) ⇒ Object
Process an update event for an object.
-
#update_time(time) ⇒ Object
Process a time update event.
Constructor Details
#initialize(verbose_logging:) ⇒ EventQueue
Returns a new instance of EventQueue.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tac_scribe/event_queue.rb', line 11 def initialize(verbose_logging:) @verbose_logging = verbose_logging @events = Queue.new @event_write = 0 @event_read = 0 return unless verbose_logging == true Thread.new do loop do puts "#{Time.now.strftime('%FT%T')} - Queue Size: #{@events.size} \t Events Added: #{@event_write} \t Events Processed: #{@event_read}" @event_write = 0 @event_read = 0 sleep 1 end end end |
Instance Attribute Details
#reference_latitude ⇒ Object
Returns the value of attribute reference_latitude.
9 10 11 |
# File 'lib/tac_scribe/event_queue.rb', line 9 def reference_latitude @reference_latitude end |
#reference_longitude ⇒ Object
Returns the value of attribute reference_longitude.
9 10 11 |
# File 'lib/tac_scribe/event_queue.rb', line 9 def reference_longitude @reference_longitude end |
Instance Method Details
#clear ⇒ Object
29 30 31 |
# File 'lib/tac_scribe/event_queue.rb', line 29 def clear @events.clear end |
#delete_object(object_id) ⇒ Object
Process a delete event for an object
64 65 66 67 |
# File 'lib/tac_scribe/event_queue.rb', line 64 def delete_object(object_id) @event_write += 1 @events << { type: :delete_object, object_id: object_id } end |
#get_event ⇒ Object
33 34 35 36 |
# File 'lib/tac_scribe/event_queue.rb', line 33 def get_event @event_read += 1 @events.shift end |
#set_property(property:, value:) ⇒ Object
Set a property
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tac_scribe/event_queue.rb', line 81 def set_property(property:, value:) case property when 'ReferenceLatitude' self.reference_latitude = BigDecimal(value) when 'ReferenceLongitude' self.reference_longitude = BigDecimal(value) when 'ReferenceTime' @reference_time = @time = Time.parse(value) end end |
#update_object(event) ⇒ Object
Process an update event for an object
On the first appearance of the object there are usually more fields including pilot names, object type etc.
For existing objects these events are almost always lat/lon/alt updates only
55 56 57 58 |
# File 'lib/tac_scribe/event_queue.rb', line 55 def update_object(event) @event_write += 1 @events << { type: :update_object, event: event, time: @time } end |
#update_time(time) ⇒ Object
Process a time update event
73 74 75 |
# File 'lib/tac_scribe/event_queue.rb', line 73 def update_time(time) @time = @reference_time + time end |