Class: TopologicalInventory::Providers::Common::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/topological_inventory/providers/common/collector.rb,
lib/topological_inventory/providers/common/collector/parser.rb,
lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb,
lib/topological_inventory/providers/common/collector/inventory_collection_wrapper.rb

Defined Under Namespace

Classes: InventoryCollectionStorage, InventoryCollectionWrapper, Parser

Instance Method Summary collapse

Constructor Details

#initialize(source, default_limit: 1_000, poll_time: 30, standalone_mode: true) ⇒ Collector

Returns a new instance of Collector.

Parameters:

  • poll_time (Integer) (defaults to: 30)

    Waiting between collecting loops. Irrelevant for standalone_mode: true

  • standalone_mode (Boolean) (defaults to: true)

    T/F if collector is created by collectors_pool



15
16
17
18
19
20
21
22
23
# File 'lib/topological_inventory/providers/common/collector.rb', line 15

def initialize(source, default_limit: 1_000, poll_time: 30, standalone_mode: true)
  self.collector_threads = Concurrent::Map.new
  self.finished          = Concurrent::AtomicBoolean.new(false)
  self.poll_time         = poll_time
  self.limits            = Hash.new(default_limit)
  self.queue             = Queue.new
  self.source            = source
  self.standalone_mode   = standalone_mode
end

Instance Method Details

#collect!Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/topological_inventory/providers/common/collector.rb', line 25

def collect!
  start_collector_threads

  until finished? do
    ensure_collector_threads

    notices = []
    notices << queue.pop until queue.empty?

    targeted_refresh(notices) unless notices.empty?

    standalone_mode ? sleep(poll_time) : stop
  end
end

#stopObject



40
41
42
# File 'lib/topological_inventory/providers/common/collector.rb', line 40

def stop
  finished.value = true
end