geirm 01/02/16 06:26:04
Modified: src/java/org/apache/velocity/runtime/resource Resource.java
ResourceManager.java
Log:
Two tiny tweaks :
1) Resource : altered the 'checking' math to work in terms of seconds rather
than milliseconds, and further, let modificationInterval <= 0 mean 'no check'.
I added the '< 0' as a negative interval is meaningless - once we assign
meaning to it, we can redo.
2) ResourceManager : small tweak in the reloading section to update age and
'checking' counters so that after a reload, everything reset for the next
checking interval.
I think that is all.
Revision Changes Path
1.2 +19 -5
jakarta-velocity/src/java/org/apache/velocity/runtime/resource/Resource.java
Index: Resource.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/resource/Resource.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Resource.java 2000/12/19 05:30:05 1.1
+++ Resource.java 2001/02/16 14:26:02 1.2
@@ -69,7 +69,7 @@
* sources.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: Resource.java,v 1.1 2000/12/19 05:30:05 jvanzyl Exp $
+ * @version $Id: Resource.java,v 1.2 2001/02/16 14:26:02 geirm Exp $
*/
public abstract class Resource
{
@@ -84,7 +84,7 @@
* The number of milliseconds in a minute, used to calculate the
* check interval.
*/
- protected static final long MILLIS_PER_MINUTE = 60 * 1000;
+ protected static final long MILLIS_PER_SECOND = 1000;
/**
* How often the file modification time is checked (in milliseconds).
@@ -145,8 +145,22 @@
* Is it time to check to see if the resource
* source has been updated?
*/
- public boolean requiresChecking()
- {
+ public boolean requiresChecking()
+ {
+ /*
+ * short circuit this if modificationCheckInterval == 0
+ * as this means "don't check"
+ */
+
+ if (modificationCheckInterval <= 0 )
+ {
+ return false;
+ }
+
+ /*
+ * otherwise, see where we are
+ */
+
if ( lastCheck >= nextCheck)
{
return true;
@@ -165,7 +179,7 @@
public void touch()
{
lastCheck = System.currentTimeMillis();
- nextCheck = lastCheck + modificationCheckInterval;
+ nextCheck = lastCheck + ( MILLIS_PER_SECOND * modificationCheckInterval);
}
/**
1.8 +34 -10
jakarta-velocity/src/java/org/apache/velocity/runtime/resource/ResourceManager.java
Index: ResourceManager.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/resource/ResourceManager.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ResourceManager.java 2001/02/14 21:34:48 1.7
+++ ResourceManager.java 2001/02/16 14:26:03 1.8
@@ -71,7 +71,7 @@
* Runtime.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: ResourceManager.java,v 1.7 2001/02/14 21:34:48 dlr Exp $
+ * @version $Id: ResourceManager.java,v 1.8 2001/02/16 14:26:03 geirm Exp $
*/
public class ResourceManager
{
@@ -213,23 +213,47 @@
* the input stream and parse it to make a new
* AST for the resource.
*/
- if (resource.requiresChecking() &&
- resource.isSourceModified())
+ if ( resource.requiresChecking() )
{
- try
- {
- resource.process();
- return resource;
- }
- catch (Exception e)
+ /*
+ * touch() the resource to reset the counters
+ */
+
+ resource.touch();
+
+ if( resource.isSourceModified() )
{
- Runtime.error(e);
+ try
+ {
+ /*
+ * read in the fresh stream and parse
+ */
+
+ resource.process();
+
+ /*
+ * now set the modification info and reset
+ * the modification check counters
+ */
+
+ resource.setLastModified(
+ resourceLoader.getLastModified( resource ));
+ }
+ catch (Exception e)
+ {
+ Runtime.error(e);
+ }
}
}
+
return resource;
}
else
{
+ /*
+ * it's not in the cache
+ */
+
try
{
resource = ResourceFactory.getResource(resourceName, resourceType);