// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.core;
import java.util.Objects;
import java.util.Queue;
/**
* @author Haavard Pettersen
* @author Simon Thoresen Hult
*/
class ScheduledQueue {
public static final int MILLIS_PER_SLOT = 100;
public static final int NUM_SLOTS = 512;
public static final int NUM_SLOTS_UNDILATED = 3;
public static final int SLOT_MASK = 511; // bitmask to modulo NUM_SLOTS
public static final int ITER_SHIFT = 9; // number of bits to shift off SLOT_MASK
private final Entry[] slots = new Entry[NUM_SLOTS + 1];
private final int[] counts = new int[NUM_SLOTS + 1];
private int currIter = 0;
private int currSlot = 0;
private long nextTick;
public ScheduledQueue(long currentTimeMillis) {
this.nextTick = currentTimeMillis + MILLIS_PER_SLOT;
}
public Entry newEntry(Object payload) {
Objects.requireNonNull(payload, "payload");
return new Entry(payload);
}
public synchronized void drainTo(long currentTimeMillis, Queue