/** * Returns the duration in seconds between the time this class was loaded and now+{@code delayMillis} */ // package private for testing static int findRelativeSecond(long delayMillis) { long now = Clock.currentTimeMillis(); long d = (now + delayMillis - INITIAL_TIME_MILLIS); return ceilToSecond(d); }
/** * Returns the duration in seconds between the time this class was loaded and now+{@code delayMillis} */ // package private for testing static int findRelativeSecond(long delayMillis) { long now = Clock.currentTimeMillis(); long d = (now + delayMillis - INITIAL_TIME_MILLIS); return ceilToSecond(d); }
private boolean scheduleEntry(long delayMillis, K key, V value) { int delaySeconds = ceilToSecond(delayMillis); Integer newSecond = findRelativeSecond(delayMillis); synchronized (mutex) { long id = uniqueIdGenerator.incrementAndGet(); Object compositeKey = new CompositeKey(key, id); secondsOfKeys.put(compositeKey, newSecond); ScheduledEntry<K, V> scheduledEntry = new ScheduledEntry<K, V>(key, value, delayMillis, delaySeconds, id); doSchedule(compositeKey, scheduledEntry, newSecond); } return true; }
private boolean scheduleEntry(long delayMillis, K key, V value) { int delaySeconds = ceilToSecond(delayMillis); Integer newSecond = findRelativeSecond(delayMillis); synchronized (mutex) { long id = uniqueIdGenerator.incrementAndGet(); Object compositeKey = new CompositeKey(key, id); secondsOfKeys.put(compositeKey, newSecond); ScheduledEntry<K, V> scheduledEntry = new ScheduledEntry<K, V>(key, value, delayMillis, delaySeconds, id); doSchedule(compositeKey, scheduledEntry, newSecond); } return true; }
private boolean schedulePostponeEntry(long delayMillis, K key, V value) { int delaySeconds = ceilToSecond(delayMillis); Integer newSecond = findRelativeSecond(delayMillis); synchronized (mutex) { Integer existingSecond = secondsOfKeys.put(key, newSecond); if (existingSecond != null) { if (existingSecond.equals(newSecond)) { return false; } removeKeyFromSecond(key, existingSecond); } long id = uniqueIdGenerator.incrementAndGet(); ScheduledEntry<K, V> scheduledEntry = new ScheduledEntry<K, V>(key, value, delayMillis, delaySeconds, id); doSchedule(key, scheduledEntry, newSecond); } return true; }
private boolean schedulePostponeEntry(long delayMillis, K key, V value) { int delaySeconds = ceilToSecond(delayMillis); Integer newSecond = findRelativeSecond(delayMillis); synchronized (mutex) { Integer existingSecond = secondsOfKeys.put(key, newSecond); if (existingSecond != null) { if (existingSecond.equals(newSecond)) { return false; } removeKeyFromSecond(key, existingSecond); } long id = uniqueIdGenerator.incrementAndGet(); ScheduledEntry<K, V> scheduledEntry = new ScheduledEntry<K, V>(key, value, delayMillis, delaySeconds, id); doSchedule(key, scheduledEntry, newSecond); } return true; }