19 package org.sleuthkit.autopsy.events;
21 import java.beans.PropertyChangeListener;
24 import java.util.concurrent.ConcurrentHashMap;
25 import java.util.logging.Level;
35 final class LocalEventPublisher {
37 private static final Logger logger = Logger.
getLogger(LocalEventPublisher.class.getName());
38 private final Map<String, Set<PropertyChangeListener>> subscribersByEvent;
44 LocalEventPublisher() {
45 subscribersByEvent =
new ConcurrentHashMap<>();
54 void addSubscriber(Set<String> eventNames, PropertyChangeListener subscriber) {
55 for (String eventName : eventNames) {
56 addSubscriber(eventName, subscriber);
66 void addSubscriber(String eventName, PropertyChangeListener subscriber) {
67 subscribersByEvent.putIfAbsent(eventName, ConcurrentHashMap.<PropertyChangeListener>newKeySet());
68 Set<PropertyChangeListener> subscribers = subscribersByEvent.get(eventName);
69 subscribers.add(subscriber);
78 void removeSubscriber(Set<String> eventNames, PropertyChangeListener subscriber) {
79 for (String eventName : eventNames) {
80 removeSubscriber(eventName, subscriber);
90 void removeSubscriber(String eventName, PropertyChangeListener subscriber) {
91 Set<PropertyChangeListener> subscribers = subscribersByEvent.getOrDefault(eventName, null);
92 if (null != subscribers) {
93 subscribers.remove(subscriber);
103 void publish(AutopsyEvent event) {
104 Set<PropertyChangeListener> subscribers = subscribersByEvent.getOrDefault(event.getPropertyName(), null);
105 if (null != subscribers) {
106 for (PropertyChangeListener subscriber : subscribers) {
108 subscriber.propertyChange(event);
109 }
catch (Exception ex) {
110 logger.log(Level.SEVERE,
"Exception thrown by subscriber", ex);
synchronized static Logger getLogger(String name)