diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index e748f7befd..e13e0fdd5b 100755 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -80,7 +80,7 @@ public final class KeywordSearchIngestModule extends IngestModuleAdapter impleme //only search images from current ingest, not images previously ingested/indexed //accessed read-only by searcher thread private AtomicInteger messageID = new AtomicInteger(0); - private boolean processedFiles; + private boolean startedSearching = false; private SleuthkitCase caseHandle = null; private static List textExtractors; private static AbstractFileStringExtract stringExtractor; @@ -88,7 +88,7 @@ public final class KeywordSearchIngestModule extends IngestModuleAdapter impleme private boolean initialized = false; private Tika tikaFormatDetector; private long jobId; - private long dataSourceId; + private long dataSourceId; private enum IngestStatus { @@ -179,8 +179,6 @@ public final class KeywordSearchIngestModule extends IngestModuleAdapter impleme NbBundle.getMessage(this.getClass(), "KeywordSearchIngestModule.init.onlyIdxKwSkipMsg"))); } - processedFiles = false; - indexer = new Indexer(); final int updateIntervalMs = KeywordSearchSettings.getUpdateFrequency().getTime() * 60 * 1000; @@ -219,14 +217,15 @@ public final class KeywordSearchIngestModule extends IngestModuleAdapter impleme return ProcessResult.OK; } - processedFiles = true; - //index the file and content (if the content is supported) indexer.indexFile(abstractFile, true); // Start searching if it hasn't started already - List keywordListNames = settings.getNamesOfEnabledKeyWordLists(); - SearchRunner.getInstance().startJob(jobId, dataSourceId, keywordListNames); + if (!startedSearching) { + List keywordListNames = settings.getNamesOfEnabledKeyWordLists(); + SearchRunner.getInstance().startJob(jobId, dataSourceId, keywordListNames); + startedSearching = true; + } return ProcessResult.OK; } diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SearchRunner.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SearchRunner.java index cdd1f4a4b0..8c6e8b3ce4 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SearchRunner.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SearchRunner.java @@ -30,6 +30,7 @@ import java.util.Map.Entry; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; import java.util.logging.Level; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; @@ -97,6 +98,8 @@ public final class SearchRunner { jobs.put(jobId, jobData); } + jobs.get(jobId).incrementModuleReferenceCount(); + if (jobs.size() > 0) { if (!updateTimer.isRunning()) { updateTimer.start(); @@ -111,16 +114,24 @@ public final class SearchRunner { */ public void endJob(long jobId) { SearchJobInfo job; + boolean readyForFinalSearch = false; synchronized(this) { job = jobs.get(jobId); if (job == null) { return; - } - jobs.remove(jobId); + } + + // Only do final search if this is the last module in this job to call endJob() + if(job.decrementModuleReferenceCount() == 0) { + jobs.remove(jobId); + readyForFinalSearch = true; + } + } + + if (readyForFinalSearch) { + commit(); + doFinalSearch(job); //this will block until it's done } - - commit(); - doFinalSearch(job); //this will block until it's done } @@ -257,7 +268,8 @@ public final class SearchRunner { private List keywordListNames; //guarded by SearchJobInfo.this private Map> currentResults; //guarded by SearchJobInfo.this private SearchRunner.Searcher currentSearcher; - + private AtomicLong moduleReferenceCount = new AtomicLong(0); + public SearchJobInfo(long jobId, long dataSourceId, List keywordListNames) { this.jobId = jobId; this.dataSourceId = dataSourceId; @@ -306,6 +318,14 @@ public final class SearchRunner { public synchronized void setCurrentSearcher(SearchRunner.Searcher searchRunner) { currentSearcher = searchRunner; } + + public void incrementModuleReferenceCount() { + moduleReferenceCount.incrementAndGet(); + } + + public long decrementModuleReferenceCount() { + return moduleReferenceCount.decrementAndGet(); + } } /**