Merge remote-tracking branch 'upstream/develop' into 7673-postartifacts-feeds-pipeline-other-apis

This commit is contained in:
Richard Cordovano 2021-10-28 10:17:47 -04:00
commit 554586a1d0
2 changed files with 13 additions and 11 deletions

View File

@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import javax.annotation.concurrent.GuardedBy;
import org.sleuthkit.autopsy.events.AutopsyEvent;
import org.sleuthkit.autopsy.ingest.IngestJobSettings;
import org.sleuthkit.autopsy.ingest.IngestJobStartResult;
@ -53,7 +54,7 @@ public final class IngestJobRunner {
*/
public static List<IngestModuleError> runIngestJob(Collection<Content> dataSources, IngestJobSettings settings) throws InterruptedException {
Object ingestMonitor = new Object();
IngestJobCompletiontListener completiontListener = new IngestJobCompletiontListener(ingestMonitor);
IngestJobCompletionListener completiontListener = new IngestJobCompletionListener(ingestMonitor, dataSources.size());
IngestManager ingestManager = IngestManager.getInstance();
ingestManager.addIngestJobEventListener(INGEST_JOB_EVENTS_OF_INTEREST, completiontListener);
try {
@ -81,10 +82,13 @@ public final class IngestJobRunner {
* An ingest job event listener that allows IngestRunner.runIngestJob to
* block until the specified ingest job is completed.
*/
private static final class IngestJobCompletiontListener implements PropertyChangeListener {
private static final class IngestJobCompletionListener implements PropertyChangeListener {
private final Object ingestMonitor;
@GuardedBy("ingestMonitor")
private int remainingJobsCount;
/**
* Constructs an ingest job event listener that allows
* IngestRunner.runIngestJob to block until the specified ingest job is
@ -92,9 +96,11 @@ public final class IngestJobRunner {
*
* @param ingestMonitor A Java object to notify when the ingest job is
* omcpleted.
* @param jobsCount The number of jobs to listen for before notifying monitor.
*/
IngestJobCompletiontListener(Object ingestMonitor) {
IngestJobCompletionListener(Object ingestMonitor, int jobsCount) {
this.ingestMonitor = ingestMonitor;
this.remainingJobsCount = jobsCount;
}
/**
@ -109,11 +115,14 @@ public final class IngestJobRunner {
String eventType = event.getPropertyName();
if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString()) || eventType.equals(IngestManager.IngestJobEvent.CANCELLED.toString())) {
synchronized (ingestMonitor) {
this.remainingJobsCount--;
if (this.remainingJobsCount <= 0) {
ingestMonitor.notify();
}
}
}
}
}
}
}

View File

@ -82,13 +82,6 @@ public class IngestedWithHashAndFileTypeIntraCaseTest extends NbTestCase {
Exceptions.printStackTrace(ex);
Assert.fail(ex.getMessage());
}
// wait 10 seconds for all processes to finish before beginning tests
try {
Thread.sleep(10_000);
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
}
@Override