class FFWD::Core::Processor

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.

Public Class Methods

build(input, emitter, processors) click to toggle source
# 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
new(input, emitter, processors, reporters) click to toggle source
# 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

Public Instance Methods

report!(diff) { |d| ... } click to toggle source
# File lib/ffwd/core/processor.rb, line 62
def report!(diff)
  @reporters.each do |reporter|
    reporter.report!(diff) do |d|
      yield d
    end
  end
end

Private Instance Methods

process_event(e) click to toggle source
# File lib/ffwd/core/processor.rb, line 86
def process_event e
  e[:time] ||= Time.now
  @emitter.event.emit e
end
process_metric(m) click to toggle source
# File lib/ffwd/core/processor.rb, line 72
def process_metric m
  m[:time] ||= Time.now

  unless p = m[:proc]
    return @emitter.metric.emit m
  end

  unless p = @processors[p]
    return @emitter.metric.emit m
  end

  p.process m
end