@Override public void track(Event<T> event) { if (started && event.isWatermark()) { handleWaterMarkEvent(event); } }
/** * Triggers all the pending windows up to the waterMarkEvent timestamp based on the sliding interval count. * * @param waterMarkEvent the watermark event */ private void handleWaterMarkEvent(Event<T> waterMarkEvent) { long watermarkTs = waterMarkEvent.getTimestamp(); List<Long> eventTs = windowManager.getSlidingCountTimestamps(lastProcessedTs, watermarkTs, count); for (long ts : eventTs) { evictionPolicy.setContext(new DefaultEvictionContext(ts, null, Long.valueOf(count))); handler.onTrigger(); lastProcessedTs = ts; } }
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); } } }
@Override public void track(Event<T> event) { if (started && !event.isWatermark()) { if (currentCount.incrementAndGet() >= count) { evictionPolicy.setContext(new DefaultEvictionContext(System.currentTimeMillis())); handler.onTrigger(); } } }
@Override public void run() { try { long waterMarkTs = computeWaterMarkTs(); if (waterMarkTs > lastWaterMarkTs) { this.windowManager.add(new WaterMarkEvent<>(waterMarkTs)); lastWaterMarkTs = waterMarkTs; } } catch (Throwable th) { LOG.error("Failed while processing watermark event ", th); throw th; } }
@Override public void track(Event<T> event) { if (started && event.isWatermark()) { handleWaterMarkEvent(event); } }
@Test public void testExpireThresholdWithWatermarkCountEvictionPolicy() throws Exception { int windowLength = WindowManager.EXPIRE_EVENTS_THRESHOLD; EvictionPolicy watermarkCountEvictionPolicy = new WatermarkCountEvictionPolicy(windowLength); testEvictBeforeWatermarkForWatermarkEvictionPolicy(watermarkCountEvictionPolicy, windowLength); }
@Test public void testExpireThresholdWithWatermarkTimeEvictionPolicy() throws Exception { int windowLength = WindowManager.EXPIRE_EVENTS_THRESHOLD; EvictionPolicy watermarkTimeEvictionPolicy = new WatermarkTimeEvictionPolicy(windowLength); testEvictBeforeWatermarkForWatermarkEvictionPolicy(watermarkTimeEvictionPolicy, windowLength); }
@Before public void setUp() { listener = new Listener(); windowManager = new WindowManager<>(listener); }
private void postInitialize() { // start trigger once the initialization is done. triggerPolicy.start(); }
@Override public void track(Event<T> event) { checkFailures(); }
@Override public String toString() { return "WatermarkTimeEvictionPolicy{" + "lag=" + lag + "} " + super.toString(); }
@Override public String toString() { return "WaterMarkEvent{} " + super.toString(); } }
@Override public void onExpiry(List<Tuple> events) { parentListener.onExpiry(events); }
@Override public void reset() { checkFailures(); }