|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.metamatrix.console.util.AutoRefresher
public class AutoRefresher
Utility class to cause an automatic refresh of data controlled by the 'target' class. Intended to be used by panels representing sub applications within the Console. Could also be used by an external controller who would manage a set of these objects and the panels they control.
Clients can specify a refresh rate in seconds, and dynamically enable or disable auto refreshing.
An AutoRefresher has a true
property, which controllers/targets
should
set to true
when about to start a lengthy network operation,
and then set to false
when and if the operation finishes.
The AutoRefresher class will ignore it's internal timer while
busy, since it is in the middle of refreshing itself anyway. Note:
it is a good idea to set the code that sets busy
back to
false
in a finally
block, to ensure that the
AutoRefresher will be un-busied in the event of a failed network operation.
Example:
public class SomePanel extends BasePanel { public Collection retrieveSomeData() { Collection result; try{ arAutoRefresher.setBusy(true); //HERE'S THE OPERATION THAT CAN TAKE SOME TIME, AND //POTENTIALLY FAIL -------------------------------- result = remoteProxy.retrieveSomeData; //------------------------------------------------- } catch (SomeException e) { //do something } catch (OtherException e) { //do something } finally { arAutoRefresher.setBusy(false); } } }
Field Summary | |
---|---|
static int |
DEFAULT_DELAY
Default refresh rate (seconds) used if none is otherwise specified. |
Constructor Summary | |
---|---|
AutoRefresher(AutoRefreshable refTarget,
ConnectionInfo conn)
Creates an AutoRefresher with the default refresh rate |
|
AutoRefresher(AutoRefreshable refTarget,
int refreshRateSeconds,
boolean isAutoRefreshEnabled,
ConnectionInfo conn)
Creates an AutoRefresher with the specified refresh rate |
|
AutoRefresher(AutoRefreshable refTarget,
int refreshRateSeconds,
ConnectionInfo conn)
Creates an AutoRefresher with the specified refresh rate |
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
This method, called by this Manager's Timer, indicates that time has run out. |
int |
getRefreshRate()
|
protected javax.swing.Timer |
getTimer()
Returns the Timer object used by AutoRefresher. |
void |
init()
Calls super.init() and also initializes timing behavior. |
boolean |
isAutoRefreshEnabled()
If the autoRefresh feature of AutoRefresher is enabled, the timer will run and the Manager will be notified each time the timer runs out, and will call it's own refresh() method. |
boolean |
isBusy()
Indicates whether this AutoRefresher is in the middle of a network call or not. |
void |
refresh()
|
void |
refresh(boolean setIsStale)
This method calls super.refresh and, additionally, stops the timer running. |
void |
setAutoRefreshEnabled(boolean isAutoRefreshEnabled)
If the autoRefresh feature of AutoRefresher is enabled, the timer will run and the Manager will be notified each time the timer runs out, and will call it's own refresh() method. |
void |
setBusy(boolean busy)
Indicates whether this AutoRefresher is in the middle of a network call or not. |
void |
setRefreshRate(int seconds)
Subclasses of AutoRefresher must be sure to set their refresh rate, in addition to other initialization behavior. |
void |
setRefreshTarget(AutoRefreshable ref)
|
void |
startTimer()
If the timer isn't already started, and autoRefresh is enabled, starts this Timed Manager's clock ticking until a Manager's data in memory is considered stale. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_DELAY
Constructor Detail |
---|
public AutoRefresher(AutoRefreshable refTarget, ConnectionInfo conn)
DEFAULT_DELAY
public AutoRefresher(AutoRefreshable refTarget, int refreshRateSeconds, ConnectionInfo conn)
refreshRateSeconds
- rate at which AutoRefresher refreshes itselfpublic AutoRefresher(AutoRefreshable refTarget, int refreshRateSeconds, boolean isAutoRefreshEnabled, ConnectionInfo conn)
refreshRateSeconds
- rate at which AutoRefresher refreshes itselfisAutoRefreshEnabled
- controls whether AutoRefresher will
refresh itself or notMethod Detail |
---|
public void init()
setRefreshRate(int)
public void startTimer()
Note that this method may always be called - it will only start the timer if autoRefresh is enabled.
There is no explicit stopTimer method, rather the refresh method causes the timer to stop. (The refresh method is either called by some outside code, or by this AutoRefresher when it's timer runs out.)
refresh(boolean)
,
AutoRefresher#setIsAutoRefreshEnabled
public void refresh(boolean setIsStale)
startTimer()
public void refresh()
public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
refresh(boolean)
public void setRefreshTarget(AutoRefreshable ref)
public int getRefreshRate()
public void setRefreshRate(int seconds)
seconds
- time after which data is stalepublic boolean isAutoRefreshEnabled()
public void setAutoRefreshEnabled(boolean isAutoRefreshEnabled)
protected javax.swing.Timer getTimer()
public boolean isBusy()
Managers should set themselves to busy right before beginning a potentially long network operation, and set themselves to not busy right after the operation completes.
public void setBusy(boolean busy)
Managers should set themselves to busy right before beginning a potentially long network operation, and set themselves to not busy right after the operation completes.
busy
- indicates AutoRefresher is in the middle of an atomic
network call
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |