use of org.apache.beam.sdk.coders.CoderException in project beam by apache.
the class ApexTimerInternals method fireReadyTimers.
/**
* Fire the timers that are ready. These are the timers
* that are registered to be triggered at a time before the current time.
* Timer processing may register new timers, which can cause the returned
* timestamp to be before the the current time. The caller may repeat
* the call until such backdated timers are cleared.
* @return minimum timestamp of registered timers.
*/
public long fireReadyTimers(long currentTime, TimerProcessor<K> timerProcessor, TimeDomain timeDomain) {
TimerSet timers = getTimerSet(timeDomain);
// move minTimestamp first,
// timer additions that result from firing may modify it
timers.minTimestamp = currentTime;
// we keep the timers to return in a different list and launch them later
// because we cannot prevent a trigger from registering another timer,
// which would lead to concurrent modification exception.
Multimap<Slice, TimerInternals.TimerData> toFire = HashMultimap.create();
Iterator<Map.Entry<Slice, Set<Slice>>> it = timers.activeTimers.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Slice, Set<Slice>> keyWithTimers = it.next();
Iterator<Slice> timerIt = keyWithTimers.getValue().iterator();
while (timerIt.hasNext()) {
try {
TimerData timerData = CoderUtils.decodeFromByteArray(timers.timerDataCoder, timerIt.next().buffer);
if (timerData.getTimestamp().isBefore(currentTime)) {
toFire.put(keyWithTimers.getKey(), timerData);
timerIt.remove();
}
} catch (CoderException e) {
throw new RuntimeException(e);
}
}
if (keyWithTimers.getValue().isEmpty()) {
it.remove();
}
}
// fire ready timers
if (!toFire.isEmpty()) {
for (Slice keyBytes : toFire.keySet()) {
try {
K key = CoderUtils.decodeFromByteArray(keyCoder, keyBytes.buffer);
timerProcessor.fireTimer(key, toFire.get(keyBytes));
} catch (CoderException e) {
throw new RuntimeException(e);
}
}
}
return timers.minTimestamp;
}
Aggregations