@Override public void accept(Partition<T, K, L> partition, T tuple) { if(!initialized_partitions.contains(partition)){ initialized_partitions.add(partition); ScheduledExecutorService ses = partition.getWindow().getScheduledExecutorService(); ses.schedule(() -> partition.evict(), time, unit); } } };
@Override public void accept(Partition<T, K, L> partition, T tuple) { if(!initialized_partitions.contains(partition)){ initialized_partitions.add(partition); ScheduledExecutorService ses = partition.getWindow().getScheduledExecutorService(); ses.schedule(() -> partition.evict(), time, unit); } } };
/** * A policy which schedules a future partition eviction if the partition is empty. * This can be used as a contents policy that is scheduling the eviction of * the tuple just about to be inserted. * @param <T> Tuple Type * @param <K> Key type * @param <L> List type for the partition contents. * @param time The time span in which tuple are permitted in the partition. * @param unit The units of time. * @return The time-based contents policy. */ public static <T, K, L extends List<T>> BiConsumer<Partition<T, K, L>, T> scheduleEvictIfEmpty(long time, TimeUnit unit){ return (partition, tuple) -> { if(partition.getContents().isEmpty()){ ScheduledExecutorService ses = partition.getWindow().getScheduledExecutorService(); ses.schedule(() -> partition.evict(), time, unit); } }; }
/** * A policy which schedules a future partition eviction if the partition is empty. * This can be used as a contents policy that is scheduling the eviction of * the tuple just about to be inserted. * @param <T> Tuple Type * @param <K> Key type * @param <L> List type for the partition contents. * @param time The time span in which tuple are permitted in the partition. * @param unit The units of time. * @return The time-based contents policy. */ public static <T, K, L extends List<T>> BiConsumer<Partition<T, K, L>, T> scheduleEvictIfEmpty(long time, TimeUnit unit){ return (partition, tuple) -> { if(partition.getContents().isEmpty()){ ScheduledExecutorService ses = partition.getWindow().getScheduledExecutorService(); ses.schedule(() -> partition.evict(), time, unit); } }; }
/** * An eviction policy which processes the window, evicts all tuples, and * schedules the next eviction after the 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, List<T>> > evictAllAndScheduleEvictWithProcess(long time, TimeUnit unit){ long timeMs = TimeUnit.MILLISECONDS.convert(time, unit); return (partition) -> { ScheduledExecutorService ses = partition.getWindow().getScheduledExecutorService(); List<T> tuples = partition.getContents(); partition.process(); tuples.clear(); ses.schedule(() -> partition.evict(), timeMs, TimeUnit.MILLISECONDS); }; }
/** * An eviction policy which processes the window, evicts all tuples, and * schedules the next eviction after the 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, List<T>> > evictAllAndScheduleEvictWithProcess(long time, TimeUnit unit){ long timeMs = TimeUnit.MILLISECONDS.convert(time, unit); return (partition) -> { ScheduledExecutorService ses = partition.getWindow().getScheduledExecutorService(); List<T> tuples = partition.getContents(); partition.process(); tuples.clear(); ses.schedule(() -> partition.evict(), 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); } }; }
/** * 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); } }; }
if(initialized.get(0).booleanValue() == false){ initialized.set(0, true); ScheduledExecutorService ses = partition.getWindow().getScheduledExecutorService(); ses.scheduleAtFixedRate(() -> {partition.process();}, 0, 1000, TimeUnit.MILLISECONDS); }},