Class: RFlow::Components::GenerateIntegerSequence

Inherits:
RFlow::Component show all
Defined in:
lib/rflow/components/integer.rb

Instance Attribute Summary

Attributes inherited from RFlow::Component

#name, #ports, #uuid, #worker

Instance Method Summary collapse

Methods inherited from RFlow::Component

build, #cleanup!, #configure_input_port!, #configure_output_port!, #connect_inputs!, #connect_outputs!, define_port, defined_input_ports, defined_output_ports, inherited, #initialize, input_port, #input_ports, output_port, #output_ports, #process_message, #shard, #shutdown!, #to_s

Constructor Details

This class inherits a constructor from RFlow::Component

Instance Method Details

#configure!(config) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/rflow/components/integer.rb', line 9

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

#generateObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rflow/components/integer.rb', line 23

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!Object

Note that this uses the timer (sometimes with 0 interval) so as not to block the reactor



19
20
21
# File 'lib/rflow/components/integer.rb', line 19

def run!
  @timer = EM::PeriodicTimer.new(@interval_seconds) { generate }
end