|
From: <de...@us...> - 2003-09-24 14:26:33
|
Update of /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker
In directory sc8-pr-cvs1:/tmp/cvs-serv30128/modules/scanner/src/com/babeldoc/scanner/worker
Modified Files:
DirectoryScanner.java
Log Message:
Applying David's patch with lastModified config option
Index: DirectoryScanner.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker/DirectoryScanner.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** DirectoryScanner.java 24 Sep 2003 09:00:20 -0000 1.21
--- DirectoryScanner.java 24 Sep 2003 14:26:29 -0000 1.22
***************
*** 99,102 ****
--- 99,103 ----
public static final String INCLUDE_SUB_DIRS = "includeSubfolders";
public static final String FILTER_FILENAME = "filter";
+ public static final String MINIMUM_FILE_AGE = "minimumFileAge";
public DirectoryScanner() {
***************
*** 113,116 ****
--- 114,123 ----
private boolean includeSubDirs = false;
+ /** Minimum time in ms since file was last modified.
+ * Attempts to guard against incomplete reads when
+ * the writer of the file is "slow".
+ */
+ private int minimumFileAge = 0;
+
/**
* This method will scan for new documents. It will queue documents by
***************
*** 166,169 ****
--- 173,183 ----
}
+ setMinimumFileAge(this.getInfo().getIntValue(MINIMUM_FILE_AGE));
+
+ if(getMinimumFileAge() > 0) {
+ LogService.getInstance().logInfo("Minimum file age: "
+ + getMinimumFileAge() + " ms");
+ }
+
//Add filename filter if exist
addFilter(FILTER_FILENAME);
***************
*** 233,237 ****
return isIncludeSubDirs();
} else {
! return acceptEntry(FILTER_FILENAME, current.getName());
}
}
--- 247,252 ----
return isIncludeSubDirs();
} else {
! //if file fulfils configured criteria
! return acceptFile(current);
}
}
***************
*** 297,300 ****
--- 312,349 ----
}
+ /**
+ * Consult configuration if this file should be processed
+ * or not. Current configurable constraints include the age
+ * of the file and a filename filter.
+ *
+ * @param file The file to be checked against configuration
+ * @return true If the file should be processed at this time
+ */
+ private boolean acceptFile(File file) {
+ // Check name filter first, and then age.
+ if(acceptEntry(FILTER_FILENAME, file.getName())) {
+ if(getMinimumFileAge() <= getFileAge(file)) {
+ return true;
+ } else {
+ LogService.getInstance().logDebug(
+ "Ignoring " + file.getName()
+ + " (age " + getFileAge(file) + " < " + getMinimumFileAge() + ")");
+ }
+ // Potentially add additional checks here.
+ }
+ return false;
+ }
+
+ /**
+ * Get age of file in ms.
+ *
+ * @param file The file to get the age of.
+ * @return long The age of the file in ms.
+ */
+ private long getFileAge(File file) {
+ return System.currentTimeMillis() - new Date(file.lastModified()).getTime();
+ }
+
+
public File getInDirectory() {
return inDirectory;
***************
*** 320,323 ****
--- 369,381 ----
this.includeSubDirs = includeSubDirs;
}
+
+ public int getMinimumFileAge() {
+ return minimumFileAge;
+ }
+
+ public void setMinimumFileAge(int minimumFileAge) {
+ if(minimumFileAge < 0) minimumFileAge = 0;
+ this.minimumFileAge = minimumFileAge;
+ }
}
***************
*** 383,386 ****
--- 441,452 ----
false,
I18n.get("scanner.DirectoryScannerInfo.option.filter")));
+
+ options.add(
+ new ConfigOption(
+ DirectoryScanner.MINIMUM_FILE_AGE,
+ IConfigOptionType.INTEGER,
+ null,
+ false,
+ I18n.get("scanner.DirectoryScannerInfo.option.minimumFileAge")));
return options;
|