From dd349acd39d7b9007675121bd45dd7ec8aeb1e92 Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Thu, 18 Jun 2020 15:23:41 -0400 Subject: [PATCH] introduced ThreadUtils.shutDownTaskExecutor to handle case closing more gracefully --- .../autopsy/timeline/TimeLineController.java | 20 +++++++++------ .../autopsy/timeline/TimeLineModule.java | 25 +++++++++++-------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/timeline/TimeLineController.java b/Core/src/org/sleuthkit/autopsy/timeline/TimeLineController.java index 6b41d849d8..0c80cb5315 100755 --- a/Core/src/org/sleuthkit/autopsy/timeline/TimeLineController.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/TimeLineController.java @@ -73,6 +73,7 @@ import org.sleuthkit.autopsy.coreutils.History; import org.sleuthkit.autopsy.coreutils.LoggedTask; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; +import org.sleuthkit.autopsy.coreutils.ThreadUtils; import org.sleuthkit.autopsy.events.AutopsyEvent; import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.ModuleDataEvent; @@ -375,17 +376,26 @@ public class TimeLineController { } } + /** - * "Shut down" Timeline. Remove all the case and ingest listers. Close the - * timeline window. + * Shuts down the task executor in charge of handling case events. + */ + void shutDownTimeLineListeners() { + ThreadUtils.shutDownTaskExecutor(executor); + } + + /** + * "Shut down" Timeline. Close the timeline window. */ @ThreadConfined(type = ThreadConfined.ThreadType.AWT) - public void shutDownTimeLine() { + public void shutDownTimeLineGui() { if (topComponent != null) { topComponent.close(); topComponent = null; } } + + /** * Add the case and ingest listeners, prompt for rebuilding the database if @@ -777,10 +787,6 @@ public class TimeLineController { case CONTENT_TAG_DELETED: future = executor.submit(() -> filteredEvents.handleContentTagDeleted((ContentTagDeletedEvent) evt)); break; - case CURRENT_CASE: - //close timeline on case changes. - SwingUtilities.invokeLater(TimeLineController.this::shutDownTimeLine); - break; case DATA_SOURCE_ADDED: future = executor.submit(() -> { filteredEvents.handleDataSourceAdded(); diff --git a/Core/src/org/sleuthkit/autopsy/timeline/TimeLineModule.java b/Core/src/org/sleuthkit/autopsy/timeline/TimeLineModule.java index 96cb9845c4..4ff7d8ac2a 100755 --- a/Core/src/org/sleuthkit/autopsy/timeline/TimeLineModule.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/TimeLineModule.java @@ -86,26 +86,29 @@ public class TimeLineModule { @Override public void propertyChange(PropertyChangeEvent evt) { - try { - getController().handleCaseEvent(evt); - } catch (NoCurrentCaseException ex) { - // ignore - return; - } catch (TskCoreException ex) { - MessageNotifyUtil.Message.error("Error creating timeline controller."); - logger.log(Level.SEVERE, "Error creating timeline controller", ex); - } - if (Case.Events.valueOf(evt.getPropertyName()).equals(CURRENT_CASE)) { // we care only about case closing here if (evt.getNewValue() == null) { + /* + * Current case is closing, shut down the timeline top + * component and set the pre case singleton controller + * reference to null. + */ synchronized (controllerLock) { if (controller != null) { - SwingUtilities.invokeLater(controller::shutDownTimeLine); + controller.shutDownTimeLineListeners(); + SwingUtilities.invokeLater(controller::shutDownTimeLineGui); } controller = null; } } + } else { + try { + getController().handleCaseEvent(evt); + } catch (NoCurrentCaseException ignored) { + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, "Error handling application event", ex); + } } } }