Class: DirectoryWatcher::EmScanner
- Inherits:
-
EventableScanner
- Object
- EventableScanner
- DirectoryWatcher::EmScanner
- Defined in:
- lib/directory_watcher/em_scanner.rb
Overview
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.
Defined Under Namespace
Instance Attribute Summary
Attributes inherited from EventableScanner
#iterations, #maximum_iterations, #watchers
Instance Method Summary collapse
-
#initialize(config) ⇒ EmScanner
constructor
call-seq: EmScanner.new( configuration ).
-
#start_loop_with_attached_scan_timer ⇒ Object
Called by EventablScanner#start to start the loop up and attach the periodic timer that will poll the globs for new files.
-
#stop_loop ⇒ Object
Called by EventableScanner#stop to stop the loop as part of the shutdown process.
Methods inherited from EventableScanner
#collection_queue, #finished_iterations?, #interval, #join, #on_modified, #on_removed, #on_scan, #pause, #paused?, #resume, #run, #running?, #start, #stop
Methods included from Logable
Constructor Details
Instance Method Details
#start_loop_with_attached_scan_timer ⇒ Object
Called by EventablScanner#start to start the loop up and attach the periodic timer that will poll the globs for new files.
47 48 49 50 51 52 53 54 55 |
# 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 |
#stop_loop ⇒ Object
Called by EventableScanner#stop to stop the loop as part of the shutdown process.
60 61 62 63 64 65 66 67 68 |
# 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 |