/** * Returns an {@code EvictionPolicy} instance which evicts elements after window duration is reached. * * @return */ @Override public EvictionPolicy<T, ?> getEvictionPolicy() { return new TimeEvictionPolicy<>(windowConfig.getWindowLength()); } }
/** * {@inheritDoc} * <p/> * Keeps events with future ts in the queue for processing in the next window. If the ts difference is more than the lag, stops scanning * the queue for the current window. */ @Override public Action evict(Event<T> event) { if (evictionContext == null) { //It is possible to get asked about eviction before we have a context, due to WindowManager.compactWindow. //In this case we should hold on to all the events. When the first watermark is received, the context will be set, //and the events will be reevaluated for eviction return Action.STOP; } long referenceTime = evictionContext.getReferenceTime(); long diff = referenceTime - event.getTimestamp(); if (diff < -lag) { return Action.STOP; } else if (diff < 0) { return Action.KEEP; } else { return super.evict(event); } }
@Override public String toString() { return "WatermarkTimeEvictionPolicy{" + "lag=" + lag + "} " + super.toString(); }
/** * Returns an {@code EvictionPolicy} instance which evicts elements after given window duration. * * @return */ @Override public EvictionPolicy<T, ?> getEvictionPolicy() { return new TimeEvictionPolicy<>(windowConfig.getWindowLength()); } }
@Override public String toString() { return "WatermarkTimeEvictionPolicy{" + "lag=" + lag + "} " + super.toString(); } }
/** * {@inheritDoc} * <p/> * Keeps events with future ts in the queue for processing in the next * window. If the ts difference is more than the lag, stops scanning * the queue for the current window. */ @Override public Action evict(Event<T> event) { if(evictionContext == null) { //It is possible to get asked about eviction before we have a context, due to WindowManager.compactWindow. //In this case we should hold on to all the events. When the first watermark is received, the context will be set, //and the events will be reevaluated for eviction return Action.STOP; } long referenceTime = evictionContext.getReferenceTime(); long diff = referenceTime - event.getTimestamp(); if (diff < -lag) { return Action.STOP; } else if (diff < 0) { return Action.KEEP; } else { return super.evict(event); } }
private EvictionPolicy<Tuple, ?> getEvictionPolicy(Count windowLengthCount, Duration windowLengthDuration) { if (windowLengthCount != null) { if (isTupleTs()) { return new WatermarkCountEvictionPolicy<>(windowLengthCount.value); } else { return new CountEvictionPolicy<>(windowLengthCount.value); } } else { if (isTupleTs()) { return new WatermarkTimeEvictionPolicy<>(windowLengthDuration.value, maxLagMs); } else { return new TimeEvictionPolicy<>(windowLengthDuration.value); } } }
@Test public void testTimeBasedWindowExpiry() throws Exception { EvictionPolicy<Integer, ?> evictionPolicy = new TimeEvictionPolicy<Integer>(new Duration(100, TimeUnit.MILLISECONDS).value); windowManager.setEvictionPolicy(evictionPolicy);
@Test public void testTimeBasedWindow() throws Exception { EvictionPolicy<Integer, ?> evictionPolicy = new TimeEvictionPolicy<Integer>(new Duration(1, TimeUnit.SECONDS).value); windowManager.setEvictionPolicy(evictionPolicy);
/** * Returns an {@code EvictionPolicy} instance which evicts elements after given window duration. * * @return */ @Override public EvictionPolicy<T> getEvictionPolicy() { return new TimeEvictionPolicy<>(windowConfig.getWindowLength()); } }
/** * Returns an {@code EvictionPolicy} instance which evicts elements after window duration is reached. * * @return */ @Override public EvictionPolicy<T> getEvictionPolicy() { return new TimeEvictionPolicy<>(windowConfig.getWindowLength()); } }
private EvictionPolicy<Tuple> getEvictionPolicy(Count windowLengthCount, Duration windowLengthDuration) { if (windowLengthCount != null) { if (isTupleTs()) { return new WatermarkCountEvictionPolicy<>(windowLengthCount.value); } else { return new CountEvictionPolicy<>(windowLengthCount.value); } } else { if (isTupleTs()) { return new WatermarkTimeEvictionPolicy<>(windowLengthDuration.value, maxLagMs); } else { return new TimeEvictionPolicy<>(windowLengthDuration.value); } } }