Autopsy  4.18.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;
33 import org.sleuthkit.datamodel.Content;
34 
38 public final class IngestJobRunner {
39 
41 
54  public static List<IngestModuleError> runIngestJob(Collection<Content> dataSources, IngestJobSettings settings) throws InterruptedException {
55  Object ingestMonitor = new Object();
56  IngestJobCompletiontListener completiontListener = new IngestJobCompletiontListener(ingestMonitor);
57  IngestManager ingestManager = IngestManager.getInstance();
58  ingestManager.addIngestJobEventListener(INGEST_JOB_EVENTS_OF_INTEREST, completiontListener);
59  try {
60  synchronized (ingestMonitor) {
61  IngestJobStartResult jobStartResult = ingestManager.beginIngestJob(dataSources, settings);
62  if (jobStartResult.getModuleErrors().isEmpty()) {
63  ingestMonitor.wait();
64  return Collections.emptyList();
65  } else {
66  return jobStartResult.getModuleErrors();
67  }
68  }
69  } finally {
70  ingestManager.removeIngestJobEventListener(completiontListener);
71  }
72  }
73 
77  private IngestJobRunner() {
78  }
79 
84  private static final class IngestJobCompletiontListener implements PropertyChangeListener {
85 
86  private final Object ingestMonitor;
87 
96  IngestJobCompletiontListener(Object ingestMonitor) {
97  this.ingestMonitor = ingestMonitor;
98  }
99 
106  @Override
107  public void propertyChange(PropertyChangeEvent event) {
108  if (AutopsyEvent.SourceType.LOCAL == ((AutopsyEvent) event).getSourceType()) {
109  String eventType = event.getPropertyName();
110  if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString()) || eventType.equals(IngestManager.IngestJobEvent.CANCELLED.toString())) {
111  synchronized (ingestMonitor) {
112  ingestMonitor.notify();
113  }
114  }
115  }
116  }
117  }
118 
119 }
static synchronized IngestManager getInstance()
static List< IngestModuleError > runIngestJob(Collection< Content > dataSources, IngestJobSettings settings)
IngestJobStartResult beginIngestJob(Collection< Content > dataSources, IngestJobSettings settings)
void removeIngestJobEventListener(final PropertyChangeListener listener)
static final Set< IngestManager.IngestJobEvent > INGEST_JOB_EVENTS_OF_INTEREST
void addIngestJobEventListener(final PropertyChangeListener listener)

Copyright © 2012-2021 Basis Technology. Generated on: Thu Jul 8 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.