|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.bushe.swing.event.ThreadSafeEventService
public class ThreadSafeEventService
A thread-safe EventService implementation.
SubscriberTimingEvent
s when subscribers exceed a certain time. This does not interrupt subscriber processing
and is published after the subscriber finishes. The service can log a warning for SubscriberTimingEvents, see the
constructor (long, boolean)
. The timing is checked for veto subscribers too.
handleException(String,Object,String,Object,Throwable,
StackTraceElement[],String)
to handleException exceptions in another way. Each call to a subscriber is wrapped in
a try block to ensure one listener does not interfere with another.
Fine logging can be turned via java.util.logging using the name "org.bushe.swing.event.ThreadSafeEventService". This
aids in debugging which subscription and publication issues.
CleanupEvent
class.
All cleanup parameters are tunable "live" and checked after each subscription and after each cleanup cycle.
To make cleanup never run, set cleanupStartThreshhold to Integer.MAX_VALUE and cleanupPeriodMS to null.
To get cleanup to run continuously, set set cleanupStartThreshhold to 0 and cleanupPeriodMS to some reasonable value,
perhaps 1000 (1 second) or so (not recommended, cleanup is conducted with regular usage and the cleanup thread is
rarely created or invoked).
Cleanup is not run in a daemon thread, and thus will not stop the JVM from exiting.
for a complete description of the API
Field Summary | |
---|---|
static java.lang.Long |
CLEANUP_PERIOD_MS_DEFAULT
|
static java.lang.Integer |
CLEANUP_START_THRESHOLD_DEFAULT
|
static java.lang.Integer |
CLEANUP_STOP_THRESHOLD_DEFAULT
|
protected static java.util.logging.Logger |
LOG
|
Constructor Summary | |
---|---|
ThreadSafeEventService()
Creates a ThreadSafeEventService that does not monitor timing of handlers. |
|
ThreadSafeEventService(java.lang.Integer cleanupStartThreshold,
java.lang.Integer cleanupStopThreshold,
java.lang.Long cleanupPeriodMS)
Creates a ThreadSafeEventService while providing proxy cleanup customization. |
|
ThreadSafeEventService(java.lang.Long timeThresholdForEventTimingEventPublication)
Creates a ThreadSafeEventService while providing time monitoring options. |
|
ThreadSafeEventService(java.lang.Long timeThresholdForEventTimingEventPublication,
boolean subscribeTimingEventsInternally)
Creates a ThreadSafeEventService while providing time monitoring options. |
|
ThreadSafeEventService(java.lang.Long timeThresholdForEventTimingEventPublication,
boolean subscribeTimingEventsInternally,
java.lang.Integer cleanupStartThreshold,
java.lang.Integer cleanupStopThreshold,
java.lang.Long cleanupPeriodMS)
Creates a ThreadSafeEventService while providing time monitoring options. |
Method Summary | |
---|---|
protected void |
addEventToCache(java.lang.Object event,
java.lang.String topic,
java.lang.Object eventObj)
Adds an event to the event cache, if appropriate. |
void |
clearAllSubscribers()
Clears all current subscribers and veto subscribers |
void |
clearCache()
Clear all event caches for all topics and event. |
void |
clearCache(java.lang.Class eventClassToClear)
Clears the event cache for a specific event class or interface and it's any of it's subclasses or implementing classes. |
void |
clearCache(java.util.regex.Pattern pattern)
Clears the topic data cache for all topics that match a particular pattern. |
void |
clearCache(java.lang.String topic)
Clears the topic data cache for a specific topic name. |
protected void |
decWeakRefPlusProxySubscriberCount()
Decrement the count of stale proxies |
java.util.List |
getCachedEvents(java.lang.Class eventClass)
|
java.util.List |
getCachedTopicData(java.lang.String topic)
|
int |
getCacheSizeForEventClass(java.lang.Class eventClass)
Returns the number of events cached for a particular class of event. |
int |
getCacheSizeForTopic(java.lang.String topic)
Returns the number of cached data objects published on a particular topic. |
java.lang.Long |
getCleanupPeriodMS()
Get the cleanup interval. |
java.lang.Integer |
getCleanupStartThreshhold()
Gets the threshold above which cleanup starts. |
java.lang.Integer |
getCleanupStopThreshold()
Gets the threshold below which cleanup stops. |
int |
getDefaultCacheSizePerClassOrTopic()
|
java.lang.Object |
getLastEvent(java.lang.Class eventClass)
|
java.lang.Object |
getLastTopicData(java.lang.String topic)
|
protected java.lang.Object |
getRealSubscriberAndCleanStaleSubscriberIfNecessary(java.util.Iterator iterator,
java.lang.Object existingSubscriber)
Unsubscribe a subscriber if it is a stale ProxySubscriber. |
java.util.List |
getSubscribers(java.lang.Class eventClass)
Union of getSubscribersToClass(Class) and getSubscribersToExactClass(Class) |
java.util.List |
getSubscribers(java.lang.String topic)
Union of getSubscribersByPattern(String) and geSubscribersToTopic(String) |
java.util.List |
getSubscribers(java.lang.reflect.Type eventType)
|
java.util.List |
getSubscribersByPattern(java.lang.String topic)
|
java.util.List |
getSubscribersToClass(java.lang.Class eventClass)
|
java.util.List |
getSubscribersToExactClass(java.lang.Class eventClass)
|
protected java.util.List |
getSubscribersToPattern(java.util.regex.Pattern topicPattern)
|
java.util.List |
getSubscribersToTopic(java.lang.String topic)
|
java.util.List |
getVetoSubscribers(java.lang.Class eventClass)
|
java.util.List |
getVetoSubscribers(java.util.regex.Pattern topicPattern)
|
java.util.List |
getVetoSubscribers(java.lang.String topic)
|
java.util.List |
getVetoSubscribersToClass(java.lang.Class eventClass)
|
java.util.List |
getVetoSubscribersToExactClass(java.lang.Class eventClass)
|
protected void |
handleException(java.lang.Object event,
java.lang.Throwable e,
java.lang.StackTraceElement[] callingStack,
EventSubscriber eventSubscriber)
Called during event handling exceptions, calls handleException |
protected void |
handleException(java.lang.String action,
java.lang.Object event,
java.lang.String topic,
java.lang.Object eventObj,
java.lang.Throwable e,
java.lang.StackTraceElement[] callingStack,
java.lang.String sourceString)
All exception handling goes through this method. |
protected void |
handleVeto(VetoEventListener vl,
java.lang.Object event,
VetoTopicEventListener vtl,
java.lang.String topic,
java.lang.Object eventObj)
Handle vetos of an event or topic, by default logs finely. |
protected void |
incWeakRefPlusProxySubscriberCount()
Increment the count of stale proxies and start a cleanup task if necessary |
protected void |
onEventException(java.lang.String topic,
java.lang.Object eventObj,
java.lang.Throwable e,
java.lang.StackTraceElement[] callingStack,
EventTopicSubscriber eventTopicSubscriber)
Called during event handling exceptions, calls handleException |
void |
publish(java.lang.Object event)
Publishes an Object so that subscribers will be notified if they subscribed to the Object's class, one of its subclasses, or to one of its implementing interfaces. |
protected void |
publish(java.lang.Object event,
java.lang.String topic,
java.lang.Object eventObj,
java.util.List subscribers,
java.util.List vetoSubscribers,
java.lang.StackTraceElement[] callingStack)
All publish methods call this method. |
void |
publish(java.lang.String topicName,
java.lang.Object eventObj)
Publishes an object on a topic name so that all subscribers to that name will be notified about it. |
void |
publish(java.lang.reflect.Type genericType,
java.lang.Object event)
Use this method to publish generified objects to subscribers of Types, i.e. |
protected void |
removeProxySubscriber(ProxySubscriber proxy,
java.util.Iterator iter)
|
void |
setCacheSizeForEventClass(java.lang.Class eventClass,
int cacheSize)
Set the number of events cached for a particular class of event. |
void |
setCacheSizeForTopic(java.util.regex.Pattern pattern,
int cacheSize)
Set the number of published data objects cached for topics matching a pattern. |
void |
setCacheSizeForTopic(java.lang.String topicName,
int cacheSize)
Set the number of published data objects cached for a particular event topic. |
void |
setCleanupPeriodMS(java.lang.Long cleanupPeriodMS)
Sets the cleanup interval. |
void |
setCleanupStartThreshhold(java.lang.Integer cleanupStartThreshhold)
Sets the threshold above which cleanup starts. |
void |
setCleanupStopThreshold(java.lang.Integer cleanupStopThreshold)
Sets the threshold below which cleanup stops. |
void |
setDefaultCacheSizePerClassOrTopic(int defaultCacheSizePerClassOrTopic)
Sets the default cache size for each kind of event, default is 0 (no caching). |
boolean |
subscribe(java.lang.Class cl,
EventSubscriber eh)
Subscribes a WeakReference to an EventSubscriber to the publication of events of an event class and its subclasses, or to an event's interface. |
protected boolean |
subscribe(java.lang.Object topicOrClass,
java.util.Map subscriberMap,
java.lang.Object subscriber)
All subscribe methods call this method, including veto subscriptions. |
boolean |
subscribe(java.util.regex.Pattern pat,
EventTopicSubscriber eh)
Subscribes a WeakReference to an EventSubscriber to the publication of all the topic names that match a RegEx Pattern. |
boolean |
subscribe(java.lang.String topic,
EventTopicSubscriber eh)
Subscribes a WeakReference to an EventSubscriber to the publication of a topic name. |
boolean |
subscribe(java.lang.reflect.Type type,
EventSubscriber eh)
|
boolean |
subscribeExactly(java.lang.Class cl,
EventSubscriber eh)
Subscribes a WeakReference to an EventSubscriber to the publication of events of an event class (not its subclasses). |
boolean |
subscribeExactlyStrongly(java.lang.Class cl,
EventSubscriber eh)
Subscribes a subscriber to an event class (and not its subclasses). |
boolean |
subscribeStrongly(java.lang.Class cl,
EventSubscriber eh)
Subscribes a subscriber to an event class and its subclasses. |
boolean |
subscribeStrongly(java.util.regex.Pattern pat,
EventTopicSubscriber eh)
Subscribes a subscriber to all the event topic names that match a RegEx expression. |
boolean |
subscribeStrongly(java.lang.String name,
EventTopicSubscriber eh)
Subscribes a subscriber to an event topic name. |
protected void |
subscribeTiming(SubscriberTimingEvent event)
|
protected void |
subscribeVetoException(java.lang.Object event,
java.lang.String topic,
java.lang.Object eventObj,
java.lang.Throwable e,
java.lang.StackTraceElement[] callingStack,
VetoEventListener vetoer)
Called during veto exceptions, calls handleException |
boolean |
subscribeVetoListener(java.lang.Class eventClass,
VetoEventListener vetoListener)
Subscribes a WeakReference to a VetoListener to a event class and its subclasses. |
protected boolean |
subscribeVetoListener(java.lang.Object subscription,
java.util.Map vetoListenerMap,
java.lang.Object vetoListener)
All veto subscriptions methods call this method. |
boolean |
subscribeVetoListener(java.util.regex.Pattern topicPattern,
VetoTopicEventListener vetoListener)
Subscribes a WeakReference to an VetoTopicEventListener to all the topic names that match the RegEx Pattern. |
boolean |
subscribeVetoListener(java.lang.String topic,
VetoTopicEventListener vetoListener)
Subscribes a WeakReference to a VetoTopicEventListener to a topic name. |
boolean |
subscribeVetoListenerExactly(java.lang.Class eventClass,
VetoEventListener vetoListener)
Subscribes a WeakReference to a VetoListener to a event class (but not its subclasses). |
boolean |
subscribeVetoListenerExactlyStrongly(java.lang.Class eventClass,
VetoEventListener vetoListener)
Subscribes a VetoListener for an event class (but not its subclasses). |
boolean |
subscribeVetoListenerStrongly(java.lang.Class eventClass,
VetoEventListener vetoListener)
Subscribes a VetoListener for an event class and its subclasses. |
boolean |
subscribeVetoListenerStrongly(java.util.regex.Pattern topicPattern,
VetoTopicEventListener vetoListener)
Subscribes a VetoTopicEventListener to a set of topics that match a RegEx expression. |
boolean |
subscribeVetoListenerStrongly(java.lang.String topic,
VetoTopicEventListener vetoListener)
Subscribes a VetoListener to a topic name. |
boolean |
unsubscribe(java.lang.Class cl,
EventSubscriber eh)
Stop the subscription for a subscriber that is subscribed to an event class and its subclasses. |
boolean |
unsubscribe(java.lang.Class eventClass,
java.lang.Object subcribedByProxy)
When using annotations, an object may be subscribed by proxy. |
protected boolean |
unsubscribe(java.lang.Object o,
java.util.Map subscriberMap,
java.lang.Object subscriber)
All event subscriber unsubscriptions call this method. |
boolean |
unsubscribe(java.util.regex.Pattern topicPattern,
EventTopicSubscriber eh)
Stop the subscription for a subscriber that is subscribed to an event topic |
boolean |
unsubscribe(java.util.regex.Pattern pattern,
java.lang.Object subcribedByProxy)
When using annotations, an object may be subscribed by proxy. |
boolean |
unsubscribe(java.lang.String name,
EventTopicSubscriber eh)
Stop the subscription for a subscriber that is subscribed to an event topic |
boolean |
unsubscribe(java.lang.String topic,
java.lang.Object subcribedByProxy)
When using annotations, an object may be subscribed by proxy. |
boolean |
unsubscribeExactly(java.lang.Class cl,
EventSubscriber eh)
Stop the subscription for a subscriber that is subscribed to an event class (and not its subclasses). |
boolean |
unsubscribeExactly(java.lang.Class eventClass,
java.lang.Object subcribedByProxy)
When using annotations, an object may be subscribed by proxy. |
boolean |
unsubscribeVetoListener(java.lang.Class eventClass,
VetoEventListener vetoListener)
Stop the subscription for a vetoListener that is subscribed to an event class and its subclasses. |
protected boolean |
unsubscribeVetoListener(java.lang.Object o,
java.util.Map vetoListenerMap,
java.lang.Object vl)
All veto unsubscriptions methods call this method. |
boolean |
unsubscribeVetoListener(java.util.regex.Pattern topicPattern,
VetoTopicEventListener vetoListener)
Stop the subscription for a VetoTopicEventListener that is subscribed to an event topic RegEx pattern. |
boolean |
unsubscribeVetoListener(java.lang.String topic,
VetoTopicEventListener vetoListener)
Stop the subscription for a VetoTopicEventListener that is subscribed to an event topic name. |
boolean |
unsubscribeVetoListenerExactly(java.lang.Class eventClass,
VetoEventListener vetoListener)
Stop the subscription for a vetoListener that is subscribed to an event class (but not its subclasses). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.Integer CLEANUP_START_THRESHOLD_DEFAULT
public static final java.lang.Integer CLEANUP_STOP_THRESHOLD_DEFAULT
public static final java.lang.Long CLEANUP_PERIOD_MS_DEFAULT
protected static final java.util.logging.Logger LOG
Constructor Detail |
---|
public ThreadSafeEventService()
public ThreadSafeEventService(java.lang.Long timeThresholdForEventTimingEventPublication)
timeThresholdForEventTimingEventPublication
- the longest time a subscriber should spend handling an event,
The service will publish an SubscriberTimingEvent after listener processing if the time was exceeded. If null, no
EventSubscriberTimingEvent will be issued.public ThreadSafeEventService(java.lang.Long timeThresholdForEventTimingEventPublication, boolean subscribeTimingEventsInternally)
timeThresholdForEventTimingEventPublication
- the longest time a subscriber should spend handling an event,
The service will publish an SubscriberTimingEvent after listener processing if the time was exceeded. If null, no
EventSubscriberTimingEvent will be issued.subscribeTimingEventsInternally
- add a subscriber to the SubscriberTimingEvent internally and call the
protected subscribeTiming() method when they occur. This logs a warning to a java.util.logging logger by
default.public ThreadSafeEventService(java.lang.Integer cleanupStartThreshold, java.lang.Integer cleanupStopThreshold, java.lang.Long cleanupPeriodMS)
cleanupStartThreshold
- see class javadoc.cleanupStopThreshold
- see class javadoc.cleanupPeriodMS
- see class javadoc.public ThreadSafeEventService(java.lang.Long timeThresholdForEventTimingEventPublication, boolean subscribeTimingEventsInternally, java.lang.Integer cleanupStartThreshold, java.lang.Integer cleanupStopThreshold, java.lang.Long cleanupPeriodMS)
timeThresholdForEventTimingEventPublication
- the longest time a subscriber should spend handling an event.
The service will publish an SubscriberTimingEvent after listener processing if the time was exceeded. If null, no
SubscriberTimingEvent will be issued.subscribeTimingEventsInternally
- add a subscriber to the SubscriberTimingEvent internally and call the
protected subscribeTiming() method when they occur. This logs a warning to a java.util.logging logger by
default.cleanupStartThreshold
- see class javadoc.cleanupStopThreshold
- see class javadoc.cleanupPeriodMS
- see class javadoc.
java.lang.IllegalArgumentException
- if timeThresholdForEventTimingEventPublication is null and
subscribeTimingEventsInternally is true.Method Detail |
---|
public java.lang.Integer getCleanupStartThreshhold()
public void setCleanupStartThreshhold(java.lang.Integer cleanupStartThreshhold)
the
- threshold at which cleanup startspublic java.lang.Integer getCleanupStopThreshold()
the
- threshold at which cleanup stops (it may start again)public void setCleanupStopThreshold(java.lang.Integer cleanupStopThreshold)
the
- threshold at which cleanup stops (it may start again).public java.lang.Long getCleanupPeriodMS()
the
- interval in milliseconds between cleanup runs.public void setCleanupPeriodMS(java.lang.Long cleanupPeriodMS)
the
- interval in milliseconds between cleanup runs. Passing null
stops cleanup.public boolean subscribe(java.lang.Class cl, EventSubscriber eh)
EventService
subscribe
in interface EventService
cl
- the class of published objects to listen toeh
- The subscriber that will accept the events when published.
EventService.subscribe(Class,EventSubscriber)
public boolean subscribe(java.lang.reflect.Type type, EventSubscriber eh)
subscribe
in interface EventService
EventService.subscribe(java.lang.reflect.Type, EventSubscriber)
public boolean subscribeExactly(java.lang.Class cl, EventSubscriber eh)
EventService
subscribeExactly
in interface EventService
cl
- the class of published objects to listen toeh
- The subscriber that will accept the events when published.
EventService.subscribeExactly(Class,EventSubscriber)
public boolean subscribe(java.lang.String topic, EventTopicSubscriber eh)
EventService
subscribe
in interface EventService
topic
- the name of the topic listened toeh
- The topic subscriber that will accept the events when published.
EventService.subscribe(String,EventTopicSubscriber)
public boolean subscribe(java.util.regex.Pattern pat, EventTopicSubscriber eh)
EventService
subscribe
in interface EventService
pat
- pattern that matches to the name of the topic published toeh
- The topic subscriber that will accept the events when published.
EventService.subscribe(Pattern,EventTopicSubscriber)
public boolean subscribeStrongly(java.lang.Class cl, EventSubscriber eh)
EventService
EventService.unsubscribe(Class,EventSubscriber)
is called.
subscribeStrongly
in interface EventService
cl
- the class of published objects to listen toeh
- The subscriber that will accept the events when published.
EventService.subscribeStrongly(Class,EventSubscriber)
public boolean subscribeExactlyStrongly(java.lang.Class cl, EventSubscriber eh)
EventService
EventService.unsubscribe(Class,EventSubscriber)
is called.
subscribeExactlyStrongly
in interface EventService
cl
- the class of published objects to listen toeh
- The subscriber that will accept the events when published.
EventService.subscribeExactlyStrongly(Class,EventSubscriber)
public boolean subscribeStrongly(java.lang.String name, EventTopicSubscriber eh)
EventService
EventService.unsubscribe(String,EventTopicSubscriber)
is called.
subscribeStrongly
in interface EventService
name
- the name of the topic listened toeh
- The topic subscriber that will accept the events when published.
EventService.subscribeStrongly(String,EventTopicSubscriber)
public boolean subscribeStrongly(java.util.regex.Pattern pat, EventTopicSubscriber eh)
EventService
EventService.unsubscribe(String,EventTopicSubscriber)
is called.
subscribeStrongly
in interface EventService
pat
- the name of the topic listened toeh
- The topic subscriber that will accept the events when published.
EventService.subscribeStrongly(Pattern,EventTopicSubscriber)
public void clearAllSubscribers()
EventService
clearAllSubscribers
in interface EventService
EventService.clearAllSubscribers()
public boolean subscribeVetoListener(java.lang.Class eventClass, VetoEventListener vetoListener)
EventService
subscribeVetoListener
in interface EventService
eventClass
- the class of published objects that can be vetoedvetoListener
- The vetoListener that can determine whether an event is published.
EventService.subscribeVetoListener(Class,VetoEventListener)
public boolean subscribeVetoListenerExactly(java.lang.Class eventClass, VetoEventListener vetoListener)
EventService
subscribeVetoListenerExactly
in interface EventService
eventClass
- the class of published objects that can be vetoedvetoListener
- The vetoListener that can determine whether an event is published.
EventService.subscribeVetoListenerExactly(Class,VetoEventListener)
public boolean subscribeVetoListener(java.lang.String topic, VetoTopicEventListener vetoListener)
EventService
subscribeVetoListener
in interface EventService
topic
- the name of the topic listened tovetoListener
- The vetoListener that can determine whether an event is published.
EventService.subscribeVetoListener(String,VetoTopicEventListener)
public boolean subscribeVetoListener(java.util.regex.Pattern topicPattern, VetoTopicEventListener vetoListener)
EventService
subscribeVetoListener
in interface EventService
topicPattern
- the RegEx pattern to match topics withvetoListener
- The vetoListener that can determine whether an event is published.
EventService.subscribeVetoListener(Pattern,VetoTopicEventListener)
public boolean subscribeVetoListenerStrongly(java.lang.Class eventClass, VetoEventListener vetoListener)
EventService
EventService.unsubscribeVetoListener(Class,VetoEventListener)
is
called.
subscribeVetoListenerStrongly
in interface EventService
eventClass
- the class of published objects to listen tovetoListener
- The vetoListener that will accept the events when published.
EventService.subscribeVetoListenerStrongly(Class,VetoEventListener)
public boolean subscribeVetoListenerExactlyStrongly(java.lang.Class eventClass, VetoEventListener vetoListener)
EventService
EventService.unsubscribeVetoListener(Class,VetoEventListener)
is
called.
subscribeVetoListenerExactlyStrongly
in interface EventService
eventClass
- the class of published objects to listen tovetoListener
- The vetoListener that will accept the events when published.
EventService.subscribeVetoListenerExactlyStrongly(Class,VetoEventListener)
public boolean subscribeVetoListenerStrongly(java.lang.String topic, VetoTopicEventListener vetoListener)
EventService
EventService.unsubscribeVetoListener(String,VetoTopicEventListener)
is
called.
subscribeVetoListenerStrongly
in interface EventService
topic
- the name of the topic listened tovetoListener
- The topic vetoListener that will accept or reject publication.
EventService.subscribeVetoListenerStrongly(String,VetoTopicEventListener)
public boolean subscribeVetoListenerStrongly(java.util.regex.Pattern topicPattern, VetoTopicEventListener vetoListener)
EventService
EventService.unsubscribeVetoListener(Pattern,VetoTopicEventListener)
is
called.
subscribeVetoListenerStrongly
in interface EventService
topicPattern
- the RegEx pattern that matches the name of the topics listened tovetoListener
- The topic vetoListener that will accept or reject publication.
EventService.subscribeVetoListenerStrongly(Pattern,VetoTopicEventListener)
protected boolean subscribeVetoListener(java.lang.Object subscription, java.util.Map vetoListenerMap, java.lang.Object vetoListener)
o
- the topic, Pattern, or event class to subsribe tovetoListenerMap
- the internal map of veto listeners to use (by topic of class)vl
- the veto listener to subscribe, may be a VetoEventListener or a WeakReference to one
java.lang.IllegalArgumentException
- if vl or o is nullprotected boolean subscribe(java.lang.Object topicOrClass, java.util.Map subscriberMap, java.lang.Object subscriber)
o
- the topic String or event Class to subscribe tosubscriberMap
- the internal map of subscribers to use (by topic or class)subscriber
- the EventSubscriber or EventTopicSubscriber to subscribe, or a WeakReference to either
java.lang.IllegalArgumentException
- if subscriber or topicOrClass is nullpublic boolean unsubscribe(java.lang.Class cl, EventSubscriber eh)
EventService
unsubscribe
in interface EventService
cl
- the class of published objects to listen toeh
- The subscriber that is subscribed to the event. The same reference as that was subscribed.
EventService.unsubscribe(Class,EventSubscriber)
public boolean unsubscribeExactly(java.lang.Class cl, EventSubscriber eh)
EventService
unsubscribeExactly
in interface EventService
cl
- the class of published objects to listen toeh
- The subscriber that is subscribed to the event. The same reference as that was subscribed.
EventService.unsubscribeExactly(Class,EventSubscriber)
public boolean unsubscribe(java.lang.String name, EventTopicSubscriber eh)
EventService
unsubscribe
in interface EventService
name
- the topic listened toeh
- The subscriber that is subscribed to the topic. The same reference as that was subscribed.
EventService.unsubscribe(String,EventTopicSubscriber)
public boolean unsubscribe(java.util.regex.Pattern topicPattern, EventTopicSubscriber eh)
EventService
unsubscribe
in interface EventService
topicPattern
- the regex expression matching topics listened toeh
- The subscriber that is subscribed to the topic. The same reference as that was subscribed.
EventService.unsubscribe(String,EventTopicSubscriber)
public boolean unsubscribe(java.lang.Class eventClass, java.lang.Object subcribedByProxy)
EventService
unsubscribe
in interface EventService
eventClass
- class this object is subscribed to by proxysubcribedByProxy
- object subscribed by proxyEventService.unsubscribe(Class,Object)
public boolean unsubscribeExactly(java.lang.Class eventClass, java.lang.Object subcribedByProxy)
EventService
unsubscribeExactly
in interface EventService
eventClass
- class this object is subscribed to by proxysubcribedByProxy
- object subscribed by proxyEventService.unsubscribeExactly(Class,Object)
public boolean unsubscribe(java.lang.String topic, java.lang.Object subcribedByProxy)
EventService
unsubscribe
in interface EventService
topic
- the topic this object is subscribed to by proxysubcribedByProxy
- object subscribed by proxyEventService.unsubscribe(String,Object)
public boolean unsubscribe(java.util.regex.Pattern pattern, java.lang.Object subcribedByProxy)
EventService
unsubscribe
in interface EventService
pattern
- the RegEx expression this object is subscribed to by proxysubcribedByProxy
- object subscribed by proxyEventService.unsubscribe(java.util.regex.Pattern,Object)
protected boolean unsubscribe(java.lang.Object o, java.util.Map subscriberMap, java.lang.Object subscriber)
o
- the topic or event class to unsubsribe fromsubscriberMap
- the map of subscribers to use (by topic of class)eh
- the subscriber to unsubscribe, either an EventSubscriber or an EventTopicSubscriber, or a WeakReference
to either
public boolean unsubscribeVetoListener(java.lang.Class eventClass, VetoEventListener vetoListener)
EventService
unsubscribeVetoListener
in interface EventService
eventClass
- the class of published objects that can be vetoedvetoListener
- The vetoListener that will accept or reject publication of an event.
EventService.unsubscribeVetoListener(Class,VetoEventListener)
public boolean unsubscribeVetoListenerExactly(java.lang.Class eventClass, VetoEventListener vetoListener)
EventService
unsubscribeVetoListenerExactly
in interface EventService
eventClass
- the class of published objects that can be vetoedvetoListener
- The vetoListener that will accept or reject publication of an event.
EventService.unsubscribeVetoListenerExactly(Class,VetoEventListener)
public boolean unsubscribeVetoListener(java.lang.String topic, VetoTopicEventListener vetoListener)
EventService
unsubscribeVetoListener
in interface EventService
topic
- the name of the topic that is listened tovetoListener
- The vetoListener that can determine whether an event is published on that topic
EventService.unsubscribeVetoListener(String,VetoTopicEventListener)
public boolean unsubscribeVetoListener(java.util.regex.Pattern topicPattern, VetoTopicEventListener vetoListener)
EventService
unsubscribeVetoListener
in interface EventService
topicPattern
- the RegEx pattern matching the name of the topics listened tovetoListener
- The vetoListener that can determine whether an event is published on that topic
EventService.unsubscribeVetoListener(Pattern,VetoTopicEventListener)
protected boolean unsubscribeVetoListener(java.lang.Object o, java.util.Map vetoListenerMap, java.lang.Object vl)
o
- the topic or event class to unsubsribe fromvetoListenerMap
- the map of veto listeners to use (by topic or class)vl
- the veto listener to unsubscribe, or a WeakReference to one
public void publish(java.lang.Object event)
EventService
publish
in interface EventService
event
- The event that occuredEventService.publish(Object)
public void publish(java.lang.reflect.Type genericType, java.lang.Object event)
EventService
EventService.subscribe(Type, EventSubscriber)
, and to publish to subscribers to the non-generic type, i.e.,
those that use EventService.subscribe(Class, EventSubscriber)
.
Due to generic type erasure, the type must be supplied by the caller. You can get a declared object's
type by using the TypeReference
class. For Example:
TypeReference> subscribingTypeReference = new TypeReference
>(){}; EventBus.subscribe(subscribingTypeReference.getType(), mySubscriber); EventBus.subscribe(List.class, thisSubscriberWillGetCalledToo); ... //Likely in some other class TypeReference
> publishingTypeReference = new TypeReference
>(){}; List
trades = new ArrayList (); EventBus.publish(publishingTypeReference.getType(), trades); trades.add(trade); EventBus.publish(publishingTypeReference.getType(), trades);
publish
in interface EventService
genericType
- the generified type of the event. Due to generic type erasure, this must be supplied.event
- The event that occuredEventService.publish(java.lang.reflect.Type, Object)
public void publish(java.lang.String topicName, java.lang.Object eventObj)
EventService
publish
in interface EventService
topicName
- The name of the topic subscribed toeventObj
- the object to publishEventService.publish(String,Object)
protected void publish(java.lang.Object event, java.lang.String topic, java.lang.Object eventObj, java.util.List subscribers, java.util.List vetoSubscribers, java.lang.StackTraceElement[] callingStack)
event
- the event to publish, null if publishing on a topictopic
- if publishing on a topic, the topic to publish on, else nulleventObj
- if publishing on a topic, the eventObj to publish, else nullsubscribers
- the subscribers to publish to - must be a snapshot copyvetoSubscribers
- the veto subscribers to publish to - must be a snapshot copy.
java.lang.IllegalArgumentException
- if eh or o is nullprotected void addEventToCache(java.lang.Object event, java.lang.String topic, java.lang.Object eventObj)
event
- the event about to be published, null if topic is non-nulltopic
- the topic about to be published to, null if the event is non-nulleventObj
- the eventObj about to be published on a topic, null if the event is non-nullpublic java.util.List getSubscribers(java.lang.Class eventClass)
EventService
getSubscribers
in interface EventService
eventClass
- the eventClass of interest
EventService.getSubscribers(Class)
public java.util.List getSubscribersToClass(java.lang.Class eventClass)
getSubscribersToClass
in interface EventService
eventClass
- the eventClass of interest
EventService.getSubscribersToClass(Class)
public java.util.List getSubscribersToExactClass(java.lang.Class eventClass)
getSubscribersToExactClass
in interface EventService
eventClass
- the eventClass of interest
EventService.getSubscribersToExactClass(Class)
public java.util.List getSubscribers(java.lang.reflect.Type eventType)
EventService.getSubscribers(Class)
public java.util.List getSubscribers(java.lang.String topic)
EventService
getSubscribers
in interface EventService
topic
- the topic of interest
EventService.getSubscribers(String)
public java.util.List getSubscribersToTopic(java.lang.String topic)
getSubscribersToTopic
in interface EventService
topic
- the topic of interest
EventService.getSubscribers(Class)
public java.util.List getSubscribersByPattern(java.lang.String topic)
getSubscribersByPattern
in interface EventService
topic
- the RegEx pattern for the topic of interest
protected java.util.List getSubscribersToPattern(java.util.regex.Pattern topicPattern)
public java.util.List getVetoSubscribers(java.lang.Class eventClass)
getVetoSubscribers
in interface EventService
eventClass
- the eventClass of interest
EventService.getVetoSubscribers(Class)
public java.util.List getVetoSubscribersToClass(java.lang.Class eventClass)
getVetoSubscribersToClass
in interface EventService
eventClass
- the eventClass of interest
EventService.getVetoSubscribersToClass(Class)
public java.util.List getVetoSubscribersToExactClass(java.lang.Class eventClass)
getVetoSubscribersToExactClass
in interface EventService
eventClass
- the eventClass of interest
public java.util.List getVetoSubscribers(java.lang.String topic)
getVetoSubscribers
in interface EventService
topic
- the topic of interest
public java.util.List getVetoSubscribers(java.util.regex.Pattern topicPattern)
getVetoSubscribers
in interface EventService
topicPattern
- the RegEx pattern for the topic of interest
protected void subscribeTiming(SubscriberTimingEvent event)
protected void handleVeto(VetoEventListener vl, java.lang.Object event, VetoTopicEventListener vtl, java.lang.String topic, java.lang.Object eventObj)
vl
- the veto listener for an eventevent
- the event, can be null if topic is notvtl
- the veto listener for a topictopic
- can be null if event is noteventObj
- the object published with the topicpublic void setDefaultCacheSizePerClassOrTopic(int defaultCacheSizePerClassOrTopic)
setDefaultCacheSizePerClassOrTopic
in interface EventService
defaultCacheSizePerClassOrTopic
- public int getDefaultCacheSizePerClassOrTopic()
getDefaultCacheSizePerClassOrTopic
in interface EventService
public void setCacheSizeForEventClass(java.lang.Class eventClass, int cacheSize)
setCacheSizeForEventClass
in interface EventService
eventClass
- the class of eventcacheSize
- the number of published events to cache for this eventpublic int getCacheSizeForEventClass(java.lang.Class eventClass)
getCacheSizeForEventClass
in interface EventService
eventClass
- the class of event
setCacheSizeForEventClass(Class,int)
public void setCacheSizeForTopic(java.lang.String topicName, int cacheSize)
setCacheSizeForTopic
in interface EventService
topicName
- the topic namecacheSize
- the number of published data Objects to cache for this topcipublic void setCacheSizeForTopic(java.util.regex.Pattern pattern, int cacheSize)
setCacheSizeForTopic
in interface EventService
pattern
- the pattern matching topic namescacheSize
- the number of data Objects to cache for this topcipublic int getCacheSizeForTopic(java.lang.String topic)
getCacheSizeForTopic
in interface EventService
topic
- the topic name
setCacheSizeForTopic(String,int)
,
setCacheSizeForTopic(java.util.regex.Pattern,int)
public java.lang.Object getLastEvent(java.lang.Class eventClass)
getLastEvent
in interface EventService
eventClass
- an index into the cache, cannot be an inteface
public java.util.List getCachedEvents(java.lang.Class eventClass)
getCachedEvents
in interface EventService
eventClass
- an index into the cache, cannot be an inteface
public java.lang.Object getLastTopicData(java.lang.String topic)
getLastTopicData
in interface EventService
topic
- an index into the cache
public java.util.List getCachedTopicData(java.lang.String topic)
getCachedTopicData
in interface EventService
topic
- an index into the cache
public void clearCache(java.lang.Class eventClassToClear)
clearCache
in interface EventService
eventClassToClear
- the event class to clear the cache forpublic void clearCache(java.lang.String topic)
clearCache
in interface EventService
topic
- the topic name to clear the cache forpublic void clearCache(java.util.regex.Pattern pattern)
clearCache
in interface EventService
pattern
- the pattern to match topic caches topublic void clearCache()
clearCache
in interface EventService
protected void subscribeVetoException(java.lang.Object event, java.lang.String topic, java.lang.Object eventObj, java.lang.Throwable e, java.lang.StackTraceElement[] callingStack, VetoEventListener vetoer)
protected void onEventException(java.lang.String topic, java.lang.Object eventObj, java.lang.Throwable e, java.lang.StackTraceElement[] callingStack, EventTopicSubscriber eventTopicSubscriber)
protected void handleException(java.lang.Object event, java.lang.Throwable e, java.lang.StackTraceElement[] callingStack, EventSubscriber eventSubscriber)
protected void handleException(java.lang.String action, java.lang.Object event, java.lang.String topic, java.lang.Object eventObj, java.lang.Throwable e, java.lang.StackTraceElement[] callingStack, java.lang.String sourceString)
protected java.lang.Object getRealSubscriberAndCleanStaleSubscriberIfNecessary(java.util.Iterator iterator, java.lang.Object existingSubscriber)
iterator
- current iteratorexistingSubscriber
- the current value of the iterator
protected void removeProxySubscriber(ProxySubscriber proxy, java.util.Iterator iter)
protected void incWeakRefPlusProxySubscriberCount()
protected void decWeakRefPlusProxySubscriberCount()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |