3838/**
3939 * A thread-safe EventService implementation.
4040 * <h2>Multithreading</h2>
41- * <p/ >
41+ * <p>
4242 * This implementation is <b>not Swing thread-safe</b>. If publication occurs on a thread other than the Swing
4343 * EventDispatchThread, subscribers will receive the event on the calling thread, and not the EDT. Swing components
4444 * should use the SwingEventService instead, which is the implementation used by the EventBus.
45- * <p/>
45+ * </p>
46+ * <p>
4647 * Two threads may be accessing the ThreadSafeEventService at the same time, one unsubscribing a
4748 * listener for topic "A" and the other publishing on topic "A". If the unsubscribing thread gets the lock first,
4849 * then it is unsubscribed, end of story. If the publisher gets the lock first, then a snapshot copy of the current
4950 * subscribers is made during the publication, the lock is released and the subscribers are called. Between the time
5051 * the lock is released and the time that the listener is called, the unsubscribing thread can unsubscribe, resulting
5152 * in an unsubscribed object receiving notification of the event after it was unsubscribed (but just once).
52- * <p/>
53+ * </p>
54+ * <p>
5355 * On event publication, subscribers are called in the order in which they subscribed.
54- * <p/>
56+ * </p>
57+ * <p>
5558 * Events and/or topic data can be cached, but are not by default. To cache events or topic data, call
5659 * {@link #setDefaultCacheSizePerClassOrTopic(int)}, {@link #setCacheSizeForEventClass(Class, int)}, or
5760 * {@link #setCacheSizeForTopic(String, int)}, {@link #setCacheSizeForTopic(Pattern, int)}. Retrieve cached values
6164 * Swing applications since both happen on the EDT in a single-threaded manner). In multithreaded applications, you
6265 * never know if your subscriber has handled an event while it was being subscribed (before the subscribe() method
6366 * returned) that is newer or older than the retrieved cached value (taken before or after subscribe() respectively).
64- * <p/>
67+ * </p>
68+ * <p>
6569 * To deal with subscribers that take too long (a concern in Swing applications), the EventService can be made to issue
6670 * {@link SubscriberTimingEvent}s when subscribers exceed a certain time. This does not interrupt subscriber processing
6771 * and is published after the subscriber finishes. The service can log a warning for SubscriberTimingEvents, see the
6872 * constructor {@link ThreadSafeEventService (long, boolean)}. The timing is checked for veto subscribers too.
69- * <p/ >
73+ * </p >
7074 * <h2>Logging</h2>
71- * <p/>
75+ * <p>
7276 * All logging goes through the {@link Logger}. The Logger is configurable and supports multiple logging systems.
73- * <p/>
77+ * </p>
78+ * <p>
7479 * Exceptions are logged by default, override {@link #handleException(String,Object,String,Object,Throwable,
7580 * StackTraceElement[],String)} to handleException exceptions in another way. Each call to a subscriber is wrapped in
7681 * a try block to ensure one listener does not interfere with another.
77- * <p/ >
82+ * </p >
7883 * <h2>Cleanup of Stale WeakReferences and Stale Annotation Proxies</h2>
79- * <p/ >
84+ * <p>
8085 * The EventService may need to clean up stale WeakReferences and ProxySubscribers created for EventBus annotations. (Aside: EventBus
8186 * Annotations are handled by the creation of proxies to the annotated objects. Since the annotations create weak references
8287 * by default, annotation proxies must held strongly by the EventService, otherwise the proxy is garbage collected.) When
8388 * a WeakReference's referent or an ProxySubscriber's proxiedObject (the annotated object) is claimed by the garbage collector,
8489 * the EventService still holds onto the actual WeakReference or ProxySubscriber subscribed to the EventService (which are pretty tiny).
85- * <p/>
90+ * </p>
91+ * <p>
8692 * There are two ways that these stale WeakReferences and ProxySubscribers are cleaned up.
93+ * </p>
8794 * <ol>
8895 * <li>On every publish, subscribe and unsubscribe, every subscriber and veto subscriber to a class or topic is checked to see
8996 * if it is a stale WeakReference or a stale ProxySubscriber (one whose getProxySubscriber() returns null). If the subscriber
95102 * of the cleanup thread follows.
96103 * </ol>
97104 * <h3>The Cleanup Thread</h3>
105+ * <p>
98106 * If a topic or class is never published to again, WeakReferences and ProxySubscribers can be left behind if they
99107 * are not cleaned up. To prevent loitering stale subscribers, the ThreadSafeEventService may periodically run through
100108 * all the EventSubscribers and VetoSubscribers for all topics and classes and clean up stale proxies. Proxies for
103111 * one caveat: If getProxiedSubscriber() returns null, even for a ProxySubscriber with a STRONG reference strength, that proxy
104112 * is cleaned up as it is assumed it is stale or just wrong. This would not occur normally in EventBus usage, but only
105113 * if someone is implementing their own custom ProxySubscriber and/or AnnotationProcessor.)
106- * <p/>
114+ * </p>
115+ * <p>
107116 * Cleanup is pretty rare in general. Not only are stale subscribers cleaned up with regular usage, stale
108117 * subscribers on abandoned topics and classes do not take up a lot of memory, hence, they are allowed to build up to a certain degree.
109118 * Cleanup does not occur until the number of WeakReferences and SubscriptionsProxy's with WeakReference strength
110119 * subscribed to an EventService for all the EventService's subscriptions in total exceed the <tt>cleanupStartThreshhold</tt>,
111120 * which is set to <tt>CLEANUP_START_THRESHOLD_DEFAULT</tt> (500) by default. The default is overridable in the constructor
112121 * or via #setCleanupStartThreshhold(Integer). If set to null, cleanup will never start.
113- * <p/>
122+ * </p>
123+ * <p>
114124 * Once the cleanup start threshold is exceeded, a <tt>java.util.Timer</tt> is started to clean up stale subscribers periodically
115125 * in another thread. The timer will fire every <tt>cleanupPeriodMS</tt> milliseconds, which is set to the
116126 * <tt>CLEANUP_PERIOD_MS_DEFAULT<tt> (20 minutes) by default. The default is overridable in the constructor or
117127 * via #setCleanupPeriodMS(Integer). If set to null, cleanup will not start. This is implemented with a <tt>java.util.Timer</tt>,
118128 * so Timer's warnings apply - setting this too low will cause cleanups to bunch up and hog the cleanup thread.
119- * <p/>
129+ * </p>
130+ * <p>
120131 * After a cleanup cycle completes, if the number of stale subscribers falls at or below the <tt>cleanupStopThreshhold</tt>
121132 * cleanup stops until the <tt>cleanupStartThreshhold</tt> is exceeded again. The <tt>cleanupStopThreshhold</tt> is set
122133 * to <tt>CLEANUP_STOP_THRESHOLD_DEFAULT</tt> (100) by default. The default is overridable in the constructor or via
123134 * #setCleanupStopThreshhold(Integer). If set to null or 0, cleanup will not stop if it is ever started.
124- * <p/>
135+ * </p>
136+ * <p>
125137 * All cleanup parameters are tunable "live" and checked after each subscription and after each cleanup cycle.
126138 * To make cleanup never run, set cleanupStartThreshhold to Integer.MAX_VALUE and cleanupPeriodMS to null.
127139 * To get cleanup to run continuously, set set cleanupStartThreshhold to 0 and cleanupPeriodMS to some reasonable value,
128140 * perhaps 1000 (1 second) or so (not recommended, cleanup is conducted with regular usage and the cleanup thread is
129141 * rarely created or invoked).
130- * <p/>
142+ * </p>
143+ * <p>
131144 * Cleanup is not run in a daemon thread, and thus will not stop the JVM from exiting.
132- * <p/ >
145+ * </p >
133146 *
134147 * @author Michael Bushe michael@bushe.com
135148 * @todo (param) a JMS-like selector (can be done in base classes by implements like a commons filter
@@ -557,8 +570,9 @@ protected boolean subscribeVetoListener(final Object subscription, final Map vet
557570 * All subscribe methods call this method, including veto subscriptions.
558571 * Extending classes only have to override this method to subscribe all
559572 * subscriber subscriptions.
560- * <p/ >
573+ * <p>
561574 * Overriding this method is only for the adventurous. This basically gives you just enough rope to hang yourself.
575+ * </p>
562576 *
563577 * @param classTopicOrPatternWrapper the topic String, event Class, or PatternWrapper to subscribe to
564578 * @param subscriberMap the internal map of subscribers to use (by topic or class)
@@ -1066,8 +1080,9 @@ private void logEvent(Object event, String topic, Object eventObj) {
10661080 /**
10671081 * Adds an event to the event cache, if appropriate. This method is called just before publication to listeners,
10681082 * after the event passes any veto listeners.
1069- * <p/ >
1083+ * <p>
10701084 * Using protected visibility to open the caching to other implementations.
1085+ * </p>
10711086 *
10721087 * @param event the event about to be published, null if topic is non-null
10731088 * @param topic the topic about to be published to, null if the event is non-null
@@ -1595,13 +1610,15 @@ private List createCopyOfContentsRemoveWeakRefs(Collection subscribersOrVetoList
15951610
15961611 /**
15971612 * Sets the default cache size for each kind of event, default is 0 (no caching).
1598- * <p/ >
1613+ * <p>
15991614 * If this value is set to a positive number, then when an event is published, the EventService caches the event or
16001615 * topic payload data for later retrieval. This allows subscribers to find out what has most recently happened
16011616 * before they subscribed. The cached event(s) are returned from #getLastEvent(Class), #getLastTopicData(String),
16021617 * #getCachedEvents(Class), or #getCachedTopicData(String)
1603- * <p/>
1618+ * </p>
1619+ * <p>
16041620 * The default can be overridden on a by-event-class or by-topic basis.
1621+ * </p>
16051622 *
16061623 * @param defaultCacheSizePerClassOrTopic
16071624 */
@@ -1620,17 +1637,20 @@ public int getDefaultCacheSizePerClassOrTopic() {
16201637
16211638 /**
16221639 * Set the number of events cached for a particular class of event. By default, no events are cached.
1623- * <p/ >
1640+ * <p>
16241641 * This overrides any setting for the DefaultCacheSizePerClassOrTopic.
1625- * <p/>
1642+ * </p>
1643+ * <p>
16261644 * Class hierarchy semantics are respected. That is, if there are three events, A, X and Y, and X and Y are both
16271645 * derived from A, then setting the cache size for A applies the cache size for all three. Setting the cache size
16281646 * for X applies to X and leaves the settings for A and Y in tact. Interfaces can be passed to this method, but they
16291647 * only take effect if the cache size of a class or it's superclasses has been set. Just like Class.getInterfaces(),
16301648 * if multiple cache sizes are set, the interface names declared earliest in the implements clause of the eventClass
16311649 * takes effect.
1632- * <p/>
1650+ * </p>
1651+ * <p>
16331652 * The cache for an event is not adjusted until the next event of that class is published.
1653+ * </p>
16341654 *
16351655 * @param eventClass the class of event
16361656 * @param cacheSize the number of published events to cache for this event
@@ -1647,9 +1667,10 @@ public void setCacheSizeForEventClass(Class eventClass, int cacheSize) {
16471667
16481668 /**
16491669 * Returns the number of events cached for a particular class of event. By default, no events are cached.
1650- * <p/ >
1670+ * <p>
16511671 * This result is computed for a particular class from the values passed to #setCacheSizeForEventClass(Class, int),
16521672 * and respects the class hierarchy.
1673+ * </p>
16531674 *
16541675 * @param eventClass the class of event
16551676 *
@@ -1706,12 +1727,15 @@ public int getCacheSizeForEventClass(Class eventClass) {
17061727
17071728 /**
17081729 * Set the number of published data objects cached for a particular event topic. By default, no caching is done.
1709- * <p/ >
1730+ * <p>
17101731 * This overrides any setting for the DefaultCacheSizePerClassOrTopic.
1711- * <p/>
1732+ * </p>
1733+ * <p>
17121734 * Settings for exact topic names take precedence over pattern matching.
1713- * <p/>
1735+ * </p>
1736+ * <p>
17141737 * The cache for a topic is not adjusted until the next publication on that topic.
1738+ * </p>
17151739 *
17161740 * @param topicName the topic name
17171741 * @param cacheSize the number of published data Objects to cache for this topic
@@ -1728,13 +1752,16 @@ public void setCacheSizeForTopic(String topicName, int cacheSize) {
17281752
17291753 /**
17301754 * Set the number of published data objects cached for topics matching a pattern. By default, caching is done.
1731- * <p/ >
1755+ * <p>
17321756 * This overrides any setting for the DefaultCacheSizePerClassOrTopic.
1733- * <p/>
1757+ * </p>
1758+ * <p>
17341759 * Settings for exact topic names take precedence over pattern matching. If a topic matches the cache settings for
17351760 * more than one pattern, the cache size chosen is an undetermined one from one of the matched pattern settings.
1736- * <p/>
1761+ * </p>
1762+ * <p>
17371763 * The cache for a topic is not adjusted until the next publication on that topic.
1764+ * </p>
17381765 *
17391766 * @param pattern the pattern matching topic names
17401767 * @param cacheSize the number of data Objects to cache for this topic
@@ -1752,9 +1779,10 @@ public void setCacheSizeForTopic(Pattern pattern, int cacheSize) {
17521779
17531780 /**
17541781 * Returns the number of cached data objects published on a particular topic. By default, no caching is performed.
1755- * <p/ >
1782+ * <p>
17561783 * This result is computed for a particular topic from the values passed to #setCacheSizeForTopic(String, int) and
17571784 * #setCacheSizeForTopic(Pattern, int).
1785+ * </p>
17581786 *
17591787 * @param topic the topic name
17601788 *
@@ -1971,17 +1999,19 @@ protected void handleException(final String action, final Object event, final St
19711999 /**
19722000 * Unsubscribe a subscriber if it is a stale ProxySubscriber. Used during subscribe() and
19732001 * in the cleanup Timer. See the class javadoc.
1974- * <p/ >
2002+ * <p>
19752003 * Not private since I don't claim I'm smart enough to anticipate all needs, but I
19762004 * am smart enough to doc the rules you must follow to override this method. Those
19772005 * rules may change (changes will be doc'ed), override at your own risk.
1978- * <p/>
2006+ * </p>
2007+ * <p>
19792008 * Overriders MUST call iterator.remove() to unsubscribe the proxy if the subscriber is
19802009 * a ProxySubscriber and is stale and should be cleaned up. If the ProxySubscriber
19812010 * is unsubscribed, then implementers MUST also call proxyUnsubscribed() on the subscriber.
19822011 * Overriders MUST also remove the proxy from the weakProxySubscriber list by calling
19832012 * removeStaleProxyFromList. Method assumes caller is holding the listenerList
19842013 * lock (else how can you pass the iterator?).
2014+ * </p>
19852015 * @param iterator current iterator
19862016 * @param existingSubscriber the current value of the iterator
19872017 * @return the real value of the param, or the proxied subscriber of the param if
0 commit comments