private Set<W> windowsThatAreOpen(Collection<W> windows) { Set<W> result = new HashSet<>(); for (W window : windows) { ReduceFn<K, InputT, OutputT, W>.Context directContext = contextFactory.base(window, StateStyle.DIRECT); if (!triggerRunner.isClosed(directContext.state())) { result.add(window); } } return result; }
private Collection<W> windowsThatShouldFire(Set<W> windows) throws Exception { Collection<W> result = new ArrayList<>(); // Filter out timers that didn't trigger. for (W window : windows) { ReduceFn<K, InputT, OutputT, W>.Context directContext = contextFactory.base(window, StateStyle.DIRECT); if (triggerRunner.shouldFire( directContext.window(), directContext.timers(), directContext.state())) { result.add(window); } } return result; }
/** Return the current data hold, or null if none. Does not clear. For debugging only. */ @Nullable public Instant getDataCurrent(ReduceFn<?, ?, ?, W>.Context context) { return context.state().access(elementHoldTag).read(); } }
mergedWindow, contextFactory.base(mergedWindow, StateStyle.DIRECT).state());
@Nullable Instant newHold = pair.newHold; final boolean isEmpty = nonEmptyPanes.isEmpty(renamedContext.state()).read(); if (isEmpty && windowingStrategy.getClosingBehavior() == ClosingBehavior.FIRE_IF_NON_EMPTY
timerInternals.currentInputWatermarkTime(), timerInternals.currentOutputWatermarkTime()); final WatermarkHoldState elementHoldState = context.state().access(elementHoldTag); final WatermarkHoldState extraHoldState = context.state().access(EXTRA_HOLD_TAG); return new ReadableState<OldAndNewHolds>() { @Override
gcHold); context.state().access(EXTRA_HOLD_TAG).add(gcHold);
"Element hold %s is beyond end-of-time", elementHold); context.state().access(elementHoldTag).add(elementHold);
checkState( triggerRunner.shouldFire( directContext.window(), directContext.timers(), directContext.state())); triggerRunner.onFire(directContext.window(), directContext.timers(), directContext.state()); boolean isFinished = triggerRunner.isClosed(directContext.state()); nonEmptyPanes.clearPane(renamedContext.state()); directContext.window(), directContext.timers(), directContext.state()); paneInfoTracker.clear(directContext.state()); activeWindows.remove(directContext.window());
/** * Return a ({@link ReadableState} for) the pane info appropriate for {@code context}. The pane * info includes the timing for the pane, who's calculation is quite subtle. * * @param isFinal should be {@code true} only if the triggering machinery can guarantee no further * firings for the */ public ReadableState<PaneInfo> getNextPaneInfo( ReduceFn<?, ?, ?, ?>.Context context, final boolean isFinal) { final Object key = context.key(); final ReadableState<PaneInfo> previousPaneFuture = context.state().access(PaneInfoTracker.PANE_INFO_TAG); final Instant windowMaxTimestamp = context.window().maxTimestamp(); return new ReadableState<PaneInfo>() { @Override public ReadableState<PaneInfo> readLater() { previousPaneFuture.readLater(); return this; } @Override public PaneInfo read() { PaneInfo previousPane = previousPaneFuture.read(); return describePane(key, windowMaxTimestamp, previousPane, isFinal); } }; }
@Override public void clearState(Context c) throws Exception { c.state().access(bufferTag).clear(); }
public void prefetchPaneInfo(ReduceFn<?, ?, ?, ?>.Context context) { context.state().access(PaneInfoTracker.PANE_INFO_TAG).readLater(); }
public void storeCurrentPaneInfo(ReduceFn<?, ?, ?, ?>.Context context, PaneInfo currentPane) { context.state().access(PANE_INFO_TAG).write(currentPane); }
@VisibleForTesting boolean isFinished(W window) { return triggerRunner.isClosed(contextFactory.base(window, StateStyle.DIRECT).state()); }
private void prefetchEmit( ReduceFn<K, InputT, OutputT, W>.Context directContext, ReduceFn<K, InputT, OutputT, W>.Context renamedContext) { triggerRunner.prefetchShouldFire(directContext.window(), directContext.state()); triggerRunner.prefetchOnFire(directContext.window(), directContext.state()); triggerRunner.prefetchIsClosed(directContext.state()); prefetchOnTrigger(directContext, renamedContext); }
private void prefetchOnTrigger( final ReduceFn<K, InputT, OutputT, W>.Context directContext, ReduceFn<K, InputT, OutputT, W>.Context renamedContext) { paneInfoTracker.prefetchPaneInfo(directContext); watermarkHold.prefetchExtract(renamedContext); nonEmptyPanes.isEmpty(renamedContext.state()).readLater(); reduceFn.prefetchOnTrigger(directContext.state()); }
/** Clear any remaining holds. */ public void clearHolds(ReduceFn<?, ?, ?, W>.Context context) { WindowTracing.debug( "WatermarkHold.clearHolds: For key:{}; window:{}; inputWatermark:{}; outputWatermark:{}", context.key(), context.window(), timerInternals.currentInputWatermarkTime(), timerInternals.currentOutputWatermarkTime()); context.state().access(elementHoldTag).clear(); context.state().access(EXTRA_HOLD_TAG).clear(); }
private void prefetchWindowsForValues(Collection<W> windows) { // Prefetch in each of the windows if we're going to need to process triggers for (W window : windows) { ReduceFn<K, InputT, OutputT, W>.Context directContext = contextFactory.base(window, StateStyle.DIRECT); triggerRunner.prefetchForValue(window, directContext.state()); } }