ERXFileNotificationCenter Class Reference

Collaboration diagram for ERXFileNotificationCenter:

Collaboration graph
[legend]

List of all members.

Classes

class  _ObserverSelectorHolder

Public Member Functions

void addObserver (Object observer, NSSelector selector, File file)
void addObserver (Object observer, NSSelector selector, String filePath)
void checkIfFilesHaveChanged (NSNotification n)
 ERXFileNotificationCenter ()
void finalize () throws Throwable
boolean hasFileChanged (File file)
void registerLastModifiedDateForFile (File file)

Static Public Member Functions

static ERXFileNotificationCenter defaultCenter ()

Static Public Attributes

static final String FileDidChange = "FileDidChange"
static final Logger log = Logger.getLogger(ERXFileNotificationCenter.class)

Protected Member Functions

String cacheKeyForFile (File file)
Object cacheValueForFile (File file)
void fileHasChanged (File file)

Static Private Member Functions

static int checkFilesPeriod ()

Private Attributes

NSMutableDictionary _lastModifiedByFilePath = new NSMutableDictionary()
NSMutableDictionary _observersByFilePath = new NSMutableDictionary()
boolean developmentMode
long lastCheckMillis = System.currentTimeMillis()
boolean symlinkSupport

Static Private Attributes

static ERXFileNotificationCenter _defaultCenter


Detailed Description

The file notification center is only used in development systems. It provides a nice repository about files and their last modified dates. So instead of every dynamic spot having to keep track of the files' dates, register and check at the end of every request-response loop, instead you can just add an observer to this center and be notified when the file changes. Files' last modification dates are checked at the end of every request-response loop.

It should be noted that the current version of the file notification center will retain a reference to each registered observer. This is not ideal and will be corrected in the future.


Constructor & Destructor Documentation

Default constructor. If you are in development mode then this object will register for the notification com.webobjects.appserver.WOApplication#ApplicationWillDispatchRequestNotification which will enable it to check if files have changed at the end of every request-response loop. If WOCaching is enabled then this object will not register for anything and will generate warning messages if observers are registered with caching enabled.


Member Function Documentation

void addObserver ( Object  observer,
NSSelector  selector,
File  file 
)

Used to register file observers for a particular file.

Parameters:
observer object to be notified when a file changes
selector selector to be invoked on the observer when the file changes.
file file to watch for changes

void addObserver ( Object  observer,
NSSelector  selector,
String  filePath 
)

Used to register file observers for a particular file.

Parameters:
observer object to be notified when a file changes
selector selector to be invoked on the observer when the file changes.
filePath location of the file

String cacheKeyForFile ( File  file  )  [protected]

Returns the path that should be used as the cache key for the given file. This will return the absolute path of the file (specifically NOT the canonical path) so that we make sure to lookup files using their original sym links rather than resolving them at registration time.

Parameters:
file the file to lookup a cache key for
Returns:
the absolute path of the file

Object cacheValueForFile ( File  file  )  [protected]

Returns the value to cache to detect changes to this file. Currently this returns the lastModified date of the canonicalized version of this file, meaning that we compare the lastModified of the target of symlinks.

Parameters:
file the file to lookup a cache value for
Returns:
a value representing the current version of this file

static int checkFilesPeriod (  )  [static, private]

In seconds. 0 means we will not regularly check files.

void checkIfFilesHaveChanged ( NSNotification  n  ) 

Notified by the NSNotificationCenter at the end of every request-response loop. It is here that all of the currently watched files are checked to see if they have any changes.

Parameters:
n NSNotification notification posted from the NSNotificationCenter.

static ERXFileNotificationCenter defaultCenter (  )  [static]

Returns:
the singleton instance of file notification center

void fileHasChanged ( File  file  )  [protected]

Only used internally. Notifies all of the observers who have been registered for the given file.

Parameters:
file file that has changed

void finalize (  )  throws Throwable

When the file notification center is garbage collected it removes itself as an observer from the NSNotificationCenter. Not doing this will cause exceptions.

boolean hasFileChanged ( File  file  ) 

Compares the last modified date of the file with the last recorded modification date.

Parameters:
file file to compare last modified date.
Returns:
if the file has changed since the last time the lastModified value was recorded.

void registerLastModifiedDateForFile ( File  file  ) 

Records the last modified date of the file for future comparison.

Parameters:
file file to record the last modified date


Member Data Documentation

holds a reference to the default file notification center

cache for last modified dates of files by file path

collections of observers by file path

boolean developmentMode [private]

flag to tell if caching is enabled, set in the object constructor

final String FileDidChange = "FileDidChange" [static]

Contains the name of the notification that is posted when a file changes.

long lastCheckMillis = System.currentTimeMillis() [private]

The last time we checked files. We only check if !WOCachingEnabled or if there is a CheckFilesPeriod set

final Logger log = Logger.getLogger(ERXFileNotificationCenter.class) [static]

Logging support

boolean symlinkSupport [private]


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

Generated on Sat May 26 06:43:12 2012 for Project Wonder by  doxygen 1.5.8