private boolean updateThrottle ( ) { // Derive new throttle state final ThrottleState newThrottle ; final boolean flapping = flapController . isFlapping ( ) ; if ( imageFailure != null ) { // Image failures take precedence newThrottle = imageFailure ; } else { newThrottle = flapping ? FLAPPING : NO ; } // If the throttle state changed, propagate it final boolean updated ; if ( ! Objects . equals ( throttle , newThrottle ) ) { log . info ( "throttle state change: {}: {} -> {}" , jobId , throttle , newThrottle ) ; throttle = newThrottle ; statusUpdater . setThrottleState ( throttle ) ; updated = true ; } else { updated = false ; } // If we're flapping, schedule a future check to potentially reset the flapping state if ( flapping ) { if ( flapTimeout != null ) { flapTimeout . cancel ( false ) ; } flapTimeout = scheduler . schedule ( new UpdateThrottle ( ) , flapController . millisLeftToUnflap ( ) , MILLISECONDS ) ; } // Let the caller know if they need to commit the state change return updated ; }
Derive a new throttle state and propagate it if needed . If flapping schedule a future check to see if we re still flapping and potentially reset the flapping state .