protected void calibrate ( ) { long currentTimer = current ( ) ; long currentMillis = System . currentTimeMillis ( ) ; long elapsedTimer = currentTimer - _driftTimerStamp ; float elapsedMillis = currentMillis - _driftMilliStamp ; float drift = elapsedMillis / ( elapsedTimer / _milliDivider ) ; if ( _debugCalibrate . getValue ( ) ) { log . warning ( "Calibrating" , "timer" , elapsedTimer , "millis" , elapsedMillis , "drift" , drift , "timerstamp" , _driftTimerStamp , "millistamp" , _driftMilliStamp , "current" , currentTimer ) ; } if ( elapsedTimer < 0 ) { log . warning ( "The timer has decided to live in the past, resetting drift" , "previousTimer" , _driftTimerStamp , "currentTimer" , currentTimer , "previousMillis" , _driftMilliStamp , "currentMillis" , currentMillis ) ; _driftRatio = 1.0F ; } else if ( drift > MAX_ALLOWED_DRIFT_RATIO || drift < MIN_ALLOWED_DRIFT_RATIO ) { log . warning ( "Calibrating" , "drift" , drift ) ; // Ignore the drift if it's hugely out of range. That indicates general clock insanity, // and we just want to stay out of the way. if ( drift < 100 * MAX_ALLOWED_DRIFT_RATIO && drift > MIN_ALLOWED_DRIFT_RATIO / 100 ) { _driftRatio = drift ; } else { _driftRatio = 1.0F ; } if ( Math . abs ( drift - 1.0 ) > Math . abs ( _maxDriftRatio - 1.0 ) ) { _maxDriftRatio = drift ; } } else if ( _driftRatio != 1.0 ) { log . warning ( "Calibrating" , "drift" , drift ) ; // If we're within bounds now but we weren't before, reset _driftFactor and log it _driftRatio = 1.0F ; } _driftMilliStamp = currentMillis ; _driftTimerStamp = currentTimer ; }
Calculates the drift factor from the time elapsed from the last calibrate call .