org.LatencyUtils
Class TimeCappedMovingAverageIntervalEstimator

java.lang.Object
  extended by org.LatencyUtils.IntervalEstimator
      extended by org.LatencyUtils.MovingAverageIntervalEstimator
          extended by org.LatencyUtils.TimeCappedMovingAverageIntervalEstimator

public class TimeCappedMovingAverageIntervalEstimator
extends MovingAverageIntervalEstimator

A moving average interval estimator with a cap on the time window length that the moving window must completely fit in in order to provide estimated time intervals.

A time capped interval estimator is useful for conservatively estimating time intervals in environments where rates can change dramatically and semi-statically. For example, the rate of market rate updates seen just before market close can be very high, dropping dramatically at market close and staying low thereafter. A non-time-capped moving average estimator will project short estimated time interval long after market close, while a time capped interval estimator will avoid carrying the small time interval beyond the time cap.

TimeCappedMovingAverageIntervalEstimator estimates time intervals by averaging the time interval values recorded in a moving window, but if any of the results in the moving window occur outside of the capped time span requested, only the results that fall within the time cap will be considered.

TimeCappedMovingAverageIntervalEstimator can react to pauses reported by an optional PauseDetector by temporarily expanding the time cap to include each pause length, until such a time that the original time cap no longer overlaps with the pause. It will also subtract the pause length from interval times measured across a detected pause. Providing a pause detector is highly recommended, as without one the time cap can cause over-conservative interval estimation (i.e. estimated interval times that are much higher than needed) in the presence of pauses.

All times and time units are in nanoseconds


Field Summary
 
Fields inherited from class org.LatencyUtils.MovingAverageIntervalEstimator
count, intervalEndTimes, windowLength, windowMagnitude, windowMask
 
Constructor Summary
TimeCappedMovingAverageIntervalEstimator(int requestedWindowLength, long timeCap)
           
TimeCappedMovingAverageIntervalEstimator(int requestedWindowLength, long timeCap, PauseDetector pauseDetector)
           
 
Method Summary
 long getEstimatedInterval(long when)
          Provides the estimated interval
 void recordInterval(long when)
          Record an interval
 void stop()
          Stop the tracking via the pauseDetector, and remove this estimator from the pause detector's listeners.
 java.lang.String toString()
           
 
Methods inherited from class org.LatencyUtils.MovingAverageIntervalEstimator
getCurrentPosition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeCappedMovingAverageIntervalEstimator

public TimeCappedMovingAverageIntervalEstimator(int requestedWindowLength,
                                                long timeCap)
Parameters:
requestedWindowLength - The requested length of the moving window. May be rounded up to nearest power of 2.
timeCap - The cap on time span length (in nanosecond units) in which all window results must fit in order for average estimate to be provided

TimeCappedMovingAverageIntervalEstimator

public TimeCappedMovingAverageIntervalEstimator(int requestedWindowLength,
                                                long timeCap,
                                                PauseDetector pauseDetector)
Parameters:
requestedWindowLength - The requested length of the moving window. May be rounded up to nearest power of 2.
timeCap - The cap on time span length in which all window results must fit in order for average estimate to be provided
pauseDetector - The PauseDetector to use to track pauses
Method Detail

recordInterval

public void recordInterval(long when)
Description copied from class: IntervalEstimator
Record an interval

Overrides:
recordInterval in class MovingAverageIntervalEstimator
Parameters:
when - the end time (in nanoTime units) at which the interval was observed.

getEstimatedInterval

public long getEstimatedInterval(long when)
Description copied from class: IntervalEstimator
Provides the estimated interval

Overrides:
getEstimatedInterval in class MovingAverageIntervalEstimator
Parameters:
when - the time (preferably now) at which the estimated interval is requested.
Returns:
estimated interval

stop

public void stop()
Stop the tracking via the pauseDetector, and remove this estimator from the pause detector's listeners.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object