1
0
mirror of https://github.com/elisspace/autopsy.git synced 2026-09-04 06:50:00 +00:00

Added cancelation via Future

This commit is contained in:
Eugene Livis
2017-11-02 15:37:49 -04:00
parent 750af85e77
commit bd32abf036
2 changed files with 21 additions and 10 deletions

View File

@@ -89,6 +89,8 @@ class AddArchiveTask implements Runnable {
result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
callback.done(result, errorMessages, newDataSources);
}
logger.log(Level.INFO, "Using Archive Extractor DSP to process archive {0} ", archivePath);
// extract the archive and pass the extracted folder as input
UUID taskId = UUID.randomUUID();
@@ -151,6 +153,7 @@ class AddArchiveTask implements Runnable {
// identified a "valid" data source within the archive
progressMonitor.setProgressText(String.format("Adding: %s", file));
logger.log(Level.INFO, "Using {0} to process extracted file {1} ", new Object[]{selectedProcessor.getDataSourceType(), file});
/*
* NOTE: we have to move the valid data sources to a
@@ -204,6 +207,7 @@ class AddArchiveTask implements Runnable {
// after all archive contents have been examined (and moved to separate folders if necessary),
// add remaining extracted contents as one logical file set
progressMonitor.setProgressText(String.format("Adding: %s", destinationFolder.toString()));
logger.log(Level.INFO, "Adding directory {0} as logical file set", destinationFolder.toString());
synchronized (archiveDspLock) {
DataSource internalDataSource = new DataSource(deviceId, destinationFolder);
DataSourceProcessorCallback internalArchiveDspCallBack = new AddDataSourceCallback(currentCase, internalDataSource, taskId, archiveDspLock);
@@ -228,6 +232,7 @@ class AddArchiveTask implements Runnable {
errorMessages.add(ex.getMessage());
logger.log(Level.SEVERE, String.format("Critical error occurred while extracting archive %s", archivePath), ex); //NON-NLS
} finally {
logger.log(Level.INFO, "Finished processing of archive {0}", archivePath);
progressMonitor.setProgress(100);
if (criticalErrorOccurred) {
result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
@@ -252,11 +257,4 @@ class AddArchiveTask implements Runnable {
}
return newFolder;
}
/*
* Attempts to cancel adding the archive to the case database.
*/
public void cancelTask() {
// do a cancelation via future instead
}
}

View File

@@ -18,9 +18,15 @@
*/
package org.sleuthkit.autopsy.experimental.autoingest;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.nio.file.Path;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.swing.JPanel;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
import org.openide.util.lookup.ServiceProviders;
@@ -50,6 +56,9 @@ public class ArchiveExtractorDSProcessor implements DataSourceProcessor, AutoIng
private String archivePath;
private boolean setDataSourceOptionsCalled;
private final ExecutorService jobProcessingExecutor;
private Future<?> jobProcessingTaskFuture;
private static final String ARCHIVE_DSP_THREAD_NAME = "Archive-DSP-%d";
private AddArchiveTask addArchiveTask;
/**
@@ -60,6 +69,7 @@ public class ArchiveExtractorDSProcessor implements DataSourceProcessor, AutoIng
*/
public ArchiveExtractorDSProcessor() {
configPanel = ArchiveFilePanel.createInstance(ArchiveExtractorDSProcessor.class.getName(), ArchiveUtil.getArchiveFilters());
jobProcessingExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat(ARCHIVE_DSP_THREAD_NAME).build());
}
@Override
@@ -151,7 +161,7 @@ public class ArchiveExtractorDSProcessor implements DataSourceProcessor, AutoIng
*/
public void run(String deviceId, String archivePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
addArchiveTask = new AddArchiveTask(deviceId, archivePath, progressMonitor, callback);
new Thread(addArchiveTask).start();
jobProcessingTaskFuture = jobProcessingExecutor.submit(addArchiveTask);
}
/**
@@ -163,8 +173,11 @@ public class ArchiveExtractorDSProcessor implements DataSourceProcessor, AutoIng
*/
@Override
public void cancel() {
if (null != addArchiveTask) {
addArchiveTask.cancelTask();
if (null != jobProcessingTaskFuture) {
jobProcessingTaskFuture.cancel(true);
jobProcessingExecutor.shutdownNow();
// ELTBD - do we want to wait for the cancellation to complete? I think not,
// given that the cancelation is of "best effort" variety
}
}