class RFlow::Components::GenerateIntegerSequence

An integer sequence generator that ticks every n seconds.

Accepts config parameters:

Emits {RFlow::Message}s whose internal type is {RFlow::Message::Data::Integer}.

Public Instance Methods

configure!(config) click to toggle source

RFlow-called method at startup. @param config [Hash] configuration from the RFlow config file @return [void]

# File lib/rflow/components/integer.rb, line 44
def configure!(config)
  @start = config['start'].to_i
  @finish = config['finish'].to_i
  @step = config['step'] ? config['step'].to_i : 1
  # If interval seconds is not given, it will default to 0
  @interval_seconds = config['interval_seconds'].to_i
end
generate() click to toggle source

@!visibility private

# File lib/rflow/components/integer.rb, line 61
def generate
  Message.new('RFlow::Message::Data::Integer').tap do |m|
    m.data.data_object = @start
    out.send_message m
    if @start % 2 == 0
      even_odd_out['even'].send_message m
    else
      even_odd_out['odd'].send_message m
    end
  end

  @start += @step
  @timer.cancel if @start > @finish && @timer
end
run!() click to toggle source

RFlow-called method at startup. @return [void]

# File lib/rflow/components/integer.rb, line 54
def run!
  # Note that this uses the timer (sometimes with 0 interval) so as
  # not to block the reactor.
  @timer = EM::PeriodicTimer.new(@interval_seconds) { generate }
end