/** * Returns a trigger policy that triggers * processing on every insert. * @param <T> Tuple type * @param <K> Key type * @param <L> List type for the partition contents. * @return A trigger policy that triggers processing on every insert. */ public static <T, K, L extends List<T>> BiConsumer<Partition<T, K, L>, T> processOnInsert(){ return (partition, tuple) -> partition.process(); }
@Override public void accept(T tuple) { window.insert(tuple); }
public static <T> Supplier<InsertionTimeList<T>> insertionTimeList() { return () -> new InsertionTimeList<>(); } }
/** * Pressure reliever that maintains up to {@code count} most recent tuples per key. * * @param count Number of tuples to maintain where downstream processing cannot keep up. * @param keyFunction Key function for tuples. */ public PressureReliever(int count, Function<T, K> keyFunction) { window = Windows.window( Policies.alwaysInsert(), Policies.countContentsPolicy(count), Policies.evictOldest(), new FirstSubmitter(), keyFunction, () -> new LinkedList<T>()); // No processing of the window takes place window.registerPartitionProcessor((tuples, k) -> { }); }
@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); } } };
/** * Returns a Consumer representing an evict determiner that evict all tuples * from the window. * @param <T> Tuple type * @param <K> Key type * @param <L> List type for the partition contents. * @return An evict determiner that evicts all tuples. */ public static <T, K, L extends List<T>> Consumer<Partition<T, K, L> > evictAll(){ return partition -> partition.getContents().clear(); }
@Override public synchronized boolean insert(T tuple) { if (getWindow().getInsertionPolicy().apply(this, tuple)) { getWindow().getContentsPolicy().accept(this, tuple); this.tuples.add(tuple); // Trigger getWindow().getTriggerPolicy().accept(this, tuple); return true; } return true; }
@Override public S removeState(String key) { return super.removeState(key); } @Override
@Override public S setState(String key, S state) { return super.setState(key, state); } }
@Override public S getState(String key) { return super.getState(key); } @Override
@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); } } };
/** * Returns an evict determiner that evicts the oldest tuple. * @param <T> Tuple type * @param <K> Key type * @param <L> List type for the partition contents. * @return A evict determiner that evicts the oldest tuple. */ public static <T, K, L extends List<T>> Consumer<Partition<T, K, L> > evictOldest(){ return partition -> partition.getContents().remove(0); }
@Override public void accept(T tuple) { window.insert(tuple); }
/** * Returns a trigger policy that triggers * processing on every insert. * @param <T> Tuple type * @param <K> Key type * @param <L> List type for the partition contents. * @return A trigger policy that triggers processing on every insert. */ public static <T, K, L extends List<T>> BiConsumer<Partition<T, K, L>, T> processOnInsert(){ return (partition, tuple) -> partition.process(); }
public static <T> Supplier<InsertionTimeList<T>> insertionTimeList() { return () -> new InsertionTimeList<>(); } }
/** * Returns a Consumer representing an evict determiner that evict all tuples * from the window. * @param <T> Tuple type * @param <K> Key type * @param <L> List type for the partition contents. * @return An evict determiner that evicts all tuples. */ public static <T, K, L extends List<T>> Consumer<Partition<T, K, L> > evictAll(){ return partition -> partition.getContents().clear(); }
@Override public void accept(T tuple) { window.insert(tuple); }
/** * Returns an evict determiner that evicts the oldest tuple. * @param <T> Tuple type * @param <K> Key type * @param <L> List type for the partition contents. * @return A evict determiner that evicts the oldest tuple. */ public static <T, K, L extends List<T>> Consumer<Partition<T, K, L> > evictOldest(){ return partition -> partition.getContents().remove(0); }
@Override public void accept(T tuple) { window.insert(tuple); }
@Override public void run() { if(count.get() < MAX_TUP_CNT){ window.insert(count.incrementAndGet()); } }