class LogStash::Codecs::IdentityMapCodec::PeriodicRunner

Public Class Methods

new(listener, interval, method_symbol) click to toggle source
# File lib/logstash/codecs/identity_map_codec.rb, line 42
def initialize(listener, interval, method_symbol)
  @listener, @interval = listener, interval
  @method_symbol = method_symbol
  @running = Concurrent::AtomicBoolean.new(false)
end

Public Instance Methods

running?() click to toggle source
# File lib/logstash/codecs/identity_map_codec.rb, line 65
def running?
  @running.true?
end
start() click to toggle source
# File lib/logstash/codecs/identity_map_codec.rb, line 48
def start
  return self if running?
  @running.make_true
  @thread = Thread.start do
    class_name = @listener.class.name.split('::').last # IdentityMapCodec
    LogStash::Util.set_thread_name("#{class_name}##{@method_symbol}")

    while running? do
      sleep @interval
      break if !running?
      break if (listener = @listener).nil?
      listener.send(@method_symbol)
    end
  end
  self
end
stop() click to toggle source
# File lib/logstash/codecs/identity_map_codec.rb, line 69
def stop
  return if !running?
  @running.make_false
  while @thread.alive?
    begin
      @thread.wakeup
    rescue ThreadError
      # thread might drop dead since the alive? check
    else
      @thread.join(0.1) # raises $! if there was any
    end
  end
  @listener = nil
end