class Riemann::Babbler::PluginManager

Constants

CHECK_ALIVE_PLUGINS

Public Class Methods

new(sender, array_of_klasses) click to toggle source
# File lib/riemann/babbler/plugin_manager.rb, line 10
def initialize(sender, array_of_klasses)
  @plugins = array_of_klasses
  @sender  = sender
  @mapping = Hash.new
end

Public Instance Methods

run!() click to toggle source
# File lib/riemann/babbler/plugin_manager.rb, line 16
def run!
  @plugins.map do |plugin|
    unless plugin.new(@sender).send(:run_plugin)
      log :unknown, "Disable plugin: #{plugin}, because it not started by condition: run_plugin"
      next
    end
    @mapping[plugin] = run_thread(plugin)
  end
  loop do
    check_alive
    sleep CHECK_ALIVE_PLUGINS
  end
end

Private Instance Methods

check_alive() click to toggle source
# File lib/riemann/babbler/plugin_manager.rb, line 42
def check_alive
  log :debug, "Check alive of threads [#{@mapping.count}]"
  @mapping.each do |plugin, thread|
    next if thread.alive?
    begin
      thread.join
    rescue => e
      log :error, "has error #{e.class}: #{e}\n #{e.backtrace.join("\n")}"
    end
    @mapping[plugin] = run_thread(plugin)
  end
end
run_thread(plugin) click to toggle source
# File lib/riemann/babbler/plugin_manager.rb, line 32
def run_thread(plugin)
  Thread.new {
    log :unknown, "Start plugin #{plugin}"
    plugin.new(@sender).run!
    Signal.trap('TERM') do
      shutdown
    end
  }
end
shutdown() click to toggle source
# File lib/riemann/babbler/plugin_manager.rb, line 55
def shutdown
  exit Errors::USER_CALL_SHUTDOWN
end