|
From: <tr...@us...> - 2003-08-17 04:36:09
|
Update of /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner
In directory sc8-pr-cvs1:/tmp/cvs-serv17646/modules/scanner/src/com/babeldoc/scanner
Modified Files:
ScannerThread.java ScannerWorker.java ScannerWorkerInfo.java
Log Message:
Updates to the scanner code - added the count down option. Updated the I/ConfigInfo object for the getStrValue, getIntValue and the getValue methods for quick and easy access to the option values.
Index: ScannerThread.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/ScannerThread.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** ScannerThread.java 14 Aug 2003 02:34:20 -0000 1.16
--- ScannerThread.java 17 Aug 2003 04:12:29 -0000 1.17
***************
*** 73,77 ****
import com.babeldoc.core.LogService;
- import org.apache.commons.lang.NumberUtils;
--- 73,76 ----
***************
*** 101,113 ****
*/
public void run() {
! while (running) {
LogService.getInstance().logDebug(this.getName() + "scanning...");
- worker.process();
! try {
! sleep(getSleepTime(worker));
! } catch (InterruptedException e) {
! LogService.getInstance().logInfo("Thread " + this.getName() +
! " interrupted");
}
}
--- 100,114 ----
*/
public void run() {
! while (running && !(worker.isCountedDown())) {
! waitToRun();
LogService.getInstance().logDebug(this.getName() + "scanning...");
! if(!worker.isCronScheduleType()) {
! worker.process();
! } else {
! ScannerSchedule scanSchedule = worker.getCronSchedule();
! if(scanSchedule!=null&&scanSchedule.isTimeToRun()) {
! worker.process();
! }
}
}
***************
*** 117,144 ****
/**
! * Stop this thread running.
! */
! public void stopThread() {
! running = false;
! worker.stop();
! interrupt();
! }
!
! /**
! * DOCUMENT ME!
! *
! * @param worker
*
- * @return
*/
! private long getSleepTime(ScannerWorker worker) {
if (worker.isCronScheduleType()) {
//return milliseconds before next minute
long currentTime = System.currentTimeMillis();
! return (((currentTime / 60000) + 1) * 60000) - currentTime;
} else {
! return NumberUtils.stringToInt((String)worker.getInfo().getOption(ScannerWorkerInfo.SCANNER_PERIOD).getValue());
}
}
}
--- 118,151 ----
/**
! * Wait certain number of milliseconds to run.
*
*/
! private void waitToRun() {
! long sleepTime;
!
if (worker.isCronScheduleType()) {
//return milliseconds before next minute
long currentTime = System.currentTimeMillis();
! sleepTime = (((currentTime / 60000) + 1) * 60000) - currentTime;
} else {
! sleepTime = worker.getInfo().getIntValue(ScannerWorkerInfo.SCANNER_PERIOD);
}
+
+ try {
+ sleep(sleepTime);
+ } catch (InterruptedException e) {
+ LogService.getInstance().logInfo("Thread " + this.getName() +
+ " interrupted");
+ }
+ }
+
+ /**
+ * Stop this thread running.
+ */
+ public void stopThread() {
+ running = false;
+ worker.stop();
+ interrupt();
}
}
Index: ScannerWorker.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/ScannerWorker.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** ScannerWorker.java 14 Aug 2003 02:34:20 -0000 1.22
--- ScannerWorker.java 17 Aug 2003 04:12:29 -0000 1.23
***************
*** 103,106 ****
--- 103,113 ----
/** time in millis since the worker was started */
private long timeStarted;
+
+ /** The count down */
+ private int countdown;
+
+ /** holds the scanner schedule */
+ private ScannerSchedule cronSchedule = null;
+
public static final String SCANNER_KEY = "scanner";
public static final String SCAN_DATE_KEY = "scan_date";
***************
*** 124,128 ****
*/
public boolean isCronScheduleType() {
! return "true".equals(getInfo().getOption(ScannerWorkerInfo.SCANNER_CRON_SCHEDULE).getValue());
}
--- 131,154 ----
*/
public boolean isCronScheduleType() {
! return "true".equalsIgnoreCase(getInfo().getStrValue(ScannerWorkerInfo.SCANNER_CRON_SCHEDULE));
! }
!
! /**
! * Get the cron schedule from this worker. This will lazily create the schedule. If the schedule is
! * not provided in the configuration parameters, then return null. Also if the schedule is invalid,
! * log exception.
! *
! * @return cron schedule
! */
! public ScannerSchedule getCronSchedule() {
! String cronSched = getInfo().getStrValue(ScannerWorkerInfo.SCANNER_CRON_SCHEDULE);
! if(cronSchedule==null&&cronSched!=null) {
! try {
! cronSchedule = new ScannerSchedule(cronSched);
! } catch (Exception e) {
! getLog().logError(e);
! }
! }
! return cronSchedule;
}
***************
*** 214,217 ****
--- 240,244 ----
getLog().logInfo(getName() + " (" +
configData.getValue(ScannerWorkerInfo.SCANNER_TYPE) + ") configured...");
+ this.countdown = getInfo().getIntValue(ScannerWorkerInfo.COUNTDOWN);
}
***************
*** 242,246 ****
//Set status to stopped if worker should be ignored
! if ("true".equals(getInfo().getOption(ScannerWorkerInfo.IGNORED).getValue())) {
setStatus(ScannerWorkerStatus.STOPPED);
} else {
--- 269,273 ----
//Set status to stopped if worker should be ignored
! if ("true".equals(getInfo().getStrValue(ScannerWorkerInfo.IGNORED))) {
setStatus(ScannerWorkerStatus.STOPPED);
} else {
***************
*** 313,317 ****
*/
protected String getPipelineName() {
! return (String)this.getInfo().getOption(ScannerWorkerInfo.SCANNER_PIPELINE).getValue();
}
--- 340,344 ----
*/
protected String getPipelineName() {
! return this.getInfo().getStrValue(ScannerWorkerInfo.SCANNER_PIPELINE);
}
***************
*** 336,340 ****
FeedDocument feed = new FeedDocument(this.getPipelineName(), data, attr,
! !("false".equals(getInfo().getOption(ScannerWorkerInfo.JOURNAL).getValue())),
false);
--- 363,367 ----
FeedDocument feed = new FeedDocument(this.getPipelineName(), data, attr,
! !("false".equals(getInfo().getStrValue(ScannerWorkerInfo.JOURNAL))),
false);
***************
*** 447,450 ****
--- 474,478 ----
/**
* Set the last status change time.
+ *
* @param lastStatusChangeTime
*/
***************
*** 469,472 ****
--- 497,516 ----
protected void setTimeStarted(long timeStarted) {
this.timeStarted = timeStarted;
+ }
+
+ /**
+ * This scanner worker is considered counted down if the counter is NOT -1 or if
+ * post decrement == 0.
+ *
+ * @return
+ */
+ public boolean isCountedDown() {
+ if(countdown==-1) {
+ return false;
+ } else {
+ return countdown-- == 0;
+ }
+
+ // return !(countdown == -1) || countdown-- == 0;
}
}
Index: ScannerWorkerInfo.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/ScannerWorkerInfo.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** ScannerWorkerInfo.java 14 Aug 2003 02:34:20 -0000 1.10
--- ScannerWorkerInfo.java 17 Aug 2003 04:12:29 -0000 1.11
***************
*** 107,110 ****
--- 107,113 ----
public static String JOURNAL = "journal";
+ /** count down (if provided) from this number until zero - then stop scanning */
+ public static String COUNTDOWN = "countDown";
+
/**
* Return collection of options that are common to all scanners
***************
*** 144,147 ****
--- 147,153 ----
IConfigOptionType.BOOLEAN, "true", false,
"Should the scanner use the journal. Default is true"));
+ general.add(new ConfigOption(COUNTDOWN,
+ IConfigOptionType.INTEGER, "-1", false,
+ "The number of times this countdown must run."));
return general;
|