org.bushe.swing.event
Class SwingEventService
java.lang.Object
org.bushe.swing.event.ThreadSafeEventService
org.bushe.swing.event.SwingEventService
- All Implemented Interfaces:
- EventService
public class SwingEventService
- extends ThreadSafeEventService
An EventService
implementation for Swing.
This class is Swing thread-safe. All publish() calls NOT on the Swing EventDispatchThread thread are queued onto the
EDT. If the calling thread is the EDT, then this is a simple pass-through (i.e the subscribers are notified on the
same stack frame, just like they would be had they added themselves via Swing addXXListener methods).
Constructor Summary |
SwingEventService()
By default, the SwingEventService is constructed such that any listener that takes over 200 ms causes an
SubscriberTimingEvent to be published. |
SwingEventService(Long timeThresholdForEventTimingEventPublication)
|
SwingEventService(Long timeThresholdForEventTimingEventPublication,
boolean subscribeTimingEventsInternally)
Create a SwingEventService is such that any listener that takes over timeThresholdForEventTimingEventPublication
milliseconds causes an EventSubscriberTimingEvent to be published. |
Method Summary |
protected void |
publish(Object event,
String topic,
Object eventObj,
List subscribers,
List vetoSubscribers,
StackTraceElement[] callingStack)
Same as ThreadSafeEventService.publish(), except if the call is coming from a thread that is not the Swing Event
Dispatch Thread, the request is put on the EDT through a a call to SwingUtilities.invokeLater(). |
Methods inherited from class org.bushe.swing.event.ThreadSafeEventService |
addEventToCache, clearAllSubscribers, clearCache, clearCache, clearCache, clearCache, decWeakRefPlusProxySubscriberCount, getCachedEvents, getCachedTopicData, getCacheSizeForEventClass, getCacheSizeForTopic, getCleanupPeriodMS, getCleanupStartThreshhold, getCleanupStopThreshold, getDefaultCacheSizePerClassOrTopic, getLastEvent, getLastTopicData, getRealSubscriberAndCleanStaleSubscriberIfNecessary, getSubscribers, getSubscribers, getSubscribers, getSubscribers, getSubscribersByPattern, getSubscribersToClass, getSubscribersToExactClass, getSubscribersToPattern, getSubscribersToTopic, getVetoEventListeners, getVetoSubscribers, getVetoSubscribers, getVetoSubscribers, getVetoSubscribersByPattern, getVetoSubscribersToClass, getVetoSubscribersToExactClass, getVetoSubscribersToTopic, handleException, handleException, handleVeto, incWeakRefPlusProxySubscriberCount, onEventException, publish, publish, publish, removeProxySubscriber, setCacheSizeForEventClass, setCacheSizeForTopic, setCacheSizeForTopic, setCleanupPeriodMS, setCleanupStartThreshhold, setCleanupStopThreshold, setDefaultCacheSizePerClassOrTopic, setStatus, subscribe, subscribe, subscribe, subscribe, subscribe, subscribeExactly, subscribeExactlyStrongly, subscribeStrongly, subscribeStrongly, subscribeStrongly, subscribeTiming, subscribeVetoException, subscribeVetoListener, subscribeVetoListener, subscribeVetoListener, subscribeVetoListener, subscribeVetoListenerExactly, subscribeVetoListenerExactlyStrongly, subscribeVetoListenerStrongly, subscribeVetoListenerStrongly, subscribeVetoListenerStrongly, unsubscribe, unsubscribe, unsubscribe, unsubscribe, unsubscribe, unsubscribe, unsubscribe, unsubscribeExactly, unsubscribeExactly, unsubscribeVeto, unsubscribeVeto, unsubscribeVeto, unsubscribeVetoExactly, unsubscribeVetoListener, unsubscribeVetoListener, unsubscribeVetoListener, unsubscribeVetoListener, unsubscribeVetoListenerExactly |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SwingEventService
public SwingEventService()
- By default, the SwingEventService is constructed such that any listener that takes over 200 ms causes an
SubscriberTimingEvent to be published. You will need to add a subscriber to this event. Note that if you use
event to launch a modal dialog, the timings will be as long as the dialog is up - this is the way Swing works.
SwingEventService
public SwingEventService(Long timeThresholdForEventTimingEventPublication)
SwingEventService
public SwingEventService(Long timeThresholdForEventTimingEventPublication,
boolean subscribeTimingEventsInternally)
- Create a SwingEventService is such that any listener that takes over timeThresholdForEventTimingEventPublication
milliseconds causes an EventSubscriberTimingEvent to be published. You can add a subscriber to this event or set
subscribeTimingEventsInternally to true to cause the default logging to occur through the protected
ThreadSafeEventService.subscribeTiming(SubscriberTimingEvent)
call.
Note that if you use event to launch a modal dialog, the timings will be as long as the dialog is up - this is the
way Swing works.
- Parameters:
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 EventSubscriberTimingEvent internally and call the
protected ThreadSafeEventService.subscribeTiming(SubscriberTimingEvent)
method when they occur. This logs a warning to the
Logger
logger by default.
- Throws:
IllegalArgumentException
- if timeThresholdForEventTimingEventPublication is null and
subscribeTimingEventsInternally is true.
publish
protected void publish(Object event,
String topic,
Object eventObj,
List subscribers,
List vetoSubscribers,
StackTraceElement[] callingStack)
- Same as ThreadSafeEventService.publish(), except if the call is coming from a thread that is not the Swing Event
Dispatch Thread, the request is put on the EDT through a a call to SwingUtilities.invokeLater(). Otherwise this
DOES NOT post a new event on the EDT. The subscribers are called on the same EDT event, just like addXXXListeners
would be.
- Overrides:
publish
in class ThreadSafeEventService
- Parameters:
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
Copyright © 2011 Bushe Enterprises, Inc.. All Rights Reserved.