@Override public NFAState deserialize(DataInputView source) throws IOException { PriorityQueue<ComputationState> partialMatches = deserializeComputationStates(source); PriorityQueue<ComputationState> completedMatches = deserializeComputationStates(source); return new NFAState(partialMatches, completedMatches); }
@Override public void serialize(NFAState record, DataOutputView target) throws IOException { serializeComputationStates(record.getPartialMatches(), target); serializeComputationStates(record.getCompletedMatches(), target); }
public static ComputationState createStartState(final String state) { return createStartState(state, new DeweyNumber(1)); }
@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(); } }
/** * Tear-down method for the NFA. */ public void close() throws Exception { for (State<T> state : getStates()) { for (StateTransition<T> transition : state.getStateTransitions()) { IterativeCondition condition = transition.getCondition(); FunctionUtils.closeFunction(condition); } } }
private boolean isStartState(ComputationState state) { State<T> stateObject = getState(state); if (stateObject == null) { throw new FlinkRuntimeException("State " + state.getCurrentStateName() + " does not exist in the NFA. NFA has states " + states.values()); } return stateObject.isStart(); }
private boolean isFinalState(ComputationState state) { State<T> stateObject = getState(state); if (stateObject == null) { throw new FlinkRuntimeException("State " + state.getCurrentStateName() + " does not exist in the NFA. NFA has states " + states.values()); } return stateObject.isFinal(); }
private boolean isSelfIgnore(final StateTransition<T> edge) { return isEquivalentState(edge.getTargetState(), currentState) && edge.getAction() == StateTransitionAction.IGNORE; } }
void add(StateTransition<T> edge) { if (!isSelfIgnore(edge)) { if (edge.getAction() == StateTransitionAction.IGNORE) { totalIgnoreBranches++; } else if (edge.getAction() == StateTransitionAction.TAKE) { totalTakeBranches++; } } edges.add(edge); }
private boolean isStateTimedOut(final ComputationState state, final long timestamp) { return !isStartState(state) && windowTime > 0L && timestamp - state.getStartTimestamp() >= windowTime; }
@Override public NFA<T> createNFA() { return new NFA<>(states, windowTime, timeoutHandling); } }
public NFASerializer(TypeSerializer<T> typeSerializer) { this(typeSerializer, new org.apache.flink.cep.nfa.SharedBuffer.SharedBufferSerializer<>( StringSerializer.INSTANCE, typeSerializer)); }
@Override protected NFAStateSerializer createOuterSerializerWithNestedSerializers(TypeSerializer<?>[] nestedSerializers) { @SuppressWarnings("unchecked") TypeSerializer<DeweyNumber> versionSerializer = (TypeSerializer<DeweyNumber>) nestedSerializers[0]; @SuppressWarnings("unchecked") TypeSerializer<NodeId> nodeIdSerializer = (TypeSerializer<NodeId>) nestedSerializers[1]; @SuppressWarnings("unchecked") TypeSerializer<EventId> eventIdSerializer = (TypeSerializer<EventId>) nestedSerializers[2]; return new NFAStateSerializer(versionSerializer, nodeIdSerializer, eventIdSerializer); } }
@Override public MigratedNFA<T> deserialize( MigratedNFA<T> reuse, DataInputView source) throws IOException { return deserialize(source); }
@Override public TypeSerializerConfigSnapshot<SharedBuffer<V>> snapshotConfiguration() { return new SharedBufferSerializerConfigSnapshot<>( keySerializer, valueSerializer, versionSerializer); }
public static ComputationState createState( final String currentState, final NodeId previousEntry, final DeweyNumber version, final long startTimestamp, final EventId startEventID) { return new ComputationState(currentState, previousEntry, version, startEventID, startTimestamp); } }
@Override protected TypeSerializer<?>[] getNestedSerializers(NFAStateSerializer outerSerializer) { TypeSerializer<DeweyNumber> versionSerializer = outerSerializer.getVersionSerializer(); TypeSerializer<NodeId> nodeIdSerializer = outerSerializer.getNodeIdSerializer(); TypeSerializer<EventId> eventIdSerializer = outerSerializer.getEventIdSerializer(); return new TypeSerializer[]{versionSerializer, nodeIdSerializer, eventIdSerializer}; }
public NFA( final Collection<State<T>> validStates, final long windowTime, final boolean handleTimeout) { this.windowTime = windowTime; this.handleTimeout = handleTimeout; this.states = loadStates(validStates); }
@Override public void copy(DataInputView source, DataOutputView target) throws IOException { copyStates(source, target); // copy partial matches copyStates(source, target); // copy completed matches }
@Override public NFAState copy(NFAState from, NFAState reuse) { return copy(from); }