public void onFire(W window, Timers timers, StateAccessor<?> state) throws Exception { // shouldFire should be false. // However it is too expensive to assert. FinishedTriggersBitSet finishedSet = readFinishedBits(state.access(FINISHED_BITS_TAG)).copy(); TriggerStateMachine.TriggerContext context = contextFactory.base(window, timers, rootTrigger, finishedSet); rootTrigger.invokeOnFire(context); persistFinishedSet(state, finishedSet); }
/** Run the trigger logic to deal with a new value. */ public void processValue(W window, Instant timestamp, Timers timers, StateAccessor<?> state) throws Exception { // Clone so that we can detect changes and so that changes here don't pollute merging. FinishedTriggersBitSet finishedSet = readFinishedBits(state.access(FINISHED_BITS_TAG)).copy(); TriggerStateMachine.OnElementContext triggerContext = contextFactory.createOnElementContext(window, timers, timestamp, rootTrigger, finishedSet); rootTrigger.invokeOnElement(triggerContext); persistFinishedSet(state, finishedSet); }
private void persistFinishedSet( StateAccessor<?> state, FinishedTriggersBitSet modifiedFinishedSet) { if (!isFinishedSetNeeded()) { return; } ValueState<BitSet> finishedSetState = state.access(FINISHED_BITS_TAG); if (!readFinishedBits(finishedSetState).equals(modifiedFinishedSet)) { if (modifiedFinishedSet.getBitSet().isEmpty()) { finishedSetState.clear(); } else { finishedSetState.write(modifiedFinishedSet.getBitSet()); } } }
/** Return true if the trigger is closed in the window corresponding to the specified state. */ public boolean isClosed(StateAccessor<?> state) { return readFinishedBits(state.access(FINISHED_BITS_TAG)).isFinished(rootTrigger); }
/** * Clear the state used for executing triggers, but leave the finished set to indicate the window * is closed. */ public void clearState(W window, Timers timers, StateAccessor<?> state) throws Exception { // Don't need to clone, because we'll be clearing the finished bits anyways. FinishedTriggers finishedSet = readFinishedBits(state.access(FINISHED_BITS_TAG)); rootTrigger.invokeClear(contextFactory.base(window, timers, rootTrigger, finishedSet)); }
/** Clear the finished bits. */ public void clearFinished(StateAccessor<?> state) { clearFinishedBits(state.access(FINISHED_BITS_TAG)); }
public boolean shouldFire(W window, Timers timers, StateAccessor<?> state) throws Exception { FinishedTriggers finishedSet = readFinishedBits(state.access(FINISHED_BITS_TAG)).copy(); TriggerStateMachine.TriggerContext context = contextFactory.base(window, timers, rootTrigger, finishedSet); return rootTrigger.invokeShouldFire(context); }
public void prefetchIsClosed(StateAccessor<?> state) { if (isFinishedSetNeeded()) { state.access(FINISHED_BITS_TAG).readLater(); } }