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
| Modifier and Type | Class and Description |
|---|---|
| private static class | TimeCappedMovingAverageIntervalEstimator.PauseTracker
PauseTracker is used to feed pause correction histograms whenever a pause is reported: |
| Modifier and Type | Field and Description |
|---|---|
| private final long | |
| private int | |
| private static final int | |
| private int | |
| private AtomicLongArray | |
| private AtomicLongArray | |
| private final TimeCappedMovingAverageIntervalEstimator. | |
| private long | |
| private volatile long |
| Access | Constructor and Description |
|---|---|
| public | TimeCappedMovingAverageIntervalEstimator(final int
The requested length of the moving window. May be rounded up to nearest
power of 2. requestedWindowLength, final long The cap on time span length (in nanosecond units) in which all window results must fit
in order for average estimate to be provided timeCap)
|
| public | TimeCappedMovingAverageIntervalEstimator(final int
The requested length of the moving window. May be rounded up to nearest
power of 2. requestedWindowLength, final long The cap on time span length in which all window results must fit in order for average
estimate to be provided timeCap, final PauseDetector The PauseDetector to use to track pauses pauseDetector)
|
| Modifier and Type | Method and Description |
|---|---|
| private long | |
| private int | |
| private void | |
| public synchronized long | getEstimatedInterval(final long
the time (preferably now) at which the estimated interval is requested. when)Overrides org. |
| public void | recordInterval(long
the end time (in nanoTime units) at which the interval was observed. when)Overrides org. |
| private synchronized void | |
| public void | stop()
Stop the tracking via the pauseDetector, and remove this estimator from the pause detector's listeners. |
| public String |
| baseTimeCap | back to summary |
|---|---|
| private final long baseTimeCap | |
| earliestPauseIndex | back to summary |
|---|---|
| private int earliestPauseIndex | |
| maxPausesToTrack | back to summary |
|---|---|
| private static final int maxPausesToTrack | |
| nextPauseRecordingIndex | back to summary |
|---|---|
| private int nextPauseRecordingIndex | |
| pauseLengths | back to summary |
|---|---|
| private AtomicLongArray pauseLengths | |
| pauseStartTimes | back to summary |
|---|---|
| private AtomicLongArray pauseStartTimes | |
| pauseTracker | back to summary |
|---|---|
| private final TimeCappedMovingAverageIntervalEstimator. | |
| timeCap | back to summary |
|---|---|
| private long timeCap | |
| timeOfLastEstimatedInterval | back to summary |
|---|---|
| private volatile long timeOfLastEstimatedInterval | |
| TimeCappedMovingAverageIntervalEstimator | back to summary |
|---|---|
public TimeCappedMovingAverageIntervalEstimator(final int requestedWindowLength, final long timeCap)
| |
| TimeCappedMovingAverageIntervalEstimator | back to summary |
|---|---|
public TimeCappedMovingAverageIntervalEstimator(final int requestedWindowLength, final long timeCap, final PauseDetector pauseDetector)
| |
| determineEarliestQualifyingTimeInWindow | back to summary |
|---|---|
| private long determineEarliestQualifyingTimeInWindow(final long when) | |
| determineNumberOfWindowPositionsOutsideOfTimeCap | back to summary |
|---|---|
| private int determineNumberOfWindowPositionsOutsideOfTimeCap(long when) | |
| eliminateStalePauses | back to summary |
|---|---|
| private void eliminateStalePauses(final long when) | |
| getEstimatedInterval | back to summary |
|---|---|
| public synchronized long getEstimatedInterval(final long when) Overrides org. Doc from org. Provides the estimated interval
| |
| recordInterval | back to summary |
|---|---|
| public void recordInterval(long when) Overrides org. Doc from org. Record an interval
| |
| recordPause | back to summary |
|---|---|
| private synchronized void recordPause(final long pauseLength, final long pauseEndTime) | |
| stop | back to summary |
|---|---|
| public void stop() Stop the tracking via the pauseDetector, and remove this estimator from the pause detector's listeners. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final PauseDetector |
| Access | Constructor and Description |
|---|---|
| pack-priv | PauseTracker(final PauseDetector pauseDetector, final TimeCappedMovingAverageIntervalEstimator estimator)
|
| Modifier and Type | Method and Description |
|---|---|
| public void | handlePauseEvent(final long
Length of reported pause (in nanoseconds) pauseLength, final long Time sampled at end of reported pause (in nanoTime units). pauseEndTime)Implements org. |
| public void |
| pauseDetector | back to summary |
|---|---|
| pack-priv final PauseDetector pauseDetector | |
| PauseTracker | back to summary |
|---|---|
| pack-priv PauseTracker(final PauseDetector pauseDetector, final TimeCappedMovingAverageIntervalEstimator estimator) | |
| handlePauseEvent | back to summary |
|---|---|
| public void handlePauseEvent(final long pauseLength, final long pauseEndTime) Implements org. Doc from org. handle a pause event notification.
| |
| stop | back to summary |
|---|---|
| public void stop() | |