Class: FFWD::Core::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/ffwd/core/processor.rb

Overview

Component responsible for receiving and internally route metrics and events.

The term ‘processor’ is used because depending on the set of provided processors it might be determined that the received metric should be provided to one of them instead.

If no processor matches, it is just passed straight through.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, emitter, processors, reporters) ⇒ Processor

Returns a new instance of Processor.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ffwd/core/processor.rb', line 37

def initialize input, emitter, processors, reporters
  @emitter = emitter
  @processors = processors
  @reporters = reporters

  subs = []

  @processors.each do |name, p|
    p.depend_on input
  end

  input.starting do
    subs << input.metric_subscribe do |m|
      process_metric m
    end

    subs << input.event_subscribe do |e|
      process_event e
    end
  end

  input.stopping do
    subs.each(&:unsubscribe).clear
  end
end

Class Method Details

.build(input, emitter, processors) ⇒ Object



31
32
33
34
35
# File 'lib/ffwd/core/processor.rb', line 31

def self.build input, emitter, processors
  processors = Hash[processors.map{|p| [p.name, p.setup(emitter)]}]
  reporters = processors.select{|k, p| FFWD.is_reporter?(p)}.map{|k, p| p}
  new(input, emitter, processors, reporters)
end

Instance Method Details

#report!Object



63
64
65
66
67
68
69
# File 'lib/ffwd/core/processor.rb', line 63

def report!
  @reporters.each do |reporter|
    reporter.report! do |d|
      yield d
    end
  end
end