module Fluent::PluginHelper::EventLoop

Constants

EVENT_LOOP_RUN_DEFAULT_TIMEOUT

stop : [-] shutdown : detach all event watchers on event loop close : stop event loop terminate: initialize internal state

Attributes

_event_loop[R]

Public Class Methods

new() click to toggle source
Calls superclass method Fluent::PluginHelper::Thread.new
# File lib/fluent/plugin_helper/event_loop.rb, line 54
def initialize
  super
  @_event_loop = Coolio::Loop.new
  @_event_loop_running = false
  @_event_loop_mutex = Mutex.new
  # plugin MAY configure loop run timeout in #configure
  @_event_loop_run_timeout = EVENT_LOOP_RUN_DEFAULT_TIMEOUT
end

Public Instance Methods

close() click to toggle source
Calls superclass method Fluent::PluginHelper::Thread#close
# File lib/fluent/plugin_helper/event_loop.rb, line 87
def close
  if @_event_loop_running
    begin
      @_event_loop.stop # we cannot check loop is running or not
    rescue RuntimeError => e
      raise unless e.message == 'loop not running'
    end
  end

  super
end
event_loop_attach(watcher) click to toggle source
# File lib/fluent/plugin_helper/event_loop.rb, line 36
def event_loop_attach(watcher)
  @_event_loop_mutex.synchronize do
    @_event_loop.attach(watcher)
  end
end
event_loop_running?() click to toggle source
# File lib/fluent/plugin_helper/event_loop.rb, line 50
def event_loop_running?
  @_event_loop_running
end
event_loop_wait_until_start() click to toggle source
# File lib/fluent/plugin_helper/event_loop.rb, line 42
def event_loop_wait_until_start
  sleep(0.1) until event_loop_running?
end
event_loop_wait_until_stop() click to toggle source
# File lib/fluent/plugin_helper/event_loop.rb, line 46
def event_loop_wait_until_stop
  sleep(0.1) while event_loop_running?
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/event_loop.rb, line 76
def shutdown
  @_event_loop_mutex.synchronize do
    @_event_loop.watchers.each {|w| w.detach if w.attached? }
  end
  while @_event_loop_running
    sleep 0.1
  end

  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/event_loop.rb, line 63
def start
  super

  # event loop does not run here, so mutex lock is not required
  thread_create :event_loop do
    default_watcher = DefaultWatcher.new
    @_event_loop.attach(default_watcher)
    @_event_loop_running = true
    @_event_loop.run(@_event_loop_run_timeout) # this method blocks
    @_event_loop_running = false
  end
end
terminate() click to toggle source
Calls superclass method Fluent::PluginHelper::Thread#terminate
# File lib/fluent/plugin_helper/event_loop.rb, line 99
def terminate
  @_event_loop = nil
  @_event_loop_running = false
  @_event_loop_mutex = nil
  @_event_loop_run_timeout = nil

  super
end