Search in sources :

Example 1 with EventId

use of org.apache.flink.cep.nfa.sharedbuffer.EventId in project flink by apache.

the class NFAStateSerializer method deserializeStartEvent.

private EventId deserializeStartEvent(DataInputView source) throws IOException {
    byte isNull = source.readByte();
    EventId startEventId = null;
    if (isNull == 1) {
        startEventId = eventIdSerializer.deserialize(source);
    }
    return startEventId;
}
Also used : EventId(org.apache.flink.cep.nfa.sharedbuffer.EventId)

Example 2 with EventId

use of org.apache.flink.cep.nfa.sharedbuffer.EventId in project flink by apache.

the class NFAStateSerializer method copyStartEvent.

private void copyStartEvent(DataInputView source, DataOutputView target) throws IOException {
    byte isNull = source.readByte();
    target.writeByte(isNull);
    if (isNull == 1) {
        EventId startEventId = eventIdSerializer.deserialize(source);
        eventIdSerializer.serialize(startEventId, target);
    }
}
Also used : EventId(org.apache.flink.cep.nfa.sharedbuffer.EventId)

Example 3 with EventId

use of org.apache.flink.cep.nfa.sharedbuffer.EventId in project flink by apache.

the class MigrationUtils method deserializeComputationStates.

static <T> Queue<ComputationState> deserializeComputationStates(org.apache.flink.cep.nfa.SharedBuffer<T> sharedBuffer, TypeSerializer<T> eventSerializer, DataInputView source) throws IOException {
    Queue<ComputationState> computationStates = new LinkedList<>();
    StringSerializer stateNameSerializer = StringSerializer.INSTANCE;
    LongSerializer timestampSerializer = LongSerializer.INSTANCE;
    DeweyNumber.DeweyNumberSerializer versionSerializer = DeweyNumber.DeweyNumberSerializer.INSTANCE;
    int computationStateNo = source.readInt();
    for (int i = 0; i < computationStateNo; i++) {
        String state = stateNameSerializer.deserialize(source);
        String prevState = stateNameSerializer.deserialize(source);
        long timestamp = timestampSerializer.deserialize(source);
        DeweyNumber version = versionSerializer.deserialize(source);
        long startTimestamp = timestampSerializer.deserialize(source);
        int counter = source.readInt();
        T event = null;
        if (source.readBoolean()) {
            event = eventSerializer.deserialize(source);
        }
        NodeId nodeId;
        EventId startEventId;
        if (prevState != null) {
            nodeId = sharedBuffer.getNodeId(prevState, timestamp, counter, event);
            startEventId = sharedBuffer.getStartEventId(version.getRun());
        } else {
            nodeId = null;
            startEventId = null;
        }
        computationStates.add(ComputationState.createState(state, nodeId, version, startTimestamp, startEventId));
    }
    return computationStates;
}
Also used : LongSerializer(org.apache.flink.api.common.typeutils.base.LongSerializer) LinkedList(java.util.LinkedList) NodeId(org.apache.flink.cep.nfa.sharedbuffer.NodeId) EventId(org.apache.flink.cep.nfa.sharedbuffer.EventId) StringSerializer(org.apache.flink.api.common.typeutils.base.StringSerializer)

Example 4 with EventId

use of org.apache.flink.cep.nfa.sharedbuffer.EventId in project flink by apache.

the class NFAStateSerializer method deserializeSingleComputationState.

private ComputationState deserializeSingleComputationState(DataInputView source) throws IOException {
    String stateName = StringValue.readString(source);
    NodeId prevState = nodeIdSerializer.deserialize(source);
    DeweyNumber version = versionSerializer.deserialize(source);
    long startTimestamp = source.readLong();
    EventId startEventId = deserializeStartEvent(source);
    return ComputationState.createState(stateName, prevState, version, startTimestamp, startEventId);
}
Also used : NodeId(org.apache.flink.cep.nfa.sharedbuffer.NodeId) EventId(org.apache.flink.cep.nfa.sharedbuffer.EventId)

Example 5 with EventId

use of org.apache.flink.cep.nfa.sharedbuffer.EventId in project flink by apache.

the class AfterMatchSkipStrategy method prune.

/**
 * Prunes matches/partial matches based on the chosen strategy.
 *
 * @param matchesToPrune current partial matches
 * @param matchedResult already completed matches
 * @param sharedBufferAccessor accessor to corresponding shared buffer
 * @throws Exception thrown if could not access the state
 */
public void prune(Collection<ComputationState> matchesToPrune, Collection<Map<String, List<EventId>>> matchedResult, SharedBufferAccessor<?> sharedBufferAccessor) throws Exception {
    EventId pruningId = getPruningId(matchedResult);
    if (pruningId != null) {
        List<ComputationState> discardStates = new ArrayList<>();
        for (ComputationState computationState : matchesToPrune) {
            if (computationState.getStartEventID() != null && shouldPrune(computationState.getStartEventID(), pruningId)) {
                sharedBufferAccessor.releaseNode(computationState.getPreviousBufferEntry(), computationState.getVersion());
                discardStates.add(computationState);
            }
        }
        matchesToPrune.removeAll(discardStates);
    }
}
Also used : ArrayList(java.util.ArrayList) EventId(org.apache.flink.cep.nfa.sharedbuffer.EventId) ComputationState(org.apache.flink.cep.nfa.ComputationState)

Aggregations

EventId (org.apache.flink.cep.nfa.sharedbuffer.EventId)6 NodeId (org.apache.flink.cep.nfa.sharedbuffer.NodeId)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)1 LongSerializer (org.apache.flink.api.common.typeutils.base.LongSerializer)1 StringSerializer (org.apache.flink.api.common.typeutils.base.StringSerializer)1 ComputationState (org.apache.flink.cep.nfa.ComputationState)1