protected long executeTimers ( ) { assert ( Thread . currentThread ( ) == worker ) ; changed = false ; // Fast track. if ( timers . isEmpty ( ) ) { return 0L ; } // Get the current time. long current = clock ( ) ; // Execute the timers that are already due. for ( Entry < TimerInfo , Long > entry : timers . entries ( ) ) { final TimerInfo timerInfo = entry . getKey ( ) ; if ( timerInfo . cancelled ) { timers . remove ( entry . getValue ( ) , timerInfo ) ; continue ; } // If we have to wait to execute the item, same will be true about // all the following items (multimap is sorted). Thus we can stop // checking the subsequent timers and return the time to wait for // the next timer (at least 1ms). final Long key = entry . getValue ( ) ; if ( key > current ) { return key - current ; } // Remove it from the list of active timers. timers . remove ( key , timerInfo ) ; // Trigger the timer. timerInfo . sink . timerEvent ( timerInfo . id ) ; } // Remove empty list object for ( Entry < TimerInfo , Long > entry : timers . entries ( ) ) { final Long key = entry . getValue ( ) ; if ( ! timers . hasValues ( key ) ) { timers . remove ( key ) ; } } if ( changed ) { return executeTimers ( ) ; } // There are no more timers. return 0L ; }
to wait to match the next timer or 0 meaning no timers .