|
||||||||||
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.
setDefaultCacheSizePerClassOrTopic(int)
, setCacheSizeForEventClass(Class, int)
, or
setCacheSizeForTopic(String, int)
, setCacheSizeForTopic(Pattern, int)
. Retrieve cached values
with getLastEvent(Class)
, getLastTopicData(String)
, getCachedEvents(Class)
, or
getCachedTopicData(String)
. Using caching while subscribing
is most likely to make sense only if you subscribe and publish on the same thread (so caching is very useful for
Swing applications since both happen on the EDT in a single-threaded manner). In multithreaded applications, you
never know if your subscriber has handled an event while it was being subscribed (before the subscribe() method
returned) that is newer or older than the retrieved cached value (taken before or after subscribe() respectively).
To deal with subscribers that take too long (a concern in Swing applications), the EventService can be made to issue
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.
Logger
. The Logger is configurable and supports multiple logging systems.
Exceptions are logged by default, override 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.
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 Long |
CLEANUP_PERIOD_MS_DEFAULT
|
static Integer |
CLEANUP_START_THRESHOLD_DEFAULT
|
static Integer |
CLEANUP_STOP_THRESHOLD_DEFAULT
|
protected static Logger |
LOG
|
Constructor Summary | |
---|---|
ThreadSafeEventService()
Creates a ThreadSafeEventService that does not monitor timing of handlers. |
|
ThreadSafeEventService(Integer cleanupStartThreshold,
Integer cleanupStopThreshold,
Long cleanupPeriodMS)
Creates a ThreadSafeEventService while providing proxy cleanup customization. |
|
ThreadSafeEventService(Long timeThresholdForEventTimingEventPublication)
Creates a ThreadSafeEventService while providing time monitoring options. |
|
ThreadSafeEventService(Long timeThresholdForEventTimingEventPublication,
boolean subscribeTimingEventsInternally)
Creates a ThreadSafeEventService while providing time monitoring options. |
|
ThreadSafeEventService(Long timeThresholdForEventTimingEventPublication,
boolean subscribeTimingEventsInternally,
Integer cleanupStartThreshold,
Integer cleanupStopThreshold,
Long cleanupPeriodMS)
Creates a ThreadSafeEventService while providing time monitoring options. |
Method Summary | ||
---|---|---|
protected void |
addEventToCache(Object event,
String topic,
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(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(Pattern pattern)
Clears the topic data cache for all topics that match a particular pattern. |
|
void |
clearCache(String topic)
Clears the topic data cache for a specific topic name. |
|
protected void |
decWeakRefPlusProxySubscriberCount()
Decrement the count of stale proxies |
|
List |
getCachedEvents(Class eventClass)
When caching, returns the last set of event published for the type supplied. |
|
List |
getCachedTopicData(String topic)
When caching, returns the last set of payload objects published on the topic name supplied. |
|
int |
getCacheSizeForEventClass(Class eventClass)
Returns the number of events cached for a particular class of event. |
|
int |
getCacheSizeForTopic(String topic)
Returns the number of cached data objects published on a particular topic. |
|
Long |
getCleanupPeriodMS()
Get the cleanup interval. |
|
Integer |
getCleanupStartThreshhold()
Gets the threshold above which cleanup starts. |
|
Integer |
getCleanupStopThreshold()
Gets the threshold below which cleanup stops. |
|
int |
getDefaultCacheSizePerClassOrTopic()
The default number of events or payloads kept per event class or topic |
|
Object |
getLastEvent(Class eventClass)
When caching, returns the last event publish for the type supplied. |
|
Object |
getLastTopicData(String topic)
When caching, returns the last payload published on the topic name supplied. |
|
protected Object |
getRealSubscriberAndCleanStaleSubscriberIfNecessary(Iterator iterator,
Object existingSubscriber)
Unsubscribe a subscriber if it is a stale ProxySubscriber. |
|
|
getSubscribers(Class<T> eventClass)
Union of getSubscribersToClass(Class) and getSubscribersToExactClass(Class) |
|
|
getSubscribers(Pattern pattern)
Gets the subscribers that subscribed to a regular expression. |
|
|
getSubscribers(String topic)
Union of getSubscribersByPattern(String) and geSubscribersToTopic(String) |
|
|
getSubscribers(Type eventType)
Gets the subscribers that subscribed to a generic type. |
|
|
getSubscribersByPattern(String topic)
Gets the subscribers that subscribed with a Pattern that matches the given topic. |
|
|
getSubscribersToClass(Class<T> eventClass)
Gets subscribers that subscribed with the given a class, but not those subscribed exactly to the class. |
|
|
getSubscribersToExactClass(Class<T> eventClass)
Gets subscribers that are subscribed exactly to a class, but not those subscribed non-exactly to a class. |
|
protected
|
getSubscribersToPattern(Pattern topicPattern)
|
|
|
getSubscribersToTopic(String topic)
Get the subscribers that subscribed to a topic. |
|
|
getVetoEventListeners(String topicOrPattern)
Union of EventService.getVetoSubscribersToTopic(String) and EventService.getVetoSubscribersByPattern(String)
Misnamed method, should be called EventService.getVetoSubscribers(String) . |
|
|
getVetoSubscribers(Class<T> eventClass)
Gets veto subscribers that subscribed to a given class. |
|
|
getVetoSubscribers(Pattern topicPattern)
Gets the veto subscribers that subscribed to a regular expression. |
|
|
getVetoSubscribers(String topic)
Deprecated. use getVetoSubscribersToTopic instead for direct replacement, or use getVetoEventListeners to get topic and pattern matchers. In EventBus 2.0 this name will replace getVetoEventListeners() and have it's union functionality |
|
|
getVetoSubscribersByPattern(String pattern)
Gets the veto subscribers that are subscribed by pattern that match the topic. |
|
|
getVetoSubscribersToClass(Class<T> eventClass)
Gets the veto subscribers that subscribed to a class. |
|
|
getVetoSubscribersToExactClass(Class<T> eventClass)
Get veto subscribers that subscribed to a given class exactly. |
|
|
getVetoSubscribersToTopic(String topic)
Gets the veto subscribers that subscribed to a topic. |
|
protected void |
handleException(Object event,
Throwable e,
StackTraceElement[] callingStack,
EventSubscriber eventSubscriber)
Called during event handling exceptions, calls handleException |
|
protected void |
handleException(String action,
Object event,
String topic,
Object eventObj,
Throwable e,
StackTraceElement[] callingStack,
String sourceString)
All exception handling goes through this method. |
|
protected void |
handleVeto(VetoEventListener vl,
Object event,
VetoTopicEventListener vtl,
String topic,
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(String topic,
Object eventObj,
Throwable e,
StackTraceElement[] callingStack,
EventTopicSubscriber eventTopicSubscriber)
Called during event handling exceptions, calls handleException |
|
void |
publish(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 the interfaces it implements. |
|
protected void |
publish(Object event,
String topic,
Object eventObj,
List subscribers,
List vetoSubscribers,
StackTraceElement[] callingStack)
All publish methods call this method. |
|
void |
publish(String topicName,
Object eventObj)
Publishes an object on a topic name so that all subscribers to that name or a Regular Expression that matches the topic name will be notified. |
|
void |
publish(Type genericType,
Object event)
Use this method to publish generified objects to subscribers of Types, i.e. |
|
protected void |
removeProxySubscriber(ProxySubscriber proxy,
Iterator iter)
|
|
void |
setCacheSizeForEventClass(Class eventClass,
int cacheSize)
Set the number of events cached for a particular class of event. |
|
void |
setCacheSizeForTopic(Pattern pattern,
int cacheSize)
Set the number of published data objects cached for topics matching a pattern. |
|
void |
setCacheSizeForTopic(String topicName,
int cacheSize)
Set the number of published data objects cached for a particular event topic. |
|
void |
setCleanupPeriodMS(Long cleanupPeriodMS)
Sets the cleanup interval. |
|
void |
setCleanupStartThreshhold(Integer cleanupStartThreshhold)
Sets the threshold above which cleanup starts. |
|
void |
setCleanupStopThreshold(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). |
|
protected void |
setStatus(PublicationStatus status,
Object event,
String topic,
Object eventObj)
Called during publication to set the status on an event. |
|
boolean |
subscribe(Class cl,
EventSubscriber eh)
Subscribes an EventSubscriber to the publication of objects matching a type. |
|
protected boolean |
subscribe(Object classTopicOrPatternWrapper,
Map<Object,Object> subscriberMap,
Object subscriber)
All subscribe methods call this method, including veto subscriptions. |
|
boolean |
subscribe(Pattern pat,
EventTopicSubscriber eh)
Subscribes an EventSubscriber to the publication of all the topic names that match a RegEx Pattern. |
|
boolean |
subscribe(String topic,
EventTopicSubscriber eh)
Subscribes an EventTopicSubscriber to the publication of a topic name. |
|
boolean |
subscribe(Type type,
EventSubscriber eh)
Subscribe an EventSubscriber to publication of generic Types. |
|
boolean |
subscribeExactly(Class cl,
EventSubscriber eh)
Subscribes an EventSubscriber to the publication of objects exactly matching a type. |
|
boolean |
subscribeExactlyStrongly(Class cl,
EventSubscriber eh)
Subscribes an EventSubscriber to the publication of objects matching a type exactly. |
|
boolean |
subscribeStrongly(Class cl,
EventSubscriber eh)
Subscribes an EventSubscriber to the publication of objects matching a type. |
|
boolean |
subscribeStrongly(Pattern pat,
EventTopicSubscriber eh)
Subscribes a subscriber to all the event topic names that match a RegEx expression. |
|
boolean |
subscribeStrongly(String name,
EventTopicSubscriber eh)
Subscribes a subscriber to an event topic name. |
|
protected void |
subscribeTiming(SubscriberTimingEvent event)
|
|
protected void |
subscribeVetoException(Object event,
String topic,
Object eventObj,
Throwable e,
StackTraceElement[] callingStack,
VetoEventListener vetoer)
Called during veto exceptions, calls handleException |
|
boolean |
subscribeVetoListener(Class eventClass,
VetoEventListener vetoListener)
Subscribes a VetoEventListener to publication of event matching a class. |
|
protected boolean |
subscribeVetoListener(Object subscription,
Map vetoListenerMap,
Object vetoListener)
All veto subscriptions methods call this method. |
|
boolean |
subscribeVetoListener(Pattern topicPattern,
VetoTopicEventListener vetoListener)
Subscribes an VetoTopicEventListener to all the topic names that match the RegEx Pattern. |
|
boolean |
subscribeVetoListener(String topic,
VetoTopicEventListener vetoListener)
Subscribes a VetoTopicEventListener to a topic name. |
|
boolean |
subscribeVetoListenerExactly(Class eventClass,
VetoEventListener vetoListener)
Subscribes a VetoEventListener to publication of an exact event class. |
|
boolean |
subscribeVetoListenerExactlyStrongly(Class eventClass,
VetoEventListener vetoListener)
Subscribes a VetoEventListener for an event class (but not its subclasses). |
|
boolean |
subscribeVetoListenerStrongly(Class eventClass,
VetoEventListener vetoListener)
Subscribes a VetoEventListener for an event class and its subclasses. |
|
boolean |
subscribeVetoListenerStrongly(Pattern topicPattern,
VetoTopicEventListener vetoListener)
Subscribes a VetoTopicEventListener to a set of topics that match a RegEx expression. |
|
boolean |
subscribeVetoListenerStrongly(String topic,
VetoTopicEventListener vetoListener)
Subscribes a VetoEventListener to a topic name. |
|
boolean |
unsubscribe(Class cl,
EventSubscriber eh)
Stop the subscription for a subscriber that is subscribed to a class. |
|
boolean |
unsubscribe(Class eventClass,
Object subscribedByProxy)
Stop a subscription for an object that is subscribed with a ProxySubscriber. |
|
protected boolean |
unsubscribe(Object o,
Map subscriberMap,
Object subscriber)
All event subscriber unsubscriptions call this method. |
|
boolean |
unsubscribe(Pattern topicPattern,
EventTopicSubscriber eh)
Stop the subscription for a subscriber that is subscribed to event topics via a Pattern. |
|
boolean |
unsubscribe(Pattern pattern,
Object subscribedByProxy)
When using annotations, an object may be subscribed by proxy. |
|
boolean |
unsubscribe(String name,
EventTopicSubscriber eh)
Stop the subscription for a subscriber that is subscribed to an event topic. |
|
boolean |
unsubscribe(String topic,
Object subscribedByProxy)
Stop a subscription for an object that is subscribed to a topic with a ProxySubscriber. |
|
boolean |
unsubscribeExactly(Class cl,
EventSubscriber eh)
Stop the subscription for a subscriber that is subscribed to an exact class. |
|
boolean |
unsubscribeExactly(Class eventClass,
Object subscribedByProxy)
Stop a subscription for an object that is subscribed exactly with a ProxySubscriber. |
|
boolean |
unsubscribeVeto(Class eventClass,
Object subscribedByProxy)
Stop a veto subscription for an object that is subscribed with a ProxySubscriber. |
|
boolean |
unsubscribeVeto(Pattern pattern,
Object subscribedByProxy)
When using annotations, an object may be subscribed by proxy. |
|
boolean |
unsubscribeVeto(String topic,
Object subscribedByProxy)
Stop a veto subscription for an object that is subscribed to a topic with a ProxySubscriber. |
|
boolean |
unsubscribeVetoExactly(Class eventClass,
Object subscribedByProxy)
Stop a veto subscription for an object that is subscribed exactly with a ProxySubscriber. |
|
boolean |
unsubscribeVetoListener(Class eventClass,
VetoEventListener vetoListener)
Stop the subscription for a vetoListener that is subscribed to an event class and its subclasses. |
|
protected boolean |
unsubscribeVetoListener(Object o,
Map vetoListenerMap,
Object vl)
All veto unsubscriptions methods call this method. |
|
boolean |
unsubscribeVetoListener(Pattern topicPattern,
VetoTopicEventListener vetoListener)
Stop the subscription for a VetoTopicEventListener that is subscribed to an event topic RegEx pattern. |
|
boolean |
unsubscribeVetoListener(String topic,
VetoTopicEventListener vetoListener)
Stop the subscription for a VetoTopicEventListener that is subscribed to an event topic name. |
|
boolean |
unsubscribeVetoListenerExactly(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 Integer CLEANUP_START_THRESHOLD_DEFAULT
public static final Integer CLEANUP_STOP_THRESHOLD_DEFAULT
public static final Long CLEANUP_PERIOD_MS_DEFAULT
protected static final Logger LOG
Constructor Detail |
---|
public ThreadSafeEventService()
public ThreadSafeEventService(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(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 the Logger
by
default.public ThreadSafeEventService(Integer cleanupStartThreshold, Integer cleanupStopThreshold, Long cleanupPeriodMS)
cleanupStartThreshold
- see class javadoc.cleanupStopThreshold
- see class javadoc.cleanupPeriodMS
- see class javadoc.public ThreadSafeEventService(Long timeThresholdForEventTimingEventPublication, boolean subscribeTimingEventsInternally, Integer cleanupStartThreshold, Integer cleanupStopThreshold, 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 the Logger
by
default.cleanupStartThreshold
- see class javadoc.cleanupStopThreshold
- see class javadoc.cleanupPeriodMS
- see class javadoc.
IllegalArgumentException
- if timeThresholdForEventTimingEventPublication is null and
subscribeTimingEventsInternally is true.Method Detail |
---|
public Integer getCleanupStartThreshhold()
public void setCleanupStartThreshhold(Integer cleanupStartThreshhold)
cleanupStartThreshhold
- threshold at which cleanup startspublic Integer getCleanupStopThreshold()
public void setCleanupStopThreshold(Integer cleanupStopThreshold)
cleanupStopThreshold
- threshold at which cleanup stops (it may start again).public Long getCleanupPeriodMS()
public void setCleanupPeriodMS(Long cleanupPeriodMS)
cleanupPeriodMS
- interval in milliseconds between cleanup runs. Passing null
stops cleanup.public boolean subscribe(Class cl, EventSubscriber eh)
EventService
subscribe
in interface EventService
cl
- the class of published objects to subscriber listen toeh
- The subscriber that will accept the events of the event class when published.
EventService.subscribe(Class,EventSubscriber)
public boolean subscribe(Type type, EventSubscriber eh)
EventService
EventService.publish(java.lang.reflect.Type, Object)
.
Due to generic type erasure, the type must be supplied by the publisher. You can get a declared object's
type by using the TypeReference
class. For Example:
TypeReference<List<Trade>> subscribingTypeReference = new TypeReference<List<Trade>>(){}; EventBus.subscribe(subscribingTypeReference.getType(), mySubscriber); EventBus.subscribe(List.class, thisSubscriberWillGetCalledToo); ... //Likely in some other class TypeReference<List<Trade>> publishingTypeReference = new TypeReference<List<Trade>>(){}; List<Trade> trades = new ArrayList<Trade>(); EventBus.publish(publishingTypeReference.getType(), trades); trades.add(trade); EventBus.publish(publishingTypeReference.getType(), trades);
subscribe
in interface EventService
type
- the generic type to subscribe toeh
- the subscriber to the type
EventService.subscribe(java.lang.reflect.Type, EventSubscriber)
public boolean subscribeExactly(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(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(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(Class cl, EventSubscriber eh)
EventService
EventService.subscribe(Class, EventSubscriber)
, except that the EventService holds
a regularly reference, not a WeakReference.
The subscriber will remain subscribed until 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(Class cl, EventSubscriber eh)
EventService
EventService.subscribeExactly(Class, EventSubscriber)
, except that the EventService
holds a regularly reference, not a WeakReference.
The subscriber will remain subscribed until 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(String name, EventTopicSubscriber eh)
EventService
EventService.subscribe(String, EventTopicSubscriber)
, except that the EventService
holds a regularly reference, not a WeakReference.
The subscriber will remain subscribed until 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(Pattern pat, EventTopicSubscriber eh)
EventService
EventService.subscribe(java.util.regex.Pattern, EventTopicSubscriber)
, except that the
EventService holds a regularly reference, not a WeakReference.
The subscriber will remain subscribed until 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(Class eventClass, VetoEventListener vetoListener)
EventService
subscribeVetoListener
in interface EventService
eventClass
- the class of published objects that can be vetoedvetoListener
- The VetoEventListener that can determine whether an event is published.
EventService.subscribeVetoListener(Class,VetoEventListener)
public boolean subscribeVetoListenerExactly(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(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(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(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(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(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(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(Object subscription, Map vetoListenerMap, Object vetoListener)
subscription
- the topic, Pattern, or event class to subscribe tovetoListenerMap
- the internal map of veto listeners to use (by topic of class)vetoListener
- the veto listener to subscribe, may be a VetoEventListener or a WeakReference to one
IllegalArgumentException
- if vl or o is nullprotected boolean subscribe(Object classTopicOrPatternWrapper, Map<Object,Object> subscriberMap, Object subscriber)
classTopicOrPatternWrapper
- the topic String, event Class, or PatternWrapper 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
IllegalArgumentException
- if subscriber or topicOrClass is nullpublic boolean unsubscribe(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 the one subscribed.
EventService.unsubscribe(Class,EventSubscriber)
public boolean unsubscribeExactly(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 the one subscribed.
EventService.unsubscribeExactly(Class,EventSubscriber)
public boolean unsubscribe(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 the one subscribed.
EventService.unsubscribe(String,EventTopicSubscriber)
public boolean unsubscribe(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 the one subscribed.
EventService.unsubscribe(String,EventTopicSubscriber)
public boolean unsubscribe(Class eventClass, Object subscribedByProxy)
EventService
unsubscribe
in interface EventService
eventClass
- class this object is subscribed to by proxysubscribedByProxy
- object subscribed by proxy
EventService.unsubscribe(Class,Object)
public boolean unsubscribeExactly(Class eventClass, Object subscribedByProxy)
EventService
unsubscribeExactly
in interface EventService
eventClass
- class this object is subscribed to by proxysubscribedByProxy
- object subscribed by proxy
EventService.unsubscribeExactly(Class,Object)
public boolean unsubscribe(String topic, Object subscribedByProxy)
EventService
unsubscribe
in interface EventService
topic
- the topic this object is subscribed to by proxysubscribedByProxy
- object subscribed by proxy
EventService.unsubscribe(String,Object)
public boolean unsubscribe(Pattern pattern, Object subscribedByProxy)
EventService
unsubscribe
in interface EventService
pattern
- the RegEx expression this object is subscribed to by proxysubscribedByProxy
- object subscribed by proxy
EventService.unsubscribe(java.util.regex.Pattern,Object)
protected boolean unsubscribe(Object o, Map subscriberMap, Object subscriber)
o
- the topic or event class to unsubscribe fromsubscriberMap
- the map of subscribers to use (by topic of class)subscriber
- the subscriber to unsubscribe, either an EventSubscriber or an EventTopicSubscriber, or a WeakReference
to either
public boolean unsubscribeVeto(Class eventClass, Object subscribedByProxy)
EventService
unsubscribeVeto
in interface EventService
eventClass
- class this object is subscribed to by proxysubscribedByProxy
- object subscribed by proxy
EventService.unsubscribeVeto(Class,Object)
public boolean unsubscribeVetoExactly(Class eventClass, Object subscribedByProxy)
EventService
unsubscribeVetoExactly
in interface EventService
eventClass
- class this object is subscribed to by proxysubscribedByProxy
- object subscribed by proxy
EventService.unsubscribeVetoExactly(Class,Object)
public boolean unsubscribeVeto(String topic, Object subscribedByProxy)
EventService
unsubscribeVeto
in interface EventService
topic
- the topic this object is subscribed to by proxysubscribedByProxy
- object subscribed by proxy
EventService.unsubscribeVeto(String,Object)
public boolean unsubscribeVeto(Pattern pattern, Object subscribedByProxy)
EventService
unsubscribeVeto
in interface EventService
pattern
- the RegEx expression this object is subscribed to by proxysubscribedByProxy
- object subscribed by proxy
EventService.unsubscribeVeto(java.util.regex.Pattern,Object)
public boolean unsubscribeVetoListener(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(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(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(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(Object o, Map vetoListenerMap, Object vl)
o
- the topic or event class to unsubscribe 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(Object event)
EventService
publish
in interface EventService
event
- the object to publishEventService.publish(Object)
public void publish(Type genericType, Object event)
EventService
EventService.subscribe(Type, EventSubscriber)
, and to publish to subscribers of the non-generic type.
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<List<Trade>> subscribingTypeReference = new TypeReference<List<Trade>>(){}; EventBus.subscribe(subscribingTypeReference.getType(), mySubscriber); EventBus.subscribe(List.class, thisSubscriberWillGetCalledToo); ... //Likely in some other class TypeReference<List<Trade>> publishingTypeReference = new TypeReference<List<Trade>>(){}; List<Trade> trades = new ArrayList<Trade>(); EventBus.publish(publishingTypeReference.getType(), trades); trades.add(trade); EventBus.publish(publishingTypeReference.getType(), trades);
publish
in interface EventService
genericType
- the generified type of the published object.event
- The event that occurredEventService.publish(java.lang.reflect.Type, Object)
public void publish(String topicName, 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(Object event, String topic, Object eventObj, List subscribers, List vetoSubscribers, 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.callingStack
- the stack that called this publication, helpful for reporting errors on other threads
IllegalArgumentException
- if eh or o is nullprotected void setStatus(PublicationStatus status, Object event, String topic, Object eventObj)
status
- the status to set on the objectevent
- the event being published, will be null if topic is not nulltopic
- the topic eventObj is being published on, will be null if event is not nulleventObj
- the payload being published on the topic , will be null if event is not nullprotected void addEventToCache(Object event, String topic, 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 <T> List<T> getSubscribers(Class<T> eventClass)
EventService
getSubscribers
in interface EventService
eventClass
- the eventClass of interest
EventService.getSubscribers(Class)
public <T> List<T> getSubscribersToClass(Class<T> eventClass)
EventService
getSubscribersToClass
in interface EventService
eventClass
- the eventClass of interest
EventService.getSubscribersToClass(Class)
public <T> List<T> getSubscribersToExactClass(Class<T> eventClass)
EventService
getSubscribersToExactClass
in interface EventService
eventClass
- the eventClass of interest
EventService.getSubscribersToExactClass(Class)
public <T> List<T> getSubscribers(Type eventType)
EventService
getSubscribers
in interface EventService
eventType
- the type of interest
EventService.getSubscribers(Type)
public <T> List<T> getSubscribers(String topic)
EventService
getSubscribers
in interface EventService
topic
- the topic of interest
EventService.getSubscribers(String)
public <T> List<T> getSubscribersToTopic(String topic)
EventService
getSubscribersToTopic
in interface EventService
topic
- the topic of interest
EventService.getSubscribersToTopic(String)
public <T> List<T> getSubscribers(Pattern pattern)
EventService
getSubscribers
in interface EventService
pattern
- the RegEx pattern that was subscribed to
EventService.getSubscribers(Pattern)
public <T> List<T> getSubscribersByPattern(String topic)
EventService
getSubscribersByPattern
in interface EventService
topic
- a topic to match Patterns against
EventService.getSubscribersByPattern(String)
public <T> List<T> getVetoSubscribers(Class<T> eventClass)
EventService
getVetoSubscribers
in interface EventService
eventClass
- the eventClass of interest
EventService.getVetoSubscribers(Class)
public <T> List<T> getVetoSubscribersToClass(Class<T> eventClass)
EventService
getVetoSubscribersToClass
in interface EventService
eventClass
- the eventClass of interest
EventService.getVetoSubscribersToClass(Class)
public <T> List<T> getVetoSubscribersToExactClass(Class<T> eventClass)
EventService
getVetoSubscribersToExactClass
in interface EventService
eventClass
- the eventClass of interest
EventService.getVetoSubscribersToExactClass(Class)
public <T> List<T> getVetoEventListeners(String topicOrPattern)
EventService
EventService.getVetoSubscribersToTopic(String)
and EventService.getVetoSubscribersByPattern(String)
Misnamed method, should be called EventService.getVetoSubscribers(String)
. Will be deprecated in 1.5.
getVetoEventListeners
in interface EventService
topicOrPattern
- the topic or pattern of interest
EventService.getVetoEventListeners(String)
public <T> List<T> getVetoSubscribersToTopic(String topic)
EventService
getVetoSubscribersToTopic
in interface EventService
topic
- the topic of interest
EventService.getVetoSubscribersToTopic(String)
public <T> List<T> getVetoSubscribers(String topic)
getVetoSubscribers
in interface EventService
topic
- the topic exactly subscribed to
EventService.getVetoSubscribersToTopic(String)
public <T> List<T> getVetoSubscribers(Pattern topicPattern)
EventService
getVetoSubscribers
in interface EventService
topicPattern
- the RegEx pattern for the topic of interest
EventService.getVetoSubscribers(Pattern)
public <T> List<T> getVetoSubscribersByPattern(String pattern)
EventService
getVetoSubscribersByPattern
in interface EventService
pattern
- the topic to match the pattern string subscribed to
EventService.getVetoSubscribersByPattern(String)
protected <T> List<T> getSubscribersToPattern(Pattern topicPattern)
protected void subscribeTiming(SubscriberTimingEvent event)
protected void handleVeto(VetoEventListener vl, Object event, VetoTopicEventListener vtl, String topic, 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()
EventService
getDefaultCacheSizePerClassOrTopic
in interface EventService
public void setCacheSizeForEventClass(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(Class eventClass)
getCacheSizeForEventClass
in interface EventService
eventClass
- the class of event
setCacheSizeForEventClass(Class,int)
public void setCacheSizeForTopic(String topicName, int cacheSize)
setCacheSizeForTopic
in interface EventService
topicName
- the topic namecacheSize
- the number of published data Objects to cache for this topicpublic void setCacheSizeForTopic(Pattern pattern, int cacheSize)
setCacheSizeForTopic
in interface EventService
pattern
- the pattern matching topic namescacheSize
- the number of data Objects to cache for this topicpublic int getCacheSizeForTopic(String topic)
getCacheSizeForTopic
in interface EventService
topic
- the topic name
setCacheSizeForTopic(String,int)
,
setCacheSizeForTopic(java.util.regex.Pattern,int)
public Object getLastEvent(Class eventClass)
EventService
getLastEvent
in interface EventService
eventClass
- an index into the cache, cannot be an interface
public List getCachedEvents(Class eventClass)
EventService
getCachedEvents
in interface EventService
eventClass
- an index into the cache, cannot be an interface
public Object getLastTopicData(String topic)
EventService
getLastTopicData
in interface EventService
topic
- an index into the cache
public List getCachedTopicData(String topic)
EventService
getCachedTopicData
in interface EventService
topic
- an index into the cache
public void clearCache(Class eventClassToClear)
clearCache
in interface EventService
eventClassToClear
- the event class to clear the cache forpublic void clearCache(String topic)
clearCache
in interface EventService
topic
- the topic name to clear the cache forpublic void clearCache(Pattern pattern)
clearCache
in interface EventService
pattern
- the pattern to match topic caches topublic void clearCache()
clearCache
in interface EventService
protected void subscribeVetoException(Object event, String topic, Object eventObj, Throwable e, StackTraceElement[] callingStack, VetoEventListener vetoer)
protected void onEventException(String topic, Object eventObj, Throwable e, StackTraceElement[] callingStack, EventTopicSubscriber eventTopicSubscriber)
protected void handleException(Object event, Throwable e, StackTraceElement[] callingStack, EventSubscriber eventSubscriber)
protected void handleException(String action, Object event, String topic, Object eventObj, Throwable e, StackTraceElement[] callingStack, String sourceString)
protected Object getRealSubscriberAndCleanStaleSubscriberIfNecessary(Iterator iterator, Object existingSubscriber)
iterator
- current iteratorexistingSubscriber
- the current value of the iterator
protected void removeProxySubscriber(ProxySubscriber proxy, Iterator iter)
protected void incWeakRefPlusProxySubscriberCount()
protected void decWeakRefPlusProxySubscriberCount()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |