Class URLChangeTracker<T>
- java.lang.Object
-
- org.apache.tapestry5.ioc.internal.util.URLChangeTracker<T>
-
- Type Parameters:
T
- The type of the optional information about the tracked resource. This type should implementequals()
andhashCode()
.
public class URLChangeTracker<T> extends java.lang.Object
Given a (growing) set of URLs, can periodically check to see if any of the underlying resources has changed. This class is capable of using either millisecond-level granularity or second-level granularity. Millisecond-level granularity is used by default. Second-level granularity is provided for compatibility with browsers vis-a-vis resource caching -- that's how granular they get with their "If-Modified-Since", "Last-Modified" and "Expires" headers.
-
-
Field Summary
Fields Modifier and Type Field Description static ClasspathURLConverter
DEFAULT_CONVERTER
-
Constructor Summary
Constructors Constructor Description URLChangeTracker()
Creates a tracker using the default (does nothing) URL converter, with default (millisecond) granularity and folder tracking disabled.URLChangeTracker(ClasspathURLConverter classpathURLConverter)
Creates a new URL change tracker with millisecond-level granularity and folder checking enabled.URLChangeTracker(ClasspathURLConverter classpathURLConverter, boolean granularitySeconds)
Creates a new URL change tracker, using either millisecond-level granularity or second-level granularity and folder checking enabled.URLChangeTracker(ClasspathURLConverter classpathURLConverter, boolean granularitySeconds, boolean trackFolderChanges)
Creates a new URL change tracker, using either millisecond-level granularity or second-level granularity.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description long
add(java.net.URL url)
Stores a new URL into the tracker, or returns the previous time stamp for a previously added URL.long
add(java.net.URL url, T resourceInfo)
Stores a new URL and associated memo (most probably a related class name) into the tracker, or returns the previous time stamp for a previously added URL.void
clear()
Clears all URL and timestamp data stored in the tracker.boolean
containsChanges()
Re-acquires the last updated timestamp for each URL and returns true if any timestamp has changed.void
forceChange()
Needed for testing; changes file timestamps so that a change will be detected bycontainsChanges()
.java.util.Set<T>
getChangedResourcesInfo()
Re-acquires the last updated timestamp for each URL and returns the non-null resource information for all files with a changed timestamp.static java.io.File
toFileFromFileProtocolURL(java.net.URL url)
Converts a URL with protocol "file" to a File instance.
-
-
-
Field Detail
-
DEFAULT_CONVERTER
public static final ClasspathURLConverter DEFAULT_CONVERTER
-
-
Constructor Detail
-
URLChangeTracker
public URLChangeTracker()
Creates a tracker using the default (does nothing) URL converter, with default (millisecond) granularity and folder tracking disabled.- Since:
- 5.2.1
-
URLChangeTracker
public URLChangeTracker(ClasspathURLConverter classpathURLConverter)
Creates a new URL change tracker with millisecond-level granularity and folder checking enabled.- Parameters:
classpathURLConverter
- used to convert URLs from one protocol to another
-
URLChangeTracker
public URLChangeTracker(ClasspathURLConverter classpathURLConverter, boolean granularitySeconds)
Creates a new URL change tracker, using either millisecond-level granularity or second-level granularity and folder checking enabled.- Parameters:
classpathURLConverter
- used to convert URLs from one protocol to anothergranularitySeconds
- whether or not to use second granularity (as opposed to millisecond granularity)
-
URLChangeTracker
public URLChangeTracker(ClasspathURLConverter classpathURLConverter, boolean granularitySeconds, boolean trackFolderChanges)
Creates a new URL change tracker, using either millisecond-level granularity or second-level granularity.- Parameters:
classpathURLConverter
- used to convert URLs from one protocol to anothergranularitySeconds
- whether or not to use second granularity (as opposed to millisecond granularity)trackFolderChanges
- if true, then adding a file URL will also track the folder containing the file (this is useful when concerned about additions to a folder)- Since:
- 5.2.1
-
-
Method Detail
-
toFileFromFileProtocolURL
public static java.io.File toFileFromFileProtocolURL(java.net.URL url)
Converts a URL with protocol "file" to a File instance.- Since:
- 5.2.0
-
add
public long add(java.net.URL url)
Stores a new URL into the tracker, or returns the previous time stamp for a previously added URL. Filters out all non-file URLs.- Parameters:
url
- of the resource to add, or null if not known- Returns:
- the current timestamp for the URL (possibly rounded off for granularity reasons), or 0 if the URL is null
-
add
public long add(java.net.URL url, T resourceInfo)
Stores a new URL and associated memo (most probably a related class name) into the tracker, or returns the previous time stamp for a previously added URL. Filters out all non-file URLs.- Parameters:
url
- of the resource to add, or null if not knownresourceInfo
- an optional object containing information about the tracked URL. It's returned in thegetChangedResourcesInfo()
method.- Returns:
- the current timestamp for the URL (possibly rounded off for granularity reasons), or 0 if the URL is null
- Since:
- 5.8.3
-
clear
public void clear()
Clears all URL and timestamp data stored in the tracker.
-
containsChanges
public boolean containsChanges()
Re-acquires the last updated timestamp for each URL and returns true if any timestamp has changed.
-
getChangedResourcesInfo
public java.util.Set<T> getChangedResourcesInfo()
Re-acquires the last updated timestamp for each URL and returns the non-null resource information for all files with a changed timestamp.
-
forceChange
public void forceChange()
Needed for testing; changes file timestamps so that a change will be detected bycontainsChanges()
.
-
-