com.metamatrix.console.models
Class TimedManager

java.lang.Object
  extended by com.metamatrix.console.models.Manager
      extended by com.metamatrix.console.models.TimedManager
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener
Direct Known Subclasses:
QueryManager, ServerLogManager, SessionManager, SummaryManager, TransactionManager

public abstract class TimedManager
extends Manager
implements java.awt.event.ActionListener

Abstract superclass of timed managers - timed managers maintain data which becomes stale after a certain amount of time, and needs periodic refreshing.

Clients can specify a refresh rate in seconds, and dynamically enable or disable auto refreshing.

A TimedManager has a true property, which subclasses should set to true when about to start a lengthy network operation, and then set to false when and if the operation finishes. The TimedManager 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 TimedManager will be un-busied in the event of a failed network operation.

Example:

public class SomeDataManager extends TimedManager{

    public Collection retrieveSomeData(){
        Collection result;
        try{
            super.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{
            super.setBusy(false);
        }
    }
}


Field Summary
static int DEFAULT_DELAY
          Default refresh rate (seconds) used if none is otherwise specified.
 
Fields inherited from class com.metamatrix.console.models.Manager
MODEL_CHANGED, MODEL_STALE
 
Constructor Summary
TimedManager(ConnectionInfo connection)
          Creates a TimedManager with the default refresh rate
TimedManager(ConnectionInfo connection, int refreshRateSeconds)
          Creates a TimedManager with the specified refresh rate
TimedManager(ConnectionInfo connection, int refreshRateSeconds, boolean isAutoRefreshEnabled)
          Creates a TimedManager 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.
 boolean getIsAutoRefreshEnabled()
          If the autoRefresh feature of TimedManager 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.
 int getRefreshRate()
           
protected  javax.swing.Timer getTimer()
          Returns the Timer object used by TimedManager.
 void init()
          Calls super.init() and also initializes timing behavior.
 boolean isBusy()
          Indicates whether this TimedManager is in the middle of a network call or not.
 void refresh()
          Refresh tells a manager that it's data is stale and it should retrieve real data (rather than cached data) the next time data is requested.
 void refresh(boolean setIsStale)
          This method calls super.refresh and, additionally, stops the timer running.
 void setBusy(boolean busy)
          Indicates whether this TimedManager is in the middle of a network call or not.
 void setIsAutoRefreshEnabled(boolean isAutoRefreshEnabled)
          If the autoRefresh feature of TimedManager 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 setRefreshRate(int seconds)
          Subclasses of TimedManager must be sure to set their refresh rate, in addition to other initialization behavior.
 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 com.metamatrix.console.models.Manager
addManagerListener, fireModelChangedEvent, fireModelChangedEvent, getConnection, getConnection, getEncryptor, getEventListeners, getIsStale, removeManagerListener, setIsStale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DELAY

public static final int DEFAULT_DELAY
Default refresh rate (seconds) used if none is otherwise specified.

See Also:
Constant Field Values
Constructor Detail

TimedManager

public TimedManager(ConnectionInfo connection)
Creates a TimedManager with the default refresh rate

See Also:
DEFAULT_DELAY

TimedManager

public TimedManager(ConnectionInfo connection,
                    int refreshRateSeconds)
Creates a TimedManager with the specified refresh rate

Parameters:
refreshRateSeconds - rate at which TimedManager refreshes itself

TimedManager

public TimedManager(ConnectionInfo connection,
                    int refreshRateSeconds,
                    boolean isAutoRefreshEnabled)
Creates a TimedManager with the specified refresh rate

Parameters:
refreshRateSeconds - rate at which TimedManager refreshes itself
isAutoRefreshEnabled - controls whether TimedManager will refresh itself or not
Method Detail

init

public void init()
Calls super.init() and also initializes timing behavior.

Overrides:
init in class Manager
See Also:
setRefreshRate(int)

startTimer

public 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. Subclasses of TimedManager should call this method every time a request is made for its data.

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 TimedManager when it's timer runs out.)

See Also:
refresh(boolean), setIsAutoRefreshEnabled(boolean)

refresh

public void refresh(boolean setIsStale)
This method calls super.refresh and, additionally, stops the timer running. Subclasses of this TimedManager class must be sure to call the start() method whenever it retrieves its data.

See Also:
startTimer(), Manager.refresh()

refresh

public void refresh()
Description copied from class: Manager
Refresh tells a manager that it's data is stale and it should retrieve real data (rather than cached data) the next time data is requested.

Currently this method simply calls setIsStale(false)

Overrides:
refresh in class Manager
See Also:
Manager.setIsStale(boolean)

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
This method, called by this Manager's Timer, indicates that time has run out. In response, this manager triggers its own refresh.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
See Also:
refresh(boolean)

getRefreshRate

public int getRefreshRate()
Returns:
time, in seconds, after which data is stale

setRefreshRate

public void setRefreshRate(int seconds)
Subclasses of TimedManager must be sure to set their refresh rate, in addition to other initialization behavior.

Parameters:
seconds - time after which data is stale

getIsAutoRefreshEnabled

public boolean getIsAutoRefreshEnabled()
If the autoRefresh feature of TimedManager 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. Disabling autoRefresh means that a TimedManager can only be refreshed by explicitly having its refresh() method called.

Returns:
boolean indicating if AutoRefresh is enabled or not

setIsAutoRefreshEnabled

public void setIsAutoRefreshEnabled(boolean isAutoRefreshEnabled)
If the autoRefresh feature of TimedManager 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. Disabling autoRefresh means that a TimedManager can only be refreshed by explicitly having its refresh() method called.


getTimer

protected javax.swing.Timer getTimer()
Returns the Timer object used by TimedManager. It is not intended that it will ever be necessary to access this object directly.


isBusy

public boolean isBusy()
Indicates whether this TimedManager is in the middle of a network call or not. TimedManager will ignore its internal timer during this time, if auto-refresh is enabled.

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.

Returns:
boolean indicating whether TimedManager is in the middle of an atomic lengthy call

setBusy

public void setBusy(boolean busy)
Indicates whether this TimedManager is in the middle of a network call or not. TimedManager will ignore its internal timer during this time, if auto-refresh is enabled.

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.

Parameters:
busy - indicates TimedManager is in the middle of an atomic network call


Copyright © 2009. All Rights Reserved.