Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileIngestPipeline.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014 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.ingest;
20 
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
26 
34 final class FileIngestPipeline {
35 
36  private static final IngestManager ingestManager = IngestManager.getInstance();
37  private final DataSourceIngestJob job;
38  private final List<PipelineModule> modules = new ArrayList<>();
39  private Date startTime;
40  private volatile boolean running;
41 
51  FileIngestPipeline(DataSourceIngestJob job, List<IngestModuleTemplate> moduleTemplates) {
52  this.job = job;
53  for (IngestModuleTemplate template : moduleTemplates) {
54  if (template.isFileIngestModuleTemplate()) {
55  PipelineModule module = new PipelineModule(template.createFileIngestModule(), template.getModuleName());
56  modules.add(module);
57  }
58  }
59  }
60 
66  boolean isEmpty() {
67  return this.modules.isEmpty();
68  }
69 
75  boolean isRunning() {
76  return this.running;
77  }
78 
85  Date getStartTime() {
86  return this.startTime;
87  }
88 
94  synchronized List<IngestModuleError> startUp() {
95  this.startTime = new Date();
96  this.running = true;
97  List<IngestModuleError> errors = new ArrayList<>();
98  for (PipelineModule module : this.modules) {
99  try {
100  module.startUp(new IngestJobContext(this.job));
101  } catch (Throwable ex) { // Catch-all exception firewall
102  errors.add(new IngestModuleError(module.getDisplayName(), ex));
103  }
104  }
105  return errors;
106  }
107 
114  synchronized List<IngestModuleError> process(FileIngestTask task) {
115  List<IngestModuleError> errors = new ArrayList<>();
116  AbstractFile file = task.getFile();
117  for (PipelineModule module : this.modules) {
118  try {
119  FileIngestPipeline.ingestManager.setIngestTaskProgress(task, module.getDisplayName());
120  module.process(file);
121  } catch (Throwable ex) { // Catch-all exception firewall
122  errors.add(new IngestModuleError(module.getDisplayName(), ex));
123  String msg = ex.getMessage();
124  // Jython run-time errors don't seem to have a message, but have details in toString.
125  if (msg == null)
126  msg = ex.toString();
127  MessageNotifyUtil.Notify.error(module.getDisplayName() + " Error", msg);
128  }
129  if (this.job.isCancelled()) {
130  break;
131  }
132  }
133  file.close();
134  if (!this.job.isCancelled()) {
135  IngestManager.getInstance().fireFileIngestDone(file);
136  }
137  FileIngestPipeline.ingestManager.setIngestTaskProgressCompleted(task);
138  return errors;
139  }
140 
146  synchronized List<IngestModuleError> shutDown() {
147  List<IngestModuleError> errors = new ArrayList<>();
148  for (PipelineModule module : this.modules) {
149  try {
150  module.shutDown();
151  } catch (Throwable ex) { // Catch-all exception firewall
152  errors.add(new IngestModuleError(module.getDisplayName(), ex));
153  String msg = ex.getMessage();
154  // Jython run-time errors don't seem to have a message, but have details in toString.
155  if (msg == null)
156  msg = ex.toString();
157  MessageNotifyUtil.Notify.error(module.getDisplayName() + " Error", msg);
158  }
159  }
160  this.running = false;
161  return errors;
162  }
163 
167  private static final class PipelineModule implements FileIngestModule {
168 
169  private final FileIngestModule module;
170  private final String displayName;
171 
179  PipelineModule(FileIngestModule module, String displayName) {
180  this.module = module;
181  this.displayName = displayName;
182  }
183 
189  String getClassName() {
190  return module.getClass().getCanonicalName();
191  }
192 
198  String getDisplayName() {
199  return displayName;
200  }
201 
205  @Override
206  public void startUp(IngestJobContext context) throws IngestModuleException {
207  module.startUp(context);
208  }
209 
213  @Override
215  return module.process(file);
216  }
217 
221  @Override
222  public void shutDown() {
223  module.shutDown();
224  }
225 
226  }
227 
228 }
ProcessResult process(AbstractFile file)
void startUp(IngestJobContext context)

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.