+ * If choosing to defer the automatic scanning, a future call to {@link #startScanning()} + * is required to initiate this Scanner so that it can begin report files in the {@link #setScanDirs(List)} + *
+ * + * @param autostart true if scanning should start automatically, false to defer start of scanning to a later call to {@link #startScanning()} + */ + public void setAutoStartScanning(boolean autostart) + { + this._autoStartScanning = autostart; + } + /** * Whether or not an initial scan will report all files as being * added. @@ -587,8 +619,37 @@ public class Scanner extends ContainerLifeCycle public void doStart() throws Exception { if (LOG.isDebugEnabled()) - LOG.debug("Scanner start: rprtExists={}, depth={}, rprtDirs={}, interval={}, filter={}, scannables={}", - _reportExisting, _scanDepth, _reportDirs, _scanInterval, _filter, _scannables); + LOG.debug("Scanner start: autoStartScanning={}, reportExists={}, depth={}, rprtDirs={}, interval={}, filter={}, scannables={}", + isAutoStartScanning(), _reportExisting, _scanDepth, _reportDirs, _scanInterval, _filter, _scannables); + + // Start the scanner and managed beans (eg: the scheduler) + super.doStart(); + + if (isAutoStartScanning()) + { + startScanning(); + } + } + + /** + * Start scanning. + *+ * This will perform the initial scan of the directories {@link #setScanDirs(List)} + * and schedule future scans, following all of the configuration + * of the scan (eg: {@link #setReportExistingFilesOnStartup(boolean)}) + *
+ */ + public void startScanning() + { + if (!isRunning()) + throw new IllegalStateException("Scanner not started"); + + if (_scanningStarted) + return; + _scanningStarted = true; + + if (LOG.isDebugEnabled()) + LOG.debug("{}.startup()", this.getClass().getSimpleName()); if (_reportExisting) { @@ -602,9 +663,7 @@ public class Scanner extends ContainerLifeCycle _prevScan = scanFiles(); } - super.doStart(); - - //schedule the scan + // schedule further scans schedule(); } @@ -624,6 +683,7 @@ public class Scanner extends ContainerLifeCycle _task = null; if (task != null) task.cancel(); + _scanningStarted = false; } /** @@ -712,7 +772,7 @@ public class Scanner extends ContainerLifeCycle } /** - * Scan all of the given paths. + * Scan all the given paths. */ private Map