void scheduleEligibleSlots ( long maxAgeMillis , long rollupDelayForMetricsWithShortDelay , long rollupWaitForMetricsWithLongDelay ) { long now = scheduleTime ; ArrayList < Integer > shardKeys = new ArrayList < Integer > ( shardStateManager . getManagedShards ( ) ) ; Collections . shuffle ( shardKeys ) ; for ( int shard : shardKeys ) { for ( Granularity g : Granularity . rollupGranularities ( ) ) { // sync on map since we do not want anything added to or taken from it while we iterate. synchronized ( scheduledSlots ) { // read synchronized ( runningSlots ) { // read List < Integer > slotsToWorkOn = shardStateManager . getSlotStateManager ( shard , g ) . getSlotsEligibleForRollup ( now , maxAgeMillis , rollupDelayForMetricsWithShortDelay , rollupWaitForMetricsWithLongDelay ) ; if ( slotsToWorkOn . size ( ) == 0 ) { continue ; } if ( ! canWorkOnShard ( shard ) ) { continue ; } for ( Integer slot : slotsToWorkOn ) { SlotKey slotKey = SlotKey . of ( g , slot , shard ) ; if ( areChildKeysOrSelfKeyScheduledOrRunning ( slotKey ) ) { continue ; } SlotKey key = SlotKey . of ( g , slot , shard ) ; scheduledSlots . add ( key ) ; orderedScheduledSlots . add ( key ) ; recentlyScheduledShards . put ( shard , scheduleTime ) ; } } } } } }
only one thread should be calling in this puppy .