/** * 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) -> { }); }
/** * 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) -> { }); }
/** * Return a window that maintains the last {@code count} tuples inserted * with processing triggered on every insert. This provides * a continuous processing, where processing is invoked every * time the window changes. Since insertion drives eviction * there is no need to process on eviction, thus once the window * has reached {@code count} tuples, each insertion results in an * eviction followed by processing of {@code count} tuples * including the tuple just inserted, which is the definition of * the window. * * @param <T> Tuple type. * @param <K> Key type. * * @param count Number of tuple to maintain per partition * @param keyFunction Tuple partitioning key function * @return window that maintains the last {@code count} tuples on a stream */ public static <T, K> Window<T, K, LinkedList<T>> lastNProcessOnInsert(final int count, Function<T, K> keyFunction) { Window<T, K, LinkedList<T>> window = Windows.window( alwaysInsert(), countContentsPolicy(count), evictOldest(), processOnInsert(), keyFunction, () -> new LinkedList<T>()); return window; }
/** * Return a window that maintains the last {@code count} tuples inserted * with processing triggered on every insert. This provides * a continuous processing, where processing is invoked every * time the window changes. Since insertion drives eviction * there is no need to process on eviction, thus once the window * has reached {@code count} tuples, each insertion results in an * eviction followed by processing of {@code count} tuples * including the tuple just inserted, which is the definition of * the window. * * @param <T> Tuple type. * @param <K> Key type. * * @param count Number of tuple to maintain per partition * @param keyFunction Tuple partitioning key function * @return window that maintains the last {@code count} tuples on a stream */ public static <T, K> Window<T, K, LinkedList<T>> lastNProcessOnInsert(final int count, Function<T, K> keyFunction) { Window<T, K, LinkedList<T>> window = Windows.window( alwaysInsert(), countContentsPolicy(count), evictOldest(), processOnInsert(), keyFunction, () -> new LinkedList<T>()); return window; }