Skip to content

Commit 0988a1d

Browse files
committed
Remove org.bushe:eventbus CleanupEvent logic
We do not need to monitor these events. Removing it simplifies the codebase and avoids a hack.
1 parent ac03bca commit 0988a1d

File tree

3 files changed

+1
-97
lines changed

3 files changed

+1
-97
lines changed

src/main/java/org/scijava/event/DefaultEventBus.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.Arrays;
3535
import java.util.List;
3636

37-
import org.scijava.event.bushe.CleanupEvent;
3837
import org.scijava.event.bushe.ThreadSafeEventService;
3938
import org.scijava.log.LogService;
4039
import org.scijava.service.Service;
@@ -116,33 +115,6 @@ public void publishLater(final String topicName, final Object eventObj) {
116115

117116
@Override
118117
public void publish(final Object event) {
119-
// HACK: Work around a deadlock problem caused by ThreadSafeEventService:
120-
121-
// 1) The ThreadSafeEventService superclass has a special cleanup thread
122-
// that takes care of cleaning up stale references. Every time it runs, it
123-
// publishes some CleanupEvents using publish(Object) to announce that this
124-
// is occurring. Normally, such publication delegates to
125-
// publishNow, which calls ThreadService#invoke, which calls
126-
// EventQueue.invokeAndWait, which queues the publication for execution on
127-
// the EDT and then blocks until publication is complete.
128-
129-
// 2) When the ThreadSafeEventService publishes the CleanupEvents, it does
130-
// so inside a synchronized block that locks on a "listenerLock" object.
131-
132-
// 3) Unfortunately, since the CleanupEvent publication is merely *queued*,
133-
// any other pending operations on the EDT happen first. If one such
134-
// operation meanwhile calls e.g.
135-
// ThreadSafeEventService#getSubscribers(Class<T>), it will deadlock because
136-
// those getter methods are also synchronized on the listenerLock object.
137-
138-
// Hence, our hack workaround is to instead use publishLater for the
139-
// CleanupEvents, since no one really cares about them anyway. ;-)
140-
141-
if (event instanceof CleanupEvent) {
142-
publishLater(event);
143-
return;
144-
}
145-
146118
publishNow(event);
147119
}
148120

src/main/java/org/scijava/event/bushe/CleanupEvent.java

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/main/java/org/scijava/event/bushe/ThreadSafeEventService.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@
122122
* to <tt>CLEANUP_STOP_THRESHOLD_DEFAULT</tt> (100) by default. The default is overridable in the constructor or via
123123
* #setCleanupStopThreshhold(Integer). If set to null or 0, cleanup will not stop if it is ever started.
124124
* <p/>
125-
* Cleanup can be monitored by subscribing to the {@link CleanupEvent} class.
126-
* <p/>
127125
* All cleanup parameters are tunable "live" and checked after each subscription and after each cleanup cycle.
128126
* To make cleanup never run, set cleanupStartThreshhold to Integer.MAX_VALUE and cleanupPeriodMS to null.
129127
* To get cleanup to run continuously, set set cleanupStartThreshhold to 0 and cleanupPeriodMS to some reasonable value,
@@ -137,7 +135,7 @@
137135
* @todo (param) a JMS-like selector (can be done in base classes by implements like a commons filter
138136
* @see EventService for a complete description of the API
139137
*/
140-
@SuppressWarnings({"unchecked", "ForLoopReplaceableByForEach"})
138+
@SuppressWarnings({"unchecked"})
141139
public class ThreadSafeEventService implements EventService {
142140
public static final Integer CLEANUP_START_THRESHOLD_DEFAULT = 250;
143141
public static final Integer CLEANUP_STOP_THRESHOLD_DEFAULT = 100;
@@ -2057,17 +2055,14 @@ class CleanupTimerTask extends TimerTask {
20572055
@Override
20582056
public void run() {
20592057
synchronized(listenerLock) {
2060-
ThreadSafeEventService.this.publish(new CleanupEvent(CleanupEvent.Status.STARTING, weakRefPlusProxySubscriberCount, null));
20612058
if (weakRefPlusProxySubscriberCount <= cleanupStopThreshold) {
20622059
this.cancel();
20632060
cleanupTimer = null;
20642061
cleanupTimerTask = null;
20652062
LOG.debug("Cancelled scheduled weak reference and proxy cleanup.");
2066-
ThreadSafeEventService.this.publish(new CleanupEvent(CleanupEvent.Status.UNDER_STOP_THRESHOLD_CLEANING_CANCELLED, weakRefPlusProxySubscriberCount, null));
20672063
return;
20682064
}
20692065
LOG.debug("Starting a weak reference and proxy cleanup.");
2070-
ThreadSafeEventService.this.publish(new CleanupEvent(CleanupEvent.Status.OVER_STOP_THRESHOLD_CLEANING_BEGUN, weakRefPlusProxySubscriberCount, null));
20712066
List<Map> allSubscriberMaps = new ArrayList<Map>();
20722067
allSubscriberMaps.add(subscribersByEventType);
20732068
allSubscriberMaps.add(subscribersByEventClass);
@@ -2093,7 +2088,6 @@ public void run() {
20932088
}
20942089
}
20952090
}
2096-
ThreadSafeEventService.this.publish(new CleanupEvent(CleanupEvent.Status.FINISHED_CLEANING, weakRefPlusProxySubscriberCount, staleCount));
20972091
}
20982092
}
20992093
}

0 commit comments

Comments
 (0)