Java Code Examples for org.apache.flink.cep.nfa.aftermatch.AfterMatchSkipStrategy#isSkipStrategy()
The following examples show how to use
org.apache.flink.cep.nfa.aftermatch.AfterMatchSkipStrategy#isSkipStrategy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NFA.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
private Collection<Map<String, List<T>>> doProcess( final SharedBufferAccessor<T> sharedBufferAccessor, final NFAState nfaState, final EventWrapper event, final AfterMatchSkipStrategy afterMatchSkipStrategy, final TimerService timerService) throws Exception { final PriorityQueue<ComputationState> newPartialMatches = new PriorityQueue<>(NFAState.COMPUTATION_STATE_COMPARATOR); final PriorityQueue<ComputationState> potentialMatches = new PriorityQueue<>(NFAState.COMPUTATION_STATE_COMPARATOR); // iterate over all current computations for (ComputationState computationState : nfaState.getPartialMatches()) { final Collection<ComputationState> newComputationStates = computeNextStates( sharedBufferAccessor, computationState, event, timerService); if (newComputationStates.size() != 1) { nfaState.setStateChanged(); } else if (!newComputationStates.iterator().next().equals(computationState)) { nfaState.setStateChanged(); } //delay adding new computation states in case a stop state is reached and we discard the path. final Collection<ComputationState> statesToRetain = new ArrayList<>(); //if stop state reached in this path boolean shouldDiscardPath = false; for (final ComputationState newComputationState : newComputationStates) { if (isFinalState(newComputationState)) { potentialMatches.add(newComputationState); } else if (isStopState(newComputationState)) { //reached stop state. release entry for the stop state shouldDiscardPath = true; sharedBufferAccessor.releaseNode(newComputationState.getPreviousBufferEntry()); } else { // add new computation state; it will be processed once the next event arrives statesToRetain.add(newComputationState); } } if (shouldDiscardPath) { // a stop state was reached in this branch. release branch which results in removing previous event from // the buffer for (final ComputationState state : statesToRetain) { sharedBufferAccessor.releaseNode(state.getPreviousBufferEntry()); } } else { newPartialMatches.addAll(statesToRetain); } } if (!potentialMatches.isEmpty()) { nfaState.setStateChanged(); } List<Map<String, List<T>>> result = new ArrayList<>(); if (afterMatchSkipStrategy.isSkipStrategy()) { processMatchesAccordingToSkipStrategy(sharedBufferAccessor, nfaState, afterMatchSkipStrategy, potentialMatches, newPartialMatches, result); } else { for (ComputationState match : potentialMatches) { Map<String, List<T>> materializedMatch = sharedBufferAccessor.materializeMatch( sharedBufferAccessor.extractPatterns( match.getPreviousBufferEntry(), match.getVersion()).get(0) ); result.add(materializedMatch); sharedBufferAccessor.releaseNode(match.getPreviousBufferEntry()); } } nfaState.setNewPartialMatches(newPartialMatches); return result; }
Example 2
Source File: NFA.java From flink with Apache License 2.0 | 4 votes |
private Collection<Map<String, List<T>>> doProcess( final SharedBufferAccessor<T> sharedBufferAccessor, final NFAState nfaState, final EventWrapper event, final AfterMatchSkipStrategy afterMatchSkipStrategy, final TimerService timerService) throws Exception { final PriorityQueue<ComputationState> newPartialMatches = new PriorityQueue<>(NFAState.COMPUTATION_STATE_COMPARATOR); final PriorityQueue<ComputationState> potentialMatches = new PriorityQueue<>(NFAState.COMPUTATION_STATE_COMPARATOR); // iterate over all current computations for (ComputationState computationState : nfaState.getPartialMatches()) { final Collection<ComputationState> newComputationStates = computeNextStates( sharedBufferAccessor, computationState, event, timerService); if (newComputationStates.size() != 1) { nfaState.setStateChanged(); } else if (!newComputationStates.iterator().next().equals(computationState)) { nfaState.setStateChanged(); } //delay adding new computation states in case a stop state is reached and we discard the path. final Collection<ComputationState> statesToRetain = new ArrayList<>(); //if stop state reached in this path boolean shouldDiscardPath = false; for (final ComputationState newComputationState : newComputationStates) { if (isFinalState(newComputationState)) { potentialMatches.add(newComputationState); } else if (isStopState(newComputationState)) { //reached stop state. release entry for the stop state shouldDiscardPath = true; sharedBufferAccessor.releaseNode(newComputationState.getPreviousBufferEntry()); } else { // add new computation state; it will be processed once the next event arrives statesToRetain.add(newComputationState); } } if (shouldDiscardPath) { // a stop state was reached in this branch. release branch which results in removing previous event from // the buffer for (final ComputationState state : statesToRetain) { sharedBufferAccessor.releaseNode(state.getPreviousBufferEntry()); } } else { newPartialMatches.addAll(statesToRetain); } } if (!potentialMatches.isEmpty()) { nfaState.setStateChanged(); } List<Map<String, List<T>>> result = new ArrayList<>(); if (afterMatchSkipStrategy.isSkipStrategy()) { processMatchesAccordingToSkipStrategy(sharedBufferAccessor, nfaState, afterMatchSkipStrategy, potentialMatches, newPartialMatches, result); } else { for (ComputationState match : potentialMatches) { Map<String, List<T>> materializedMatch = sharedBufferAccessor.materializeMatch( sharedBufferAccessor.extractPatterns( match.getPreviousBufferEntry(), match.getVersion()).get(0) ); result.add(materializedMatch); sharedBufferAccessor.releaseNode(match.getPreviousBufferEntry()); } } nfaState.setNewPartialMatches(newPartialMatches); return result; }
Example 3
Source File: NFA.java From flink with Apache License 2.0 | 4 votes |
private Collection<Map<String, List<T>>> doProcess( final SharedBufferAccessor<T> sharedBufferAccessor, final NFAState nfaState, final EventWrapper event, final AfterMatchSkipStrategy afterMatchSkipStrategy, final TimerService timerService) throws Exception { final PriorityQueue<ComputationState> newPartialMatches = new PriorityQueue<>(NFAState.COMPUTATION_STATE_COMPARATOR); final PriorityQueue<ComputationState> potentialMatches = new PriorityQueue<>(NFAState.COMPUTATION_STATE_COMPARATOR); // iterate over all current computations for (ComputationState computationState : nfaState.getPartialMatches()) { final Collection<ComputationState> newComputationStates = computeNextStates( sharedBufferAccessor, computationState, event, timerService); if (newComputationStates.size() != 1) { nfaState.setStateChanged(); } else if (!newComputationStates.iterator().next().equals(computationState)) { nfaState.setStateChanged(); } //delay adding new computation states in case a stop state is reached and we discard the path. final Collection<ComputationState> statesToRetain = new ArrayList<>(); //if stop state reached in this path boolean shouldDiscardPath = false; for (final ComputationState newComputationState : newComputationStates) { if (isFinalState(newComputationState)) { potentialMatches.add(newComputationState); } else if (isStopState(newComputationState)) { //reached stop state. release entry for the stop state shouldDiscardPath = true; sharedBufferAccessor.releaseNode(newComputationState.getPreviousBufferEntry()); } else { // add new computation state; it will be processed once the next event arrives statesToRetain.add(newComputationState); } } if (shouldDiscardPath) { // a stop state was reached in this branch. release branch which results in removing previous event from // the buffer for (final ComputationState state : statesToRetain) { sharedBufferAccessor.releaseNode(state.getPreviousBufferEntry()); } } else { newPartialMatches.addAll(statesToRetain); } } if (!potentialMatches.isEmpty()) { nfaState.setStateChanged(); } List<Map<String, List<T>>> result = new ArrayList<>(); if (afterMatchSkipStrategy.isSkipStrategy()) { processMatchesAccordingToSkipStrategy(sharedBufferAccessor, nfaState, afterMatchSkipStrategy, potentialMatches, newPartialMatches, result); } else { for (ComputationState match : potentialMatches) { Map<String, List<T>> materializedMatch = sharedBufferAccessor.materializeMatch( sharedBufferAccessor.extractPatterns( match.getPreviousBufferEntry(), match.getVersion()).get(0) ); result.add(materializedMatch); sharedBufferAccessor.releaseNode(match.getPreviousBufferEntry()); } } nfaState.setNewPartialMatches(newPartialMatches); return result; }