Class: RFlow::Components::Clock

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

Defined Under Namespace

Modules: Tick

Constant Summary collapse

DEFAULT_CONFIG =
{
  'name' => 'Clock',
  'tick_interval' => 1
}

Instance Attribute Summary collapse

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 Attribute Details

#configObject (readonly)

Returns the value of attribute config.



28
29
30
# File 'lib/rflow/components/clock.rb', line 28

def config
  @config
end

#tick_intervalObject (readonly)

Returns the value of attribute tick_interval.



28
29
30
# File 'lib/rflow/components/clock.rb', line 28

def tick_interval
  @tick_interval
end

Instance Method Details

#clock_nameObject



35
# File 'lib/rflow/components/clock.rb', line 35

def clock_name; config['name']; end

#configure!(config) ⇒ Object



30
31
32
33
# File 'lib/rflow/components/clock.rb', line 30

def configure!(config)
  @config = DEFAULT_CONFIG.merge config
  @tick_interval = Float(@config['tick_interval'])
end

#run!Object



37
38
39
# File 'lib/rflow/components/clock.rb', line 37

def run!
  @timer = EventMachine::PeriodicTimer.new(tick_interval) { tick }
end

#tickObject



41
42
43
44
45
46
# File 'lib/rflow/components/clock.rb', line 41

def tick
  tick_port.send_message(RFlow::Message.new('RFlow::Message::Clock::Tick').tap do |m|
    m.data.name = clock_name
    m.data.timestamp = Integer(Time.now.to_f * 1000) # ms since epoch
  end)
end