cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/depend DependManager.java
costin 01/06/12 18:42:16 Modified:src/share/org/apache/tomcat/modules/mappers ReloadInterceptor.java src/share/org/apache/tomcat/util/depend DependManager.java Log: Added a setDebug to DependManager. Setting debug on the reload interceptor will also enable debugging in the DependManager ( those 2 are used to implement reloading ). JspInterceptor(34) uses a local DependManager for each page for the local JSPs. Revision ChangesPath 1.8 +3 -1 jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/ReloadInterceptor.java Index: ReloadInterceptor.java === RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/ReloadInterceptor.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ReloadInterceptor.java2001/06/08 03:05:19 1.7 +++ ReloadInterceptor.java2001/06/13 01:42:15 1.8 @@ -105,7 +105,9 @@ dm=new DependManager(); context.getContainer().setNote("DependManager", dm); } - + if( debug > 0 ) { + dm.setDebug( debug ); + } } /** Example of adding web.xml to the dependencies. 1.7 +10 -2 jakarta-tomcat/src/share/org/apache/tomcat/util/depend/DependManager.java Index: DependManager.java === RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/depend/DependManager.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- DependManager.java2001/06/08 03:12:45 1.6 +++ DependManager.java2001/06/13 01:42:16 1.7 @@ -134,7 +134,7 @@ public boolean shouldReload1() { // somebody else is checking, so we don't know yet. // assume we're fine - reduce the need for sync - if( debug > 0 && expired ) + if( debug > 0 && expired ) log( "ShouldReload1 E=" + expired + " C=" + checking); if( checking ) return expired; @@ -168,6 +168,7 @@ if( ! d.isLocal() ) { // if d is local, it'll just be marked as expired, // the DependManager will not. + // if( debug >0 ) expired=true; } } @@ -194,6 +195,9 @@ } public void setExpired( boolean e ) { + if( debug > 0 ) { + log( "SetExpired " + e ); + } for( int i=0; i
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/depend DependManager.java Dependency.java
costin 01/06/07 20:12:49 Modified:src/share/org/apache/tomcat/util/depend DependManager.java Dependency.java Log: Added a toString method to Dependency ( for easy debug/messages ). Added few convenience methods to DependManager. Revision ChangesPath 1.6 +23 -1 jakarta-tomcat/src/share/org/apache/tomcat/util/depend/DependManager.java Index: DependManager.java === RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/depend/DependManager.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- DependManager.java2001/03/07 23:39:20 1.5 +++ DependManager.java2001/06/08 03:12:45 1.6 @@ -76,7 +76,7 @@ */ public class DependManager { int delay=4000; -Dependency deps[]=new Dependency[32]; +Dependency deps[]; int depsCount=0; long lastCheck=0; boolean checking=false; @@ -84,8 +84,15 @@ int checkCount=0; private boolean expired=false; + +static final int INITIAL_DEP_SIZE=32; public DependManager() { + this( INITIAL_DEP_SIZE ); +} + +public DependManager(int initial_size) { + deps=new Dependency[initial_size]; } /** Reset the depend manager - all dependencies are reset too. @@ -177,6 +184,21 @@ } } +/** Update all times, so next "shouldReload" will happen if + * any time changes ( after the specified time ) + */ +public void setLastModified( long time ) { + for( int i=0; i= deps.length ) { Dependency deps1[]=new Dependency[ deps.length *2 ]; 1.4 +6 -1 jakarta-tomcat/src/share/org/apache/tomcat/util/depend/Dependency.java Index: Dependency.java === RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/depend/Dependency.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Dependency.java 2001/03/07 23:39:20 1.3 +++ Dependency.java 2001/06/08 03:12:46 1.4 @@ -150,7 +150,12 @@ return target; } - +public String toString() { + return "Dep(O=" + origin + " LM=" + lastModified + + " OLM=" + ((origin!=null) ? origin.lastModified() :0) + + " E=" + expired + ") "; +} + // methods /** Check if the origin changed since target's was lastModified.
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/depend DependManager.java Dependency.java
costin 01/03/07 15:39:21 Modified:src/share/org/apache/tomcat/util/depend DependManager.java Dependency.java Log: Add "reset" - this remove the need to replace the DependManager on reloading, and most of the extra setup. Revision ChangesPath 1.5 +11 -0 jakarta-tomcat/src/share/org/apache/tomcat/util/depend/DependManager.java Index: DependManager.java === RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/depend/DependManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DependManager.java2000/12/13 18:48:43 1.4 +++ DependManager.java2001/03/07 23:39:20 1.5 @@ -88,6 +88,17 @@ public DependManager() { } +/** Reset the depend manager - all dependencies are reset too. + This will be called after a reload +*/ +public void reset() { + expired=false; + for( int i=0; i
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/depend DependManager.java Dependency.java
costin 00/12/13 10:48:47 Modified:src/share/org/apache/tomcat/util/depend DependManager.java Dependency.java Log: Few small enhancements to the depend manager - some dependencies are "local" ( the case of a jsp file ), and don't triger the expiration of the full collection. Revision ChangesPath 1.4 +9 -7 jakarta-tomcat/src/share/org/apache/tomcat/util/depend/DependManager.java Index: DependManager.java === RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/depend/DependManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- DependManager.java2000/12/02 08:26:58 1.3 +++ DependManager.java2000/12/13 18:48:43 1.4 @@ -141,15 +141,17 @@ //exact science ( and no dep can be removed) for( int i=0; i0 ) if( debug > 0) - log("Found expired4 file " + f.getName()); - expired=true; - // at least one file is expired + log("Found expired file " + + d.getOrigin().getName()); + + if( ! d.isLocal() ) { + // if d is local, it'll just be marked as expired, + // the DependManager will not. + expired=true; + } } } checkTime += lastCheck-startCheck; 1.2 +78 -34 jakarta-tomcat/src/share/org/apache/tomcat/util/depend/Dependency.java Index: Dependency.java === RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/depend/Dependency.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Dependency.java 2000/08/14 18:40:35 1.1 +++ Dependency.java 2000/12/13 18:48:43 1.2 @@ -63,56 +63,100 @@ import java.util.zip.*; import java.security.*; -/** +/** Represents a dependency between a real file and a server object. + * The servler object has a timestamp, and it is compared with the + * file lastModified time to detect changes. + * + * The DependManager will do the checkings ( with the minimal possible + * overhead ). */ -public class Dependency { - - +public final class Dependency { + +private File origin; +private long lastModified; +private Object target; +private boolean localDep=false; +private boolean expired=false; + public Dependency() { } -long lastModified; - /** - * Get the value of lastModified. - * @return Value of lastModified. + * The time when the server-side object has been loaded/modified. + * + * @param v modification time */ -public long getLastModified() {return lastModified;} - +public void setLastModified(long v) { + this.lastModified = v; +} + +public long getLastModified() { + return lastModified; +} + /** - * Set the value of lastModified. - * @param v Value to assign to lastModified. + * If set, the dependency will be "local", i.e. will be marked as + * expired but the DependManager will not triger an expire at a higher + * level ( example: if a JSP changes, no need to reload the context ) */ -public void setLastModified(long v) {this.lastModified = v;} +public void setLocal(boolean b) { + localDep=b; +} - -File origin; +public boolean isLocal() { + return localDep; +} + +/** Mark this dependency as expired. + */ +public void setExpired( boolean b ) { + expired=b; +} + +public boolean isExpired() { + return expired; +} /** - * Get the value of origin. - * @return Value of origin. - */ -public File getOrigin() {return origin;} + * The file on which the server-side object depends or has been + * loaded from. + * + * @param v Value to assign to origin. + */ +public void setOrigin(File v) { + this.origin = v; +} -/** - * Set the value of origin. - * @param v Value to assign to origin. - */ -public void setOrigin(File v) {this.origin = v;} +public File getOrigin() { + return origin; +} -Object target; /** - * Get the value of target. - * @return Value of target. - */ -public Object getTarget() {return target;} + * Server-side object that is checked for dependency on the file. + * + * @param v
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/depend DependManager.java
costin 00/12/01 15:15:23 Modified:src/share/org/apache/tomcat/util/depend DependManager.java Log: Checked in "debug" version of DependManager. It seems the workaround works fine ( i.e. call the method from another method, ignore the result that is bogus and return the real value ) Revision ChangesPath 1.2 +27 -6 jakarta-tomcat/src/share/org/apache/tomcat/util/depend/DependManager.java Index: DependManager.java === RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/depend/DependManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DependManager.java2000/08/14 18:40:35 1.1 +++ DependManager.java2000/12/01 23:15:22 1.2 @@ -83,7 +83,7 @@ long checkTime=0; int checkCount=0; -boolean expired=false; +private boolean expired=false; public DependManager() { } @@ -100,22 +100,37 @@ public long getCheckCount() { return checkCount; } - -// Not synchronized - we do that inside + public boolean shouldReload() { + boolean b=shouldReload1(); + if( b!=expired) + log("BUG ( VM or Tomcat? ) shouldReload returns expired=" + b + + " and the real value is " + expired); + return expired; +} + +// Not synchronized - we do that inside +public boolean shouldReload1() { // somebody else is checking, so we don't know yet. // assume we're fine - reduce the need for sync + if( debug > 0 && expired ) + log( "ShouldReload1 E=" + expired + " C=" + checking); if( checking ) return expired; synchronized(this) { try { // someone else got here and did it before me + if( debug>0 && expired ) + log( "ShouldReload2 E=" + expired + " C=" + checking); if( checking ) return expired; // did a check in the last N seconds long startCheck=System.currentTimeMillis(); - if( startCheck - lastCheck < delay ) + if( startCheck - lastCheck < delay ) { + if( debug > 0 && expired ) + log( "ShouldReload3 E=" + expired + " C=" + checking); return expired; + } checking=true; @@ -127,7 +142,11 @@ File f=d.getOrigin(); if( lm < f.lastModified() ) { // something got modified + // if( debug>0 ) + if( debug > 0) + log("Found expired4 file " + f.getName()); expired=true; + // at least one file is expired } } checkTime += lastCheck-startCheck; @@ -136,6 +155,8 @@ } finally { checking=false; } + if( debug > 0 && expired ) + log( "ShouldReload5 E=" + expired + " C=" + checking); return expired; } } @@ -149,10 +170,10 @@ deps[depsCount++]= dep ; if( debug>2) log( "Added " + dep.getOrigin() + " " + dep.getTarget()); } - + // Private -private static final int debug=0; +private static final int debug=10; void log( String s ) { System.out.println("DependManager: " + s );