rename queueDBWorkerTask ->queueDBTask, don't bother putting task on bg thread, remove unused executor

This commit is contained in:
millmanorama 2017-06-22 12:53:24 +02:00
parent ebad833635
commit 1b26096503
3 changed files with 42 additions and 63 deletions

View File

@ -25,7 +25,6 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
@ -88,18 +87,11 @@ import org.sleuthkit.datamodel.TskData;
* Connects different parts of ImageGallery together and is hub for flow of * Connects different parts of ImageGallery together and is hub for flow of
* control. * control.
*/ */
public final class ImageGalleryController implements Executor { public final class ImageGalleryController {
private static final Logger LOGGER = Logger.getLogger(ImageGalleryController.class.getName()); private static final Logger LOGGER = Logger.getLogger(ImageGalleryController.class.getName());
private static ImageGalleryController instance; private static ImageGalleryController instance;
private final Region infoOverLayBackground = new Region() {
{
setBackground(new Background(new BackgroundFill(Color.GREY, CornerRadii.EMPTY, Insets.EMPTY)));
setOpacity(.4);
}
};
/** /**
* true if Image Gallery should listen to ingest events, false if it should * true if Image Gallery should listen to ingest events, false if it should
* not listen to speed up ingest * not listen to speed up ingest
@ -112,7 +104,7 @@ public final class ImageGalleryController implements Executor {
private final ReadOnlyBooleanWrapper metaDataCollapsed = new ReadOnlyBooleanWrapper(false); private final ReadOnlyBooleanWrapper metaDataCollapsed = new ReadOnlyBooleanWrapper(false);
private final ReadOnlyDoubleWrapper thumbnailSize = new ReadOnlyDoubleWrapper(100); private final ReadOnlyDoubleWrapper thumbnailSize = new ReadOnlyDoubleWrapper(100);
private final ReadOnlyBooleanWrapper regroupDisabled = new ReadOnlyBooleanWrapper(false); private final ReadOnlyBooleanWrapper regroupDisabled = new ReadOnlyBooleanWrapper(false);
private final ReadOnlyIntegerWrapper queueSizeProperty = new ReadOnlyIntegerWrapper(0); private final ReadOnlyIntegerWrapper dbTaskQueueSize = new ReadOnlyIntegerWrapper(0);
private final FileIDSelectionModel selectionModel = new FileIDSelectionModel(this); private final FileIDSelectionModel selectionModel = new FileIDSelectionModel(this);
@ -128,19 +120,18 @@ public final class ImageGalleryController implements Executor {
private StackPane fullUIStackPane; private StackPane fullUIStackPane;
private StackPane centralStackPane; private StackPane centralStackPane;
private Node infoOverlay; private Node infoOverlay;
private final Region infoOverLayBackground = new Region() {
private final Executor execDelegate = Executors.newSingleThreadExecutor(); {
setBackground(new Background(new BackgroundFill(Color.GREY, CornerRadii.EMPTY, Insets.EMPTY)));
setOpacity(.4);
}
};
private ListeningExecutorService dbExecutor; private ListeningExecutorService dbExecutor;
private SleuthkitCase sleuthKitCase; private SleuthkitCase sleuthKitCase;
private DrawableDB db; private DrawableDB db;
@Override
public void execute(Runnable command) {
execDelegate.execute(command);
}
public static synchronized ImageGalleryController getDefault() { public static synchronized ImageGalleryController getDefault() {
if (instance == null) { if (instance == null) {
instance = new ImageGalleryController(); instance = new ImageGalleryController();
@ -221,7 +212,7 @@ public final class ImageGalleryController implements Executor {
//if we just turned on listening and a case is open and that case is not up to date //if we just turned on listening and a case is open and that case is not up to date
if (newValue && !oldValue && Case.isCaseOpen() && ImageGalleryModule.isDrawableDBStale(Case.getCurrentCase())) { if (newValue && !oldValue && Case.isCaseOpen() && ImageGalleryModule.isDrawableDBStale(Case.getCurrentCase())) {
//populate the db //populate the db
queueDBWorkerTask(new CopyAnalyzedFiles(instance, db, sleuthKitCase)); queueDBTask(new CopyAnalyzedFiles(instance, db, sleuthKitCase));
} }
}); });
@ -256,7 +247,7 @@ public final class ImageGalleryController implements Executor {
ingestManager.addIngestModuleEventListener(ingestEventHandler); ingestManager.addIngestModuleEventListener(ingestEventHandler);
ingestManager.addIngestJobEventListener(ingestEventHandler); ingestManager.addIngestJobEventListener(ingestEventHandler);
queueSizeProperty.addListener(obs -> this.updateRegroupDisabled()); dbTaskQueueSize.addListener(obs -> this.updateRegroupDisabled());
} }
public ReadOnlyBooleanProperty getCanAdvance() { public ReadOnlyBooleanProperty getCanAdvance() {
@ -285,7 +276,7 @@ public final class ImageGalleryController implements Executor {
@ThreadConfined(type = ThreadConfined.ThreadType.JFX) @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
private void updateRegroupDisabled() { private void updateRegroupDisabled() {
regroupDisabled.set((queueSizeProperty.get() > 0) || IngestManager.getInstance().isIngestRunning()); regroupDisabled.set((dbTaskQueueSize.get() > 0) || IngestManager.getInstance().isIngestRunning());
} }
/** /**
@ -316,7 +307,7 @@ public final class ImageGalleryController implements Executor {
new ProgressIndicator())); new ProgressIndicator()));
} }
} else if (queueSizeProperty.get() > 0) { } else if (dbTaskQueueSize.get() > 0) {
replaceNotification(fullUIStackPane, replaceNotification(fullUIStackPane,
new NoGroupsDialog(Bundle.ImageGalleryController_noGroupsDlg_msg3(), new NoGroupsDialog(Bundle.ImageGalleryController_noGroupsDlg_msg3(),
new ProgressIndicator())); new ProgressIndicator()));
@ -436,7 +427,7 @@ public final class ImageGalleryController implements Executor {
* *
* @param bgTask * @param bgTask
*/ */
public synchronized void queueDBWorkerTask(BackgroundTask bgTask) { public synchronized void queueDBTask(BackgroundTask bgTask) {
if (dbExecutor == null || dbExecutor.isShutdown()) { if (dbExecutor == null || dbExecutor.isShutdown()) {
dbExecutor = getNewDBExecutor(); dbExecutor = getNewDBExecutor();
} }
@ -446,11 +437,11 @@ public final class ImageGalleryController implements Executor {
} }
private void incrementQueueSize() { private void incrementQueueSize() {
Platform.runLater(() -> queueSizeProperty.set(queueSizeProperty.get() + 1)); Platform.runLater(() -> dbTaskQueueSize.set(dbTaskQueueSize.get() + 1));
} }
private void decrementQueueSize() { private void decrementQueueSize() {
Platform.runLater(() -> queueSizeProperty.set(queueSizeProperty.get() - 1)); Platform.runLater(() -> dbTaskQueueSize.set(dbTaskQueueSize.get() - 1));
} }
@Nullable @Nullable
@ -514,7 +505,7 @@ public final class ImageGalleryController implements Executor {
} }
public ReadOnlyIntegerProperty getDBTasksQueueSizeProperty() { public ReadOnlyIntegerProperty getDBTasksQueueSizeProperty() {
return queueSizeProperty.getReadOnlyProperty(); return dbTaskQueueSize.getReadOnlyProperty();
} }
public synchronized SleuthkitCase getSleuthKitCase() { public synchronized SleuthkitCase getSleuthKitCase() {
@ -895,11 +886,11 @@ public final class ImageGalleryController implements Executor {
synchronized (ImageGalleryController.this) { synchronized (ImageGalleryController.this) {
if (ImageGalleryModule.isDrawableAndNotKnown(file)) { if (ImageGalleryModule.isDrawableAndNotKnown(file)) {
//this file should be included and we don't already know about it from hash sets (NSRL) //this file should be included and we don't already know about it from hash sets (NSRL)
queueDBWorkerTask(new UpdateFileTask(file, db)); queueDBTask(new UpdateFileTask(file, db));
} else if (FileTypeUtils.getAllSupportedExtensions().contains(file.getNameExtension())) { } else if (FileTypeUtils.getAllSupportedExtensions().contains(file.getNameExtension())) {
//doing this check results in fewer tasks queued up, and faster completion of db update //doing this check results in fewer tasks queued up, and faster completion of db update
//this file would have gotten scooped up in initial grab, but actually we don't need it //this file would have gotten scooped up in initial grab, but actually we don't need it
queueDBWorkerTask(new RemoveFileTask(file, db)); queueDBTask(new RemoveFileTask(file, db));
} }
} }
} catch (TskCoreException | FileTypeDetector.FileTypeDetectorInitException ex) { } catch (TskCoreException | FileTypeDetector.FileTypeDetectorInitException ex) {
@ -945,7 +936,7 @@ public final class ImageGalleryController implements Executor {
//copy all file data to drawable databse //copy all file data to drawable databse
Content newDataSource = (Content) evt.getNewValue(); Content newDataSource = (Content) evt.getNewValue();
if (isListeningEnabled()) { if (isListeningEnabled()) {
queueDBWorkerTask(new PrePopulateDataSourceFiles(newDataSource, ImageGalleryController.this, getDatabase(), getSleuthKitCase())); queueDBTask(new PrePopulateDataSourceFiles(newDataSource, ImageGalleryController.this, getDatabase(), getSleuthKitCase()));
} else {//TODO: keep track of what we missed for later } else {//TODO: keep track of what we missed for later
setStale(true); setStale(true);
} }

View File

@ -87,7 +87,7 @@ public class CategorizeAction extends Action {
final void addCatToFiles(Set<Long> ids) { final void addCatToFiles(Set<Long> ids) {
Logger.getAnonymousLogger().log(Level.INFO, "categorizing{0} as {1}", new Object[]{ids.toString(), cat.getDisplayName()}); //NON-NLS Logger.getAnonymousLogger().log(Level.INFO, "categorizing{0} as {1}", new Object[]{ids.toString(), cat.getDisplayName()}); //NON-NLS
controller.queueDBWorkerTask(new CategorizeTask(ids, cat, createUndo)); controller.queueDBTask(new CategorizeTask(ids, cat, createUndo));
} }
/** /**

View File

@ -1,7 +1,7 @@
/* /*
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2013-15 Basis Technology Corp. * Copyright 2011-17 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org * Contact: carrier <at> sleuthkit <dot> org
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -21,22 +21,23 @@ package org.sleuthkit.autopsy.imagegallery.actions;
import java.util.Optional; import java.util.Optional;
import javafx.beans.Observable; import javafx.beans.Observable;
import javafx.beans.binding.ObjectExpression; import javafx.beans.binding.ObjectExpression;
import javafx.concurrent.Task; import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import org.controlsfx.control.action.Action; import org.controlsfx.control.action.Action;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined;
import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController;
import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.DrawableGroup;
import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager;
import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState; import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState;
/** /**
* Marks the currently fisplayed group as "seen" and advances to the next unseen * Marks the currently displayed group as "seen" and advances to the next unseen
* group * group
*/ */
@NbBundle.Messages({"NextUnseenGroup.markGroupSeen=Mark Group Seen", @NbBundle.Messages({"NextUnseenGroup.markGroupSeen=Mark Group Seen",
"NextUnseenGroup.nextUnseenGroup=Next Unseen group"}) "NextUnseenGroup.nextUnseenGroup=Next Unseen group"})
public class NextUnseenGroup extends Action { public class NextUnseenGroup extends Action {
private static final Image END = private static final Image END =
@ -47,54 +48,41 @@ public class NextUnseenGroup extends Action {
private static final String MARK_GROUP_SEEN = Bundle.NextUnseenGroup_markGroupSeen(); private static final String MARK_GROUP_SEEN = Bundle.NextUnseenGroup_markGroupSeen();
private static final String NEXT_UNSEEN_GROUP = Bundle.NextUnseenGroup_nextUnseenGroup(); private static final String NEXT_UNSEEN_GROUP = Bundle.NextUnseenGroup_nextUnseenGroup();
private final ImageGalleryController controller; private final GroupManager groupManager;
private final ObservableList<DrawableGroup> unSeenGroups;
private final ObservableList<DrawableGroup> analyzedGroups;
public NextUnseenGroup(ImageGalleryController controller) { public NextUnseenGroup(ImageGalleryController controller) {
super(NEXT_UNSEEN_GROUP); super(NEXT_UNSEEN_GROUP);
this.controller = controller; groupManager = controller.getGroupManager();
unSeenGroups = groupManager.getUnSeenGroups();
analyzedGroups = groupManager.getAnalyzedGroups();
setGraphic(new ImageView(ADVANCE)); setGraphic(new ImageView(ADVANCE));
//TODO: do we need both these listeners? //TODO: do we need both these listeners?
controller.getGroupManager().getAnalyzedGroups().addListener((Observable observable) -> { analyzedGroups.addListener((Observable o) -> this.updateButton());
updateButton(); unSeenGroups.addListener((Observable o) -> this.updateButton());
}); setEventHandler(event -> {
controller.getGroupManager().getUnSeenGroups().addListener((Observable observable) -> {
updateButton();
});
setEventHandler((ActionEvent t) -> {
//fx-thread //fx-thread
//if there is a group assigned to the view, mark it as seen //if there is a group assigned to the view, mark it as seen
Optional.ofNullable(controller.viewState()) Optional.ofNullable(controller.viewState())
.map(ObjectExpression<GroupViewState>::getValue) .map(ObjectExpression<GroupViewState>::getValue)
.map(GroupViewState::getGroup) .map(GroupViewState::getGroup)
.ifPresent(group -> controller.getGroupManager().markGroupSeen(group, true)); .ifPresent(group -> groupManager.markGroupSeen(group, true));
controller.execute(new Task<Void>() {
@Override if (unSeenGroups.isEmpty() == false) {
protected Void call() throws Exception { controller.advance(GroupViewState.tile(unSeenGroups.get(0)), true);
if (false == controller.getGroupManager().getUnSeenGroups().isEmpty()) { updateButton();
controller.advance(GroupViewState.tile(controller.getGroupManager().getUnSeenGroups().get(0)), true); }
}
return null;
}
@Override
protected void succeeded() {
super.succeeded();
updateButton();
}
});
}); });
updateButton(); updateButton();
} }
@ThreadConfined(type = ThreadConfined.ThreadType.JFX) @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
private void updateButton() { private void updateButton() {
setDisabled(controller.getGroupManager().getUnSeenGroups().isEmpty()); setDisabled(unSeenGroups.isEmpty());
if (controller.getGroupManager().getUnSeenGroups().size() <= 1) { if (unSeenGroups.size() <= 1) {
setText(MARK_GROUP_SEEN); setText(MARK_GROUP_SEEN);
setGraphic(new ImageView(END)); setGraphic(new ImageView(END));
} else { } else {