final PriorityQueue<ComputationState> newPartialMatches = new PriorityQueue<>(NFAState.COMPUTATION_STATE_COMPARATOR); for (ComputationState computationState : nfaState.getPartialMatches()) { if (isStateTimedOut(computationState, timestamp)) { nfaState.setStateChanged(); } else { newPartialMatches.add(computationState); nfaState.setNewPartialMatches(newPartialMatches);
private void updateNFA(NFAState nfaState) throws IOException { if (nfaState.isStateChanged()) { nfaState.resetStateChanged(); computationStates.update(nfaState); } }
public NFAState createInitialNFAState() { Queue<ComputationState> startingStates = new LinkedList<>(); for (State<T> state : states.values()) { if (state.isStart()) { startingStates.add(ComputationState.createStartState(state.getName())); } } return new NFAState(startingStates); }
@Override public void serialize(NFAState record, DataOutputView target) throws IOException { serializeComputationStates(record.getPartialMatches(), target); serializeComputationStates(record.getCompletedMatches(), target); }
List<Map<String, List<T>>> result) throws Exception { nfaState.getCompletedMatches().addAll(potentialMatches); ComputationState earliestMatch = nfaState.getCompletedMatches().peek(); isEarlier(earliestMatch, earliestPartialMatch))) { nfaState.setStateChanged(); nfaState.getCompletedMatches().poll(); List<Map<String, List<EventId>>> matchedResult = sharedBufferAccessor.extractPatterns(earliestMatch.getPreviousBufferEntry(), earliestMatch.getVersion()); nfaState.getCompletedMatches(), matchedResult, sharedBufferAccessor); earliestMatch = nfaState.getCompletedMatches().peek(); nfaState.getPartialMatches().removeIf(pm -> pm.getStartEventID() != null && !partialMatches.contains(pm));
)); assertEquals(1, nfaState.getPartialMatches().size()); assertEquals("start", nfaState.getPartialMatches().peek().getCurrentStateName());
)); assertEquals(1, nfaState.getPartialMatches().size()); assertEquals("start", nfaState.getPartialMatches().peek().getCurrentStateName());
List<Map<String, List<T>>> result) throws Exception { nfaState.getCompletedMatches().addAll(potentialMatches); ComputationState earliestMatch = nfaState.getCompletedMatches().peek(); isEarlier(earliestMatch, earliestPartialMatch))) { nfaState.setStateChanged(); nfaState.getCompletedMatches().poll(); List<Map<String, List<EventId>>> matchedResult = sharedBufferAccessor.extractPatterns(earliestMatch.getPreviousBufferEntry(), earliestMatch.getVersion()); nfaState.getCompletedMatches(), matchedResult, sharedBufferAccessor); earliestMatch = nfaState.getCompletedMatches().peek(); nfaState.getPartialMatches().removeIf(pm -> pm.getStartEventID() != null && !partialMatches.contains(pm));
@Override public void serialize(NFAState record, DataOutputView target) throws IOException { serializeComputationStates(record.getPartialMatches(), target); serializeComputationStates(record.getCompletedMatches(), target); }
for (ComputationState computationState : nfaState.getPartialMatches()) { final Collection<ComputationState> newComputationStates = computeNextStates( sharedBufferAccessor, nfaState.setStateChanged(); } else if (!newComputationStates.iterator().next().equals(computationState)) { nfaState.setStateChanged(); nfaState.setStateChanged(); nfaState.setNewPartialMatches(newPartialMatches);
@Test public void testNFAChangedOnTimeoutWithoutPrune() throws Exception { Pattern<Event, ?> pattern = Pattern.<Event>begin("start").where(new IterativeCondition<Event>() { @Override public boolean filter(Event value, Context<Event> ctx) throws Exception { return value.getName().equals("start"); } }).followedBy("end").where(new IterativeCondition<Event>() { private static final long serialVersionUID = 8061969839441121955L; @Override public boolean filter(Event value, Context<Event> ctx) throws Exception { return value.getName().equals("end"); } }).within(Time.milliseconds(10)); NFA<Event> nfa = compile(pattern, true); NFAState nfaState = nfa.createInitialNFAState(); nfaState.resetStateChanged(); nfa.advanceTime(sharedBufferAccessor, nfaState, 6L); nfa.process(sharedBufferAccessor, nfaState, new Event(6, "start", 1.0), 6L, skipStrategy, timerService); nfaState.resetStateChanged(); nfa.advanceTime(sharedBufferAccessor, nfaState, 17L); assertTrue(nfaState.isStateChanged()); } }
Lists.newArrayList(startEvent, middleEvent1, breaking) )); assertEquals(1, nfaState.getPartialMatches().size()); assertEquals("start", nfaState.getPartialMatches().peek().getCurrentStateName());
List<Map<String, List<T>>> result) throws Exception { nfaState.getCompletedMatches().addAll(potentialMatches); ComputationState earliestMatch = nfaState.getCompletedMatches().peek(); isEarlier(earliestMatch, earliestPartialMatch))) { nfaState.setStateChanged(); nfaState.getCompletedMatches().poll(); List<Map<String, List<EventId>>> matchedResult = sharedBufferAccessor.extractPatterns(earliestMatch.getPreviousBufferEntry(), earliestMatch.getVersion()); nfaState.getCompletedMatches(), matchedResult, sharedBufferAccessor); earliestMatch = nfaState.getCompletedMatches().peek(); nfaState.getPartialMatches().removeIf(pm -> pm.getStartEventID() != null && !partialMatches.contains(pm));
@Override public void serialize(NFAState record, DataOutputView target) throws IOException { serializeComputationStates(record.getPartialMatches(), target); serializeComputationStates(record.getCompletedMatches(), target); }
@Override public NFAState deserialize(DataInputView source) throws IOException { PriorityQueue<ComputationState> partialMatches = deserializeComputationStates(source); PriorityQueue<ComputationState> completedMatches = deserializeComputationStates(source); return new NFAState(partialMatches, completedMatches); }
final PriorityQueue<ComputationState> newPartialMatches = new PriorityQueue<>(NFAState.COMPUTATION_STATE_COMPARATOR); for (ComputationState computationState : nfaState.getPartialMatches()) { if (isStateTimedOut(computationState, timestamp)) { nfaState.setStateChanged(); } else { newPartialMatches.add(computationState); nfaState.setNewPartialMatches(newPartialMatches);
assertFalse("NFA status should not change as the event does not match the take condition of the 'start' state", nfaState.isStateChanged()); nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(2, "a", 1.0), 2L, skipStrategy, timerService); assertTrue("NFA status should change as the event matches the take condition of the 'start' state", nfaState.isStateChanged()); nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(3, "f", 1.0), 3L, skipStrategy, timerService); assertTrue("NFA status should change as the event matches the ignore condition and proceed condition of the 'middle:1' state", nfaState.isStateChanged()); nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(4, "f", 1.0), 4L, skipStrategy, timerService); assertFalse("NFA status should not change as the event only matches the ignore condition of the 'middle:2' state and the target state is still 'middle:2'", nfaState.isStateChanged()); nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(5, "b", 1.0), 5L, skipStrategy, timerService); assertTrue("NFA status should change as the event matches the take condition of 'middle:2' state", nfaState.isStateChanged()); nfaState.resetStateChanged(); nfa.process(sharedBufferAccessor, nfaState, new Event(6, "d", 1.0), 6L, skipStrategy, timerService); assertTrue("NFA status should change as the event matches the take condition of 'middle2' state", nfaState.isStateChanged()); nfaState.resetStateChanged(); nfa.advanceTime(sharedBufferAccessor, nfaState, 8L); assertFalse("NFA status should not change as the timestamp is within the window", nfaState.isStateChanged()); nfaState.resetStateChanged(); Collection<Tuple2<Map<String, List<Event>>, Long>> timeoutResults = nfa.advanceTime(sharedBufferAccessor, nfaState, 12L); assertTrue("NFA status should change as timeout happens", nfaState.isStateChanged() && !timeoutResults.isEmpty());
)); assertEquals(1, nfaState.getPartialMatches().size()); assertEquals("start", nfaState.getPartialMatches().peek().getCurrentStateName());
@Override public void process(Object key, ValueState<MigratedNFA<IN>> state) throws Exception { MigratedNFA<IN> oldState = state.value(); computationStates.update(new NFAState(oldState.getComputationStates())); org.apache.flink.cep.nfa.SharedBuffer<IN> sharedBuffer = oldState.getSharedBuffer(); partialMatches.init(sharedBuffer.getEventsBuffer(), sharedBuffer.getPages()); state.clear(); } }
final PriorityQueue<ComputationState> newPartialMatches = new PriorityQueue<>(NFAState.COMPUTATION_STATE_COMPARATOR); for (ComputationState computationState : nfaState.getPartialMatches()) { if (isStateTimedOut(computationState, timestamp)) { nfaState.setStateChanged(); } else { newPartialMatches.add(computationState); nfaState.setNewPartialMatches(newPartialMatches);