Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestJobRunner.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2018-2019 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.autopsy.testutils;
20
21import java.beans.PropertyChangeEvent;
22import java.beans.PropertyChangeListener;
23import java.util.Collection;
24import java.util.Collections;
25import java.util.EnumSet;
26import java.util.List;
27import java.util.Set;
28import javax.annotation.concurrent.GuardedBy;
29import org.sleuthkit.autopsy.events.AutopsyEvent;
30import org.sleuthkit.autopsy.ingest.IngestJobSettings;
31import org.sleuthkit.autopsy.ingest.IngestJobStartResult;
32import org.sleuthkit.autopsy.ingest.IngestManager;
33import org.sleuthkit.autopsy.ingest.IngestModuleError;
34import org.sleuthkit.datamodel.Content;
35
39public final class IngestJobRunner {
40
42
55 public static List<IngestModuleError> runIngestJob(Collection<Content> dataSources, IngestJobSettings settings) throws InterruptedException {
56 Object ingestMonitor = new Object();
57 IngestJobCompletionListener completiontListener = new IngestJobCompletionListener(ingestMonitor, dataSources.size());
58 IngestManager ingestManager = IngestManager.getInstance();
59 ingestManager.addIngestJobEventListener(INGEST_JOB_EVENTS_OF_INTEREST, completiontListener);
60 try {
61 synchronized (ingestMonitor) {
62 IngestJobStartResult jobStartResult = ingestManager.beginIngestJob(dataSources, settings);
63 if (jobStartResult.getModuleErrors().isEmpty()) {
64 ingestMonitor.wait();
65 return Collections.emptyList();
66 } else {
67 return jobStartResult.getModuleErrors();
68 }
69 }
70 } finally {
71 ingestManager.removeIngestJobEventListener(completiontListener);
72 }
73 }
74
78 private IngestJobRunner() {
79 }
80
85 private static final class IngestJobCompletionListener implements PropertyChangeListener {
86
87 private final Object ingestMonitor;
88
89 @GuardedBy("ingestMonitor")
90 private int remainingJobsCount;
91
101 IngestJobCompletionListener(Object ingestMonitor, int jobsCount) {
102 this.ingestMonitor = ingestMonitor;
103 this.remainingJobsCount = jobsCount;
104 }
105
112 @Override
113 public void propertyChange(PropertyChangeEvent event) {
114 if (AutopsyEvent.SourceType.LOCAL == ((AutopsyEvent) event).getSourceType()) {
115 String eventType = event.getPropertyName();
116 if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString()) || eventType.equals(IngestManager.IngestJobEvent.CANCELLED.toString())) {
117 synchronized (ingestMonitor) {
118 this.remainingJobsCount--;
119 if (this.remainingJobsCount <= 0) {
120 ingestMonitor.notify();
121 }
122 }
123 }
124 }
125 }
126 }
127
128}
static synchronized IngestManager getInstance()
IngestJobStartResult beginIngestJob(Collection< Content > dataSources, IngestJobSettings settings)
void removeIngestJobEventListener(final PropertyChangeListener listener)
void addIngestJobEventListener(final PropertyChangeListener listener)
static final Set< IngestManager.IngestJobEvent > INGEST_JOB_EVENTS_OF_INTEREST
static List< IngestModuleError > runIngestJob(Collection< Content > dataSources, IngestJobSettings settings)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.