lib/sinotify/notifier.rb
# Listen for linux inotify events, and as they come in
#   1. adapt them into Sinotify::Event objects 
#   2. 'announce' them using Cosell. 
# By default, Cosell is setup to Queue the announcements in a bg thread.
#
# The references to two different logs in this method may be a bit confusing. The @spy_logger 
# exclusively logs (spys on) events and announcements. The "log" method instead uses the @logger
# and logs errors and exceptions. The @logger is defined when creating this object (using the :logger
# option), and the @spy_logger is defined in the :spy! method.
#
Listen for linux inotify events, and as they come in
1. adapt them into Sinotify::Event objects
2. 'announce' them using Cosell.
By default, Cosell is setup to Queue the announcements in a bg thread.

The references to two different logs in this method may be a bit confusing. The @spy_logger
exclusively logs (spys on) events and announcements. The "log" method instead uses the @logger
and logs errors and exceptions. The @logger is defined when creating this object (using the :logger
option), and the @spy_logger is defined in the :spy. method.
Listen for linux inotify events and as they come in 1 . adapt them into Sinotify :: Event objects 2 . ' announce ' them using Cosell . By default Cosell is setup to Queue the announcements in a bg thread . The references to two different logs in this method may be a bit confusing . The @spy_logger exclusively logs ( spys on ) events and announcements . The " log " method instead uses the @logger and logs errors and exceptions . The @logger is defined when creating this object ( using the : logger option ) and the @spy_logger is defined in the : spy . method .
def start_prim_event_loop_thread
        raise "Already watching!" unless @watch_thread.nil?
        @watch_thread = Thread.new do
          begin
            self.prim_notifier.each_event do |prim_event|
              watch = self.watches[prim_event.watch_descriptor.to_s]
              if event_is_noise?(prim_event, watch)
                self.spy_logger.debug("Sinotify::Notifier Spy: Skipping noise[#{prim_event.inspect}]") if self.spy_on_prim_events
              else
                spy_on_prim_event(prim_event)
                if watch.nil?
                  self.log "Could not determine watch from descriptor #{prim_event.watch_descriptor}, something is wrong. Event: #{prim_event.inspect}", :warn
                else
                  event = Sinotify::Event.from_prim_event_and_watch(prim_event, watch)
                  self.announce event
                  if event.has_etype?(:create) && event.directory?
                    Thread.new do 
                      sleep 0.1
                      self.add_watch(event.path)
                    end
                  end
                  self.remove_watch(event.watch_descriptor) if event.has_etype?(:delete) && event.directory?
                  break if closed?
                end
              end
          end
          rescue Exception => x
            log "Exception: #{x}, trace: \n\t#{x.backtrace.join("\n\t")}", :error 
          end
          log "Exiting prim event loop thread for #{self}"
        end
      end
def start_prim_event_loop_thread raise "Already watching!" unless @watch_thread . nil? @watch_thread = Thread . new do begin self . prim_notifier . each_event do | prim_event | watch = self . watches [ prim_event . watch_descriptor . to_s ] if event_is_noise? ( prim_event , watch ) self . spy_logger . debug ( "Sinotify::Notifier Spy: Skipping noise[#{prim_event.inspect}]" ) if self . spy_on_prim_events else spy_on_prim_event ( prim_event ) if watch . nil? self . log "Could not determine watch from descriptor #{prim_event.watch_descriptor}, something is wrong. Event: #{prim_event.inspect}" , :warn else event = Sinotify :: Event . from_prim_event_and_watch ( prim_event , watch ) self . announce event if event . has_etype? ( :create ) && event . directory? Thread . new do sleep 0.1 self . add_watch ( event . path ) end end self . remove_watch ( event . watch_descriptor ) if event . has_etype? ( :delete ) && event . directory? break if closed? end end end rescue Exception => x log "Exception: #{x}, trace: \n\t#{x.backtrace.join("\n\t")}" , :error end log "Exiting prim event loop thread for #{self}" end end
Listen for linux inotify events, and as they come in
1. adapt them into Sinotify::Event objects
2.
Listen for linux inotify events and as they come in 1 . adapt them into Sinotify :: Event objects 2 .
# have to thread this because the :create event comes in _before_ the directory exists, # and inotify will not permit a watch on a file unless it exists # puts "REMOVING: #{event.inspect}, WATCH: #{self.watches[event.watch_descriptor.to_s]}" if event.has_etype?(:delete) && event.directory?