|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Observable | +--org.opendoors.util.PostponeObservable
PostponeObservable is the delegated instance for an observable with the following characteristic: notification of the change arrives after the observable has not changed for a period of n milliseconds.
This pattern solves a fundamental problem, namely thrashing. Thrashing occurs when the same action occurs repeatedly over short periods of time because the same event is fired, usually hundreds or thousand of times per second.
So, for example, if a cache changes thousands of times per second during a load or a transition to a new working set, how many times do you want to refresh it? Once or a thousand times? An instance of PostponeObservable allows your cache (or any changing object) to notify that it has changed just once.
Thus, changes are deferred so that the observers of the changes are not inundated with notifications.
Since this class implements the PropertyChangeListener interface, the class PropertyChangeSupport may also be employed as well to notify observers of changes.
This class is extends java.util.Observable. Observers must implement the interface java.util.Observer.
Note: Shared instances of a PostponeObservable must implement their own synchronizing strategy.
Postponeability may be enabled/disabled at runtime.
Observable
,
Observer
Field Summary | |
protected int |
postponeInterval
On property change, postpone event notification this number of millis. |
protected boolean |
resetClockOnUpdate
While waiting to fire a notification, reset the interval if another change comes in. |
Constructor Summary | |
PostponeObservable()
Constructs a default observable. |
|
PostponeObservable(int postponeInterval,
boolean resetClockOnUpdate)
Constructs a default observable with the following settings. |
Method Summary | |
void |
destroy()
Destoys this instance and the associated timer. |
void |
enablePostponeability(boolean enable)
Enables postponeability if true. |
protected void |
init()
Initializes the instance. |
void |
propertyChange(java.beans.PropertyChangeEvent evt)
Using the property event model propagate a change event to the observable. |
void |
setChanged()
Signals that the observable has changed. |
void |
setPostponePeriod(int postponeInterval)
Sets the observable period. |
void |
timerAction()
Call back from the timer when the observation period has expired. |
Methods inherited from class java.util.Observable |
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int postponeInterval
protected boolean resetClockOnUpdate
Constructor Detail |
public PostponeObservable()
public PostponeObservable(int postponeInterval, boolean resetClockOnUpdate)
The
- interval to wait in millis between notifications.Resets
- the clock so that changes can be aggregated
over a period of timeMethod Detail |
protected void init()
public void setPostponePeriod(int postponeInterval)
public void enablePostponeability(boolean enable)
public void propertyChange(java.beans.PropertyChangeEvent evt)
propertyChange
in interface java.beans.PropertyChangeListener
evt
- The property change event which can be null.public void timerAction()
public void setChanged()
Observers will be notified when
current time > (time of last change + postponeInterval)provided postponeability is enabled.
setChanged
in class java.util.Observable
public void destroy()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |