Qore fsevent Module ..
Loading...
Searching...
No Matches
FsEventPoller::AbstractDelayedFsEventPoller Class Reference

Delayed file notification handler. More...

#include <FsEventPoller.qm.dox.h>

Inheritance diagram for FsEventPoller::AbstractDelayedFsEventPoller:
FsEventPoller::AbstractFsEventPoller

Public Member Methods

 constructor (string path, *hash< FsDelayedEventPollerOptionInfo > options)
 Construct a file poller. More...
 
 destructor ()
 Stops the event thread if it's running.
 
int start ()
 starts polling in the background; returns the thread ID of the polling thread More...
 
 stop ()
 stops the polling operation, returns when the polling operation has been stopped More...
 
- Public Member Methods inherited from FsEventPoller::AbstractFsEventPoller
 constructor (string path, hash< AbstractFsEventPollerOptionInfo > options=< AbstractFsEventPollerOptionInfo >{})
 Construct a file poller. More...
 
abstract fileEvent (hash< FsEventInfo > event)
 Abstract method called whenever soem filesystem event occurs. More...
 

Private Member Methods

hash< string, hash< FsEventInfo > > m_cache ()
 cache of events keyed by file path
 
Counter m_start_counter (1)
 Counter that signals when the polling thread is running.
 
int startIntern ()
 Starts the background thread and returns the TID.
 
 runBackground ()
 Processes file events in the background.
 
- Private Member Methods inherited from FsEventPoller::AbstractFsEventPoller
 setMask (string mask)
 Set filesystem mask like in shell etc. More...
 
 logInfo (string fmt)
 calls the "log_info" closure or call reference with important information
 
 logDetail (string fmt)
 calls the "log_detail" closure or call reference with detail information
 
 logDebug (string fmt)
 calls the "log_debug" closure or call reference with verbose debugging information
 
 initialRun (string path)
 Called in the constructor to get already existing files/events.
 

Private Attributes

hash< string, date > age_map
 cache of ages: file path -> last modified date
 
int m_minage = 600
 the minimum age for events in seconds
 

Detailed Description

Delayed file notification handler.

The additional functionality of this class is to provide last modification timestamp check for affected files. The fileEvent() method is invoked only if the last modification timestamp is older than value specified by file_poller_delayed_constructor_hash key minage.

The example usecase can be when you need to communicate with applications which cannot write files atomically so your code needs to assume all is ready when the file is not modified in eg. 5 minutes.

Algorithm used:

  • file events are registered in the internal cache (hash m_cache) in form: file - ast modification timestamp
  • there is a background thread running in the infinite loop until the stop() method is called
  • the background thread periodically checks the internal cache to compare all timestamps with their validity against "minage" value
  • the fileEvent() is invoked only when relative modification timestamp is lesser then "minage" value

Member Function Documentation

◆ constructor()

FsEventPoller::AbstractDelayedFsEventPoller::constructor ( string  path,
*hash< FsDelayedEventPollerOptionInfo options 
)

Construct a file poller.

Parameters
patha string with full path to the directory to be monitored
optionsa hash with features settings; see FsDelayedEventPollerOptionInfo for details about this parameter

◆ start()

int FsEventPoller::AbstractDelayedFsEventPoller::start ( )

starts polling in the background; returns the thread ID of the polling thread

if polling had already been started, then the thread ID of the polling thread is returned immediately

◆ stop()

FsEventPoller::AbstractDelayedFsEventPoller::stop ( )

stops the polling operation, returns when the polling operation has been stopped

if polling was not in progress then this method returns immediately

Exceptions
THREAD-ERRORthis exception is thrown if this method is called from the event thread since it would result in a deadlock

The documentation for this class was generated from the following file: