use of org.apache.beam.runners.core.StateNamespaces.WindowNamespace in project beam by apache.
the class SimpleParDoFn method processSystemTimer.
private void processSystemTimer(TimerData timer) throws Exception {
// Timer owned by this class, for cleaning up state in expired windows
if (timer.getTimerId().equals(CLEANUP_TIMER_ID)) {
checkState(timer.getDomain().equals(TimeDomain.EVENT_TIME), "%s received cleanup timer with domain not EVENT_TIME: %s", this, timer);
checkState(timer.getNamespace() instanceof WindowNamespace, "%s received cleanup timer not for a %s: %s", this, WindowNamespace.class.getSimpleName(), timer);
BoundedWindow window = ((WindowNamespace) timer.getNamespace()).getWindow();
Instant targetTime = earliestAllowableCleanupTime(window, fnInfo.getWindowingStrategy());
checkState(!targetTime.isAfter(timer.getTimestamp()), "%s received state cleanup timer for window %s " + " that is before the appropriate cleanup time %s", this, window, targetTime);
fnRunner.onWindowExpiration(window, timer.getOutputTimestamp(), this.stepContext.stateInternals().getKey());
// This is for a timer for a window that is expired, so clean it up.
for (StateDeclaration stateDecl : fnSignature.stateDeclarations().values()) {
StateTag<?> tag;
try {
tag = StateTags.tagForSpec(stateDecl.id(), (StateSpec) stateDecl.field().get(fnInfo.getDoFn()));
} catch (IllegalAccessException e) {
throw new RuntimeException(String.format("Error accessing %s for %s", StateSpec.class.getName(), fnInfo.getDoFn().getClass().getName()), e);
}
StateInternals stateInternals = userStepContext.stateInternals();
org.apache.beam.sdk.state.State state = stateInternals.state(timer.getNamespace(), tag);
state.clear();
}
}
}
Aggregations