Project Wonder 5.0

er.extensions.foundation
Class ERXFileNotificationCenter

java.lang.Object
  extended by er.extensions.foundation.ERXFileNotificationCenter

public class ERXFileNotificationCenter
extends java.lang.Object

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.


Nested Class Summary
static class ERXFileNotificationCenter._ObserverSelectorHolder
          Simple observer-selector holder class.
 
Field Summary
static java.lang.String FileDidChange
          Contains the name of the notification that is posted when a file changes.
static org.apache.log4j.Logger log
          Logging support
 
Constructor Summary
ERXFileNotificationCenter()
          Default constructor.
 
Method Summary
 void addObserver(java.lang.Object observer, com.webobjects.foundation.NSSelector selector, java.io.File file)
          Used to register file observers for a particular file.
 void addObserver(java.lang.Object observer, com.webobjects.foundation.NSSelector selector, java.lang.String filePath)
          Used to register file observers for a particular file.
protected  java.lang.String cacheKeyForFile(java.io.File file)
          Returns the path that should be used as the cache key for the given file.
protected  java.lang.Object cacheValueForFile(java.io.File file)
          Returns the value to cache to detect changes to this file.
 void checkIfFilesHaveChanged(com.webobjects.foundation.NSNotification n)
          Notified by the NSNotificationCenter at the end of every request-response loop.
static ERXFileNotificationCenter defaultCenter()
           
protected  void fileHasChanged(java.io.File file)
          Only used internally.
 void finalize()
          When the file notification center is garbage collected it removes itself as an observer from the NSNotificationCenter.
 boolean hasFileChanged(java.io.File file)
          Compares the last modified date of the file with the last recorded modification date.
 void registerLastModifiedDateForFile(java.io.File file)
          Records the last modified date of the file for future comparison.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.log4j.Logger log
Logging support


FileDidChange

public static final java.lang.String FileDidChange
Contains the name of the notification that is posted when a file changes.

See Also:
Constant Field Values
Constructor Detail

ERXFileNotificationCenter

public ERXFileNotificationCenter()
Default constructor. If you are in development mode then this object will register for the notification 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.

Method Detail

defaultCenter

public static ERXFileNotificationCenter defaultCenter()
Returns:
the singleton instance of file notification center

finalize

public void finalize()
              throws java.lang.Throwable
When the file notification center is garbage collected it removes itself as an observer from the NSNotificationCenter. Not doing this will cause exceptions.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

addObserver

public void addObserver(java.lang.Object observer,
                        com.webobjects.foundation.NSSelector selector,
                        java.lang.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

addObserver

public void addObserver(java.lang.Object observer,
                        com.webobjects.foundation.NSSelector selector,
                        java.io.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

cacheKeyForFile

protected java.lang.String cacheKeyForFile(java.io.File file)
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

cacheValueForFile

protected java.lang.Object cacheValueForFile(java.io.File file)
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

registerLastModifiedDateForFile

public void registerLastModifiedDateForFile(java.io.File file)
Records the last modified date of the file for future comparison.

Parameters:
file - file to record the last modified date

hasFileChanged

public boolean hasFileChanged(java.io.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.

fileHasChanged

protected void fileHasChanged(java.io.File file)
Only used internally. Notifies all of the observers who have been registered for the given file.

Parameters:
file - file that has changed

checkIfFilesHaveChanged

public void checkIfFilesHaveChanged(com.webobjects.foundation.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.

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.