mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 09:17:42 +00:00
better handling of exceptions in event bus eventhandlers
This commit is contained in:
parent
c689956bbc
commit
1c16f9e405
@ -20,20 +20,21 @@
|
|||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.eventbus.AsyncEventBus;
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.atomic.LongAdder;
|
import java.util.concurrent.atomic.LongAdder;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
import org.sleuthkit.autopsy.events.ContentTagAddedEvent;
|
import org.sleuthkit.autopsy.events.ContentTagAddedEvent;
|
||||||
import org.sleuthkit.autopsy.events.ContentTagDeletedEvent;
|
import org.sleuthkit.autopsy.events.ContentTagDeletedEvent;
|
||||||
import org.sleuthkit.autopsy.imagegallery.ImageGalleryController;
|
import org.sleuthkit.autopsy.imagegallery.ImageGalleryController;
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.Category;
|
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB;
|
|
||||||
import org.sleuthkit.datamodel.ContentTag;
|
import org.sleuthkit.datamodel.ContentTag;
|
||||||
import org.sleuthkit.datamodel.TagName;
|
import org.sleuthkit.datamodel.TagName;
|
||||||
import org.sleuthkit.datamodel.TskCoreException;
|
import org.sleuthkit.datamodel.TskCoreException;
|
||||||
@ -66,7 +67,11 @@ public class CategoryManager {
|
|||||||
/**
|
/**
|
||||||
* Used to distribute {@link CategoryChangeEvent}s
|
* Used to distribute {@link CategoryChangeEvent}s
|
||||||
*/
|
*/
|
||||||
private final EventBus categoryEventBus = new EventBus("Category Event Bus");
|
private final EventBus categoryEventBus = new AsyncEventBus(Executors.newSingleThreadExecutor(
|
||||||
|
new BasicThreadFactory.Builder().namingPattern("Category Event Bus").uncaughtExceptionHandler((Thread t, Throwable e) -> {
|
||||||
|
LOGGER.log(Level.SEVERE, "uncaught exception in event bus handler", e);
|
||||||
|
}).build()
|
||||||
|
));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For performance reasons, keep current category counts in memory. All of
|
* For performance reasons, keep current category counts in memory. All of
|
||||||
|
@ -18,19 +18,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.imagegallery.datamodel;
|
package org.sleuthkit.autopsy.imagegallery.datamodel;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.AsyncEventBus;
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||||
import org.sleuthkit.autopsy.casemodule.services.TagsManager;
|
import org.sleuthkit.autopsy.casemodule.services.TagsManager;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
import org.sleuthkit.autopsy.events.ContentTagAddedEvent;
|
import org.sleuthkit.autopsy.events.ContentTagAddedEvent;
|
||||||
import org.sleuthkit.autopsy.events.ContentTagDeletedEvent;
|
import org.sleuthkit.autopsy.events.ContentTagDeletedEvent;
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.Category;
|
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile;
|
|
||||||
import org.sleuthkit.datamodel.Content;
|
import org.sleuthkit.datamodel.Content;
|
||||||
import org.sleuthkit.datamodel.ContentTag;
|
import org.sleuthkit.datamodel.ContentTag;
|
||||||
import org.sleuthkit.datamodel.TagName;
|
import org.sleuthkit.datamodel.TagName;
|
||||||
@ -42,13 +43,20 @@ import org.sleuthkit.datamodel.TskCoreException;
|
|||||||
*/
|
*/
|
||||||
public class DrawableTagsManager {
|
public class DrawableTagsManager {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(DrawableTagsManager.class.getName());
|
||||||
|
|
||||||
private static final String FOLLOW_UP = "Follow Up";
|
private static final String FOLLOW_UP = "Follow Up";
|
||||||
|
|
||||||
final private Object autopsyTagsManagerLock = new Object();
|
final private Object autopsyTagsManagerLock = new Object();
|
||||||
private TagsManager autopsyTagsManager;
|
private TagsManager autopsyTagsManager;
|
||||||
|
|
||||||
/** Used to distribute {@link TagsChangeEvent}s */
|
/** Used to distribute {@link TagsChangeEvent}s */
|
||||||
private final EventBus tagsEventBus = new EventBus("Tags Event Bus");
|
private final EventBus tagsEventBus = new AsyncEventBus(
|
||||||
|
Executors.newSingleThreadExecutor(
|
||||||
|
new BasicThreadFactory.Builder().namingPattern("Tags Event Bus").uncaughtExceptionHandler((Thread t, Throwable e) -> {
|
||||||
|
LOGGER.log(Level.SEVERE, "uncaught exception in event bus handler", e);
|
||||||
|
}).build()
|
||||||
|
));
|
||||||
|
|
||||||
/** The tag name corresponding to the "built-in" tag "Follow Up" */
|
/** The tag name corresponding to the "built-in" tag "Follow Up" */
|
||||||
private TagName followUpTagName;
|
private TagName followUpTagName;
|
||||||
@ -130,7 +138,7 @@ public class DrawableTagsManager {
|
|||||||
.filter(CategoryManager::isCategoryTagName)
|
.filter(CategoryManager::isCategoryTagName)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
} catch (TskCoreException | IllegalStateException ex) {
|
} catch (TskCoreException | IllegalStateException ex) {
|
||||||
Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.WARNING, "couldn't access case", ex);
|
LOGGER.log(Level.WARNING, "couldn't access case", ex);
|
||||||
}
|
}
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
@ -166,7 +174,7 @@ public class DrawableTagsManager {
|
|||||||
throw new TskCoreException("tagame exists but wasn't found", ex);
|
throw new TskCoreException("tagame exists but wasn't found", ex);
|
||||||
}
|
}
|
||||||
} catch (IllegalStateException ex) {
|
} catch (IllegalStateException ex) {
|
||||||
Logger.getLogger(DrawableTagsManager.class.getName()).log(Level.SEVERE, "Case was closed out from underneath", ex);
|
LOGGER.log(Level.SEVERE, "Case was closed out from underneath", ex);
|
||||||
throw new TskCoreException("Case was closed out from underneath", ex);
|
throw new TskCoreException("Case was closed out from underneath", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -537,15 +537,16 @@ public class GroupManager {
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void handleTagAdded(ContentTagAddedEvent evt) {
|
public void handleTagAdded(ContentTagAddedEvent evt) {
|
||||||
GroupKey<?> groupKey = null;
|
GroupKey<?> groupKey = null;
|
||||||
if (groupBy == DrawableAttribute.TAGS) {
|
if (groupBy == DrawableAttribute.CATEGORY && CategoryManager.isCategoryTagName(evt.getTag().getName())) {
|
||||||
groupKey = new GroupKey<TagName>(DrawableAttribute.TAGS, evt.getTag().getName());
|
|
||||||
} else if (groupBy == DrawableAttribute.CATEGORY) {
|
|
||||||
groupKey = new GroupKey<Category>(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName()));
|
groupKey = new GroupKey<Category>(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName()));
|
||||||
|
} else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) {
|
||||||
|
groupKey = new GroupKey<TagName>(DrawableAttribute.TAGS, evt.getTag().getName());
|
||||||
|
}
|
||||||
|
if (groupKey != null) {
|
||||||
|
final long fileID = evt.getTag().getContent().getId();
|
||||||
|
DrawableGroup g = getGroupForKey(groupKey);
|
||||||
|
addFileToGroup(g, groupKey, fileID);
|
||||||
}
|
}
|
||||||
final long fileID = evt.getTag().getContent().getId();
|
|
||||||
DrawableGroup g = getGroupForKey(groupKey);
|
|
||||||
addFileToGroup(g, groupKey, fileID);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("AssignmentToMethodParameter")
|
@SuppressWarnings("AssignmentToMethodParameter")
|
||||||
@ -563,13 +564,16 @@ public class GroupManager {
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void handleTagDeleted(ContentTagDeletedEvent evt) {
|
public void handleTagDeleted(ContentTagDeletedEvent evt) {
|
||||||
GroupKey<?> groupKey = null;
|
GroupKey<?> groupKey = null;
|
||||||
if (groupBy == DrawableAttribute.TAGS) {
|
if (groupBy == DrawableAttribute.CATEGORY && CategoryManager.isCategoryTagName(evt.getTag().getName())) {
|
||||||
groupKey = new GroupKey<TagName>(DrawableAttribute.TAGS, evt.getTag().getName());
|
|
||||||
} else if (groupBy == DrawableAttribute.CATEGORY) {
|
|
||||||
groupKey = new GroupKey<Category>(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName()));
|
groupKey = new GroupKey<Category>(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName()));
|
||||||
|
} else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) {
|
||||||
|
groupKey = new GroupKey<TagName>(DrawableAttribute.TAGS, evt.getTag().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupKey != null) {
|
||||||
|
final long fileID = evt.getTag().getContent().getId();
|
||||||
|
DrawableGroup g = removeFromGroup(groupKey, fileID);
|
||||||
}
|
}
|
||||||
final long fileID = evt.getTag().getContent().getId();
|
|
||||||
DrawableGroup g = removeFromGroup(groupKey, fileID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
Loading…
x
Reference in New Issue
Block a user