Autopsy  4.21.0
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  */
19 package org.sleuthkit.autopsy.testutils;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.EnumSet;
26 import java.util.List;
27 import java.util.Set;
28 import javax.annotation.concurrent.GuardedBy;
34 import org.sleuthkit.datamodel.Content;
35 
39 public 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()
static List< IngestModuleError > runIngestJob(Collection< Content > dataSources, IngestJobSettings settings)
static final Set< IngestManager.IngestJobEvent > INGEST_JOB_EVENTS_OF_INTEREST
void addIngestJobEventListener(final PropertyChangeListener listener)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.