class Fluent::DummyInput

Constants

BIN_NUM

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method Fluent::Input#configure
# File lib/fluent/plugin/in_dummy.rb, line 51
def configure(conf)
  super

  @increment_value = 0
  @dummy_index = 0
end
emit(num) click to toggle source
# File lib/fluent/plugin/in_dummy.rb, line 86
def emit(num)
  num.times { router.emit(@tag, Fluent::Engine.now, generate()) }
end
generate() click to toggle source
# File lib/fluent/plugin/in_dummy.rb, line 90
def generate
  d = @dummy[@dummy_index]
  unless d
    @dummy_index = 0
    d = @dummy[0]
  end
  @dummy_index += 1
  if @auto_increment_key
    d = d.dup
    d[@auto_increment_key] = @increment_value
    @increment_value += 1
  end
  d
end
run() click to toggle source
# File lib/fluent/plugin/in_dummy.rb, line 69
def run
  batch_num    = (@rate / BIN_NUM).to_i
  residual_num = (@rate % BIN_NUM)
  while @running
    current_time = Time.now.to_i
    BIN_NUM.times do
      break unless (@running && Time.now.to_i <= current_time)
      wait(0.1) { emit(batch_num) }
    end
    emit(residual_num)
    # wait for next second
    while @running && Time.now.to_i <= current_time
      sleep 0.01
    end
  end
end
shutdown() click to toggle source
# File lib/fluent/plugin/in_dummy.rb, line 64
def shutdown
  @running = false
  @thread.join
end
start() click to toggle source
Calls superclass method Fluent::Input#start
# File lib/fluent/plugin/in_dummy.rb, line 58
def start
  super
  @running = true
  @thread = Thread.new(&method(:run))
end
wait(time) { || ... } click to toggle source
# File lib/fluent/plugin/in_dummy.rb, line 105
def wait(time)
  start_time = Time.now
  yield
  sleep_time = time - (Time.now - start_time)
  sleep sleep_time if sleep_time > 0
end