|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--lava.mv.MvModel | +--lava.util.SpeedometerModel
Measures progress rate.
Details: SpeedometerModel
is a tool for estimating realtime processing rates. Applications which need to perform long operations (such as file transfers), while displaying instantaneous progress rates, can benefit from this class.
To use this class, instantiate a new instance before each long operation, and then report intermediate progress data to the instance, using the recordProgress method, after each processing step. Your progress display should then call getRate as often as convenient (once every second, for example), in order to obtain an estimate of the current, instantaneous processing rate.
SpeedometerModel divides time into user-specified intervals, creating an accumulator for each interval. When the application calls recordProgress with an amount corresponding to each completed processing step, that amount is added to the accumulator for the current interval. Whenever getRate
is called, a weighted average based on the most recently passed intervals is computed and returned.
The formula for computing the instantaneous progress rate is designed to generate a stable result when the data amounts reported by the client arrive with relatively stable frequency and quantity. The formula is based on a weighted average that is biased towards the most recently measured time intervals.
Although it is not strictly necessary, you can use SpeedometerModel
as a model in programs that use the model-view design pattern. Views for SpeedometerModel
implement the IMvView
interface and receive periodic instantaneous processing rate updates via IMvView
's updateView
method. When updateView
is called, the ipModelId
parameter is a pointer to this instance and the ipModelData
parameter is an MvModelEvent
. If the event's getType
method returns CURRENT_RATE
, then getParam (0)
will return an Integer
representing the new instantaneous rate. (See sample code below.)
SpeedometerModel
is thread-safe.
Test application:
Field Summary | |
static int |
CURRENT_RATE
Indicates rate change. |
protected int |
mnInterval
Duration of metering period. |
protected int |
mnPeriods
History size. |
Constructor Summary | |
SpeedometerModel(int inPeriods,
int inInterval)
Sets number and length of metering intervals. |
Method Summary | |
void |
dispose()
Kills internal metering thread. |
protected void |
finalize()
Prepares for destruction. |
int |
getRate()
Returns current progress rate. |
void |
recordProgress(int inAmount)
Records progress. |
Methods inherited from class lava.mv.MvModel |
getEventDispatcher, notifyViews, notifyViews, registerView, setEventDispatcher, unregisterView |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int CURRENT_RATE
Details: CURRENT_RATE
indicates that a new instantaneous rate has been computed. This value is returned by MvModelEvent
s getType
method in views that subscribe to this model. If this model is expanded to generates other types of events, new type constants will be defined.
protected int mnPeriods
Details: mnPeriods is the number previously completed metering periods used to determine the instantaneous data rate.
protected int mnInterval
Details: mnInterval is the length, in milliseconds, of each metering period.
Constructor Detail |
public SpeedometerModel(int inPeriods, int inInterval)
Details: This constructor sets the number of intervals to track and the duration of each interval. Refer to the class introduction for details.
mnPeriods
- number of mnPeriods (buckets)mnInterval
- duration of each periodMethod Detail |
public void recordProgress(int inAmount)
Details: Called by the client, this method reports an amount of progress to be recorded. The client should call this method as often as it completes processing steps.
inAmount
- the amount of data processedpublic final int getRate()
Details: getRate
returns an estimate of the current, instantaneous progress rate.
public void dispose()
Details: dispose
causes the graceful death of this instance's internal metering thread. This method should only be called when this instance is no longer needed, in preparation for garbage collection.
protected void finalize()
Details: finalize
prepares this instance for destruction by calling dispose
.
finalize
in class java.lang.Object
|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |