blueflood-core/src/main/java/com/rackspacecloud/blueflood/service/ScheduleContext.java
@VisibleForTesting
    SlotKey getNextScheduled() {
        synchronized (scheduledSlots) {
            if (scheduledSlots.size() == 0)
                return null;
            synchronized (runningSlots) {
                SlotKey key = orderedScheduledSlots.remove(0);
                int slot = key.getSlot();
                Granularity gran = key.getGranularity();
                int shard = key.getShard();

                // notice how we change the state, but the timestamp remained
                // the same. this is important.  When the state is evaluated
                // (i.e., in Reader.getShardState()) we need to realize that
                // when timestamps are the same (this will happen), that a
                // remove always wins during the coalesce.
                scheduledSlots.remove(key);

                if (canWorkOnShard(shard)) {
                    UpdateStamp stamp = shardStateManager.getSlotStateManager(shard, gran).getAndSetState(slot, UpdateStamp.State.Running);
                    runningSlots.put(key, stamp.getTimestamp());
                    return key;
                } else {
                    shardOwnershipChanged.mark();
                    return null;
                }
            }
        }
    }
@VisibleForTesting
    SlotKey getNextScheduled() {
        synchronized (scheduledSlots) {
            if (scheduledSlots.size() == 0)
                return null;
            synchronized (runningSlots) {
                SlotKey key = orderedScheduledSlots.remove(0);
                int slot = key.getSlot();
                Granularity gran = key.getGranularity();
                int shard = key.getShard();

                // notice how we change the state, but the timestamp remained
                // the same. this is important.  When the state is evaluated
                // (i.e., in Reader.getShardState()) we need to realize that
                // when timestamps are the same (this will happen), that a
                // remove always wins during the coalesce.
                scheduledSlots.remove(key);

                if (canWorkOnShard(shard)) {
                    UpdateStamp stamp = shardStateManager.getSlotStateManager(shard, gran).getAndSetState(slot, UpdateStamp.State.Running);
                    runningSlots.put(key, stamp.getTimestamp());
                    return key;
                } else {
                    shardOwnershipChanged.mark();
                    return null;
                }
            }
        }
    }
@ VisibleForTesting SlotKey getNextScheduled ( ) { synchronized ( scheduledSlots ) { if ( scheduledSlots . size ( ) == 0 ) return null ; synchronized ( runningSlots ) { SlotKey key = orderedScheduledSlots . remove ( 0 ) ; int slot = key . getSlot ( ) ; Granularity gran = key . getGranularity ( ) ; int shard = key . getShard ( ) ; // notice how we change the state, but the timestamp remained // the same. this is important.  When the state is evaluated // (i.e., in Reader.getShardState()) we need to realize that // when timestamps are the same (this will happen), that a // remove always wins during the coalesce. scheduledSlots . remove ( key ) ; if ( canWorkOnShard ( shard ) ) { UpdateStamp stamp = shardStateManager . getSlotStateManager ( shard , gran ) . getAndSetState ( slot , UpdateStamp . State . Running ) ; runningSlots . put ( key , stamp . getTimestamp ( ) ) ; return key ; } else { shardOwnershipChanged . mark ( ) ; return null ; } } } }
Returns the next scheduled key. It has a few side effects:
1) it resets update tracking for that slot
2) it adds the key to the set of running rollups.

@return
Returns the next scheduled key . It has a few side effects : 1 ) it resets update tracking for that slot 2 ) it adds the key to the set of running rollups .