Only do final search if this is the last module in this job to call endJob()

This commit is contained in:
Samuel H. Kenyon 2014-04-03 17:25:23 -04:00
parent d3321853e0
commit 7913ecf25d
2 changed files with 33 additions and 14 deletions

View File

@ -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<AbstractFileExtract> 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<String> keywordListNames = settings.getNamesOfEnabledKeyWordLists();
SearchRunner.getInstance().startJob(jobId, dataSourceId, keywordListNames);
if (!startedSearching) {
List<String> keywordListNames = settings.getNamesOfEnabledKeyWordLists();
SearchRunner.getInstance().startJob(jobId, dataSourceId, keywordListNames);
startedSearching = true;
}
return ProcessResult.OK;
}

View File

@ -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<String> keywordListNames; //guarded by SearchJobInfo.this
private Map<Keyword, List<Long>> currentResults; //guarded by SearchJobInfo.this
private SearchRunner.Searcher currentSearcher;
private AtomicLong moduleReferenceCount = new AtomicLong(0);
public SearchJobInfo(long jobId, long dataSourceId, List<String> 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();
}
}
/**