class DirectoryWatcher::EmScanner
The EmScanner uses the EventMachine reactor loop to monitor changes to files in the watched directory. This scanner is more efficient than the pure Ruby scanner because it relies on the operating system kernel notifications instead of a periodic polling and stat of every file in the watched directory (the technique used by the Scanner class).
EventMachine cannot notify us when a file is added to the watched directory; therefore, added files are only picked up when we apply the glob pattern to the directory. This is done at the configured interval.
Notes:
* Kqueue does not generate notifications when "touch" is used to update a file's timestamp. This applies to Mac and BSD systems. * New files are detected only when the watched directory is polled at the configured interval.
Public Class Methods
# File lib/directory_watcher/em_scanner.rb, line 40 def initialize( config ) super(config) end
Public Instance Methods
Called by EventablScanner#start to start the loop up and attach the periodic timer that will poll the globs for new files.
# File lib/directory_watcher/em_scanner.rb, line 47 def start_loop_with_attached_scan_timer return if @loop_thread unless EventMachine.reactor_running? @loop_thread = Thread.new {EventMachine.run} Thread.pass until EventMachine.reactor_running? end @timer = ScanTimer.new(self) end
Called by EventableScanner#stop to stop the loop as part of the shutdown process.
# File lib/directory_watcher/em_scanner.rb, line 60 def stop_loop if @loop_thread then EventMachine.next_tick do EventMachine.stop_event_loop end @loop_thread.kill @loop_thread = nil end end