public static <T> Supplier<InsertionTimeList<T>> insertionTimeList() { return () -> new InsertionTimeList<>(); } }
void evictOlderThan(long evictTime) { while(!times.isEmpty() && times.getFirst() <= evictTime){ remove(); } }
/** * An eviction policy which evicts all tuples that are older than a specified time. * If any tuples remain in the partition, it schedules their eviction after * an appropriate interval. * @param <T> Tuple Type * @param <K> Key type * @param time The timespan in which tuple are permitted in the partition. * @param unit The units of time. * @return The time-based eviction policy. */ public static <T, K> Consumer<Partition<T, K, InsertionTimeList<T>> > evictOlderWithProcess(long time, TimeUnit unit){ long timeMs = TimeUnit.MILLISECONDS.convert(time, unit); return (partition) -> { ScheduledExecutorService ses = partition.getWindow().getScheduledExecutorService(); InsertionTimeList<T> tuples = partition.getContents(); long evictTime = System.currentTimeMillis() - timeMs; tuples.evictOlderThan(evictTime); partition.process(); if(!tuples.isEmpty()){ ses.schedule(() -> partition.evict(), tuples.nextEvictDelay(timeMs), TimeUnit.MILLISECONDS); } }; }
/** * An eviction policy which evicts all tuples that are older than a specified time. * If any tuples remain in the partition, it schedules their eviction after * an appropriate interval. * @param <T> Tuple Type * @param <K> Key type * @param time The timespan in which tuple are permitted in the partition. * @param unit The units of time. * @return The time-based eviction policy. */ public static <T, K> Consumer<Partition<T, K, InsertionTimeList<T>> > evictOlderWithProcess(long time, TimeUnit unit){ long timeMs = TimeUnit.MILLISECONDS.convert(time, unit); return (partition) -> { ScheduledExecutorService ses = partition.getWindow().getScheduledExecutorService(); InsertionTimeList<T> tuples = partition.getContents(); long evictTime = System.currentTimeMillis() - timeMs; tuples.evictOlderThan(evictTime); partition.process(); if(!tuples.isEmpty()){ ses.schedule(() -> partition.evict(), tuples.nextEvictDelay(timeMs), TimeUnit.MILLISECONDS); } }; }
public static <T> Supplier<InsertionTimeList<T>> insertionTimeList() { return () -> new InsertionTimeList<>(); } }
void evictOlderThan(long evictTime) { while(!times.isEmpty() && times.getFirst() <= evictTime){ remove(); } }
}}, unpartitioned(), () -> new InsertionTimeList<Long>());