protected void reschedule ( long minTimeoutAt ) { if ( minTimeoutAt == Long . MAX_VALUE ) { for ( PendingPromise pending : promises . values ( ) ) { if ( pending . timeoutAt > 0 && pending . timeoutAt < minTimeoutAt ) { minTimeoutAt = pending . timeoutAt ; } } long timeoutAt ; requestStreamReadLock . lock ( ) ; try { for ( IncomingStream stream : requestStreams . values ( ) ) { timeoutAt = stream . getTimeoutAt ( ) ; if ( timeoutAt > 0 && timeoutAt < minTimeoutAt ) { minTimeoutAt = timeoutAt ; } } } finally { requestStreamReadLock . unlock ( ) ; } responseStreamReadLock . lock ( ) ; try { for ( IncomingStream stream : responseStreams . values ( ) ) { timeoutAt = stream . getTimeoutAt ( ) ; if ( timeoutAt > 0 && timeoutAt < minTimeoutAt ) { minTimeoutAt = timeoutAt ; } } } finally { responseStreamReadLock . unlock ( ) ; } } long now = System . currentTimeMillis ( ) ; if ( minTimeoutAt == Long . MAX_VALUE ) { ScheduledFuture < ? > t = callTimeoutTimer . get ( ) ; if ( t != null ) { if ( prevTimeoutAt . get ( ) > now ) { t . cancel ( false ) ; prevTimeoutAt . set ( 0 ) ; } else { callTimeoutTimer . set ( null ) ; prevTimeoutAt . set ( 0 ) ; } } } else { minTimeoutAt = ( minTimeoutAt / 100 * 100 ) + 100 ; long prev = prevTimeoutAt . getAndSet ( minTimeoutAt ) ; if ( prev == minTimeoutAt ) { // Next when not changed return ; } // Stop previous timer ScheduledFuture < ? > t = callTimeoutTimer . get ( ) ; if ( t != null ) { t . cancel ( false ) ; } // Schedule next timeout timer long delay = Math . max ( 10 , minTimeoutAt - now ) ; callTimeoutTimer . set ( scheduler . schedule ( this :: checkTimeouts , delay , TimeUnit . MILLISECONDS ) ) ; } }
Recalculates the next timeout checking time .