improve thread safety

This commit is contained in:
jmillman 2014-08-11 14:14:13 -04:00
parent 48997a097a
commit 9ef9cb28aa
2 changed files with 14 additions and 3 deletions

View File

@ -17,6 +17,6 @@ public @interface ThreadConfined {
public enum ThreadType { public enum ThreadType {
ANY, UI, NOT_UI ANY, UI, JFX, AWT, NOT_UI
} }
} }

View File

@ -44,6 +44,8 @@ import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.imageanalyzer.EurekaController; import org.sleuthkit.autopsy.imageanalyzer.EurekaController;
import org.sleuthkit.autopsy.imageanalyzer.EurekaModule; import org.sleuthkit.autopsy.imageanalyzer.EurekaModule;
import org.sleuthkit.autopsy.imageanalyzer.LoggedTask; import org.sleuthkit.autopsy.imageanalyzer.LoggedTask;
import org.sleuthkit.autopsy.imageanalyzer.ThreadConfined;
import org.sleuthkit.autopsy.imageanalyzer.ThreadConfined.ThreadType;
import org.sleuthkit.autopsy.imageanalyzer.datamodel.Category; import org.sleuthkit.autopsy.imageanalyzer.datamodel.Category;
import org.sleuthkit.autopsy.imageanalyzer.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imageanalyzer.datamodel.DrawableAttribute;
import org.sleuthkit.autopsy.imageanalyzer.datamodel.DrawableDB; import org.sleuthkit.autopsy.imageanalyzer.datamodel.DrawableDB;
@ -74,12 +76,15 @@ public class GroupManager {
private final Map<GroupKey, Grouping> groupMap = new HashMap<>(); private final Map<GroupKey, Grouping> groupMap = new HashMap<>();
/** list of all analyzed groups */ /** list of all analyzed groups */
@ThreadConfined(type = ThreadType.JFX)
private final ObservableList<Grouping> analyzedGroups = FXCollections.observableArrayList(); private final ObservableList<Grouping> analyzedGroups = FXCollections.observableArrayList();
/** list of unseen groups */ /** list of unseen groups */
@ThreadConfined(type = ThreadType.JFX)
private final ObservableList<Grouping> unSeenGroups = FXCollections.observableArrayList(); private final ObservableList<Grouping> unSeenGroups = FXCollections.observableArrayList();
/** sorted list of unseen groups */ /** sorted list of unseen groups */
@ThreadConfined(type = ThreadType.JFX)
private final SortedList<Grouping> sortedUnSeenGroups = unSeenGroups.sorted(); private final SortedList<Grouping> sortedUnSeenGroups = unSeenGroups.sorted();
private ReGroupTask groupByTask; private ReGroupTask groupByTask;
@ -100,6 +105,7 @@ public class GroupManager {
return analyzedGroups; return analyzedGroups;
} }
@ThreadConfined(type = ThreadType.JFX)
public SortedList<Grouping> getUnSeenGroups() { public SortedList<Grouping> getUnSeenGroups() {
return sortedUnSeenGroups; return sortedUnSeenGroups;
} }
@ -542,14 +548,19 @@ public class GroupManager {
if (groupByTask != null) { if (groupByTask != null) {
groupByTask.cancel(true); groupByTask.cancel(true);
} }
sortedUnSeenGroups.setComparator(sortBy.getGrpComparator(groupBy, sortOrder)); Platform.runLater(() -> {
sortedUnSeenGroups.setComparator(sortBy.getGrpComparator(groupBy, sortOrder));
});
groupByTask = new ReGroupTask(groupBy, sortBy, sortOrder); groupByTask = new ReGroupTask(groupBy, sortBy, sortOrder);
controller.submitBGTask(groupByTask); controller.submitBGTask(groupByTask);
} else { } else {
// just resort the list of groups // just resort the list of groups
setSortBy(sortBy); setSortBy(sortBy);
setSortOrder(sortOrder); setSortOrder(sortOrder);
sortedUnSeenGroups.setComparator(sortBy.getGrpComparator(groupBy, sortOrder)); Platform.runLater(() -> {
sortedUnSeenGroups.setComparator(sortBy.getGrpComparator(groupBy, sortOrder));
});
} }
} }