org.apache.flink.cep.functions.TimedOutPartialMatchHandler Java Examples

The following examples show how to use org.apache.flink.cep.functions.TimedOutPartialMatchHandler. 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: CepOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
	 * @Description: 触发新逻辑注入时通过调用用户代码得到返回的pattern更新NFA
	 * @param: []
	 * @return: void
	 * @auther: greenday
	 * @date: 2019/9/9 15:54
	 */
	private void changeNFA(IN flagElement)throws Exception{
		Pattern pattern ;
		pattern = userFunction.getNewPattern(flagElement);
		NFACompiler.NFAFactoryCompiler<IN> nfaFactoryCompiler = new NFACompiler.NFAFactoryCompiler<IN>((Pattern<IN,?>)pattern);
		nfaFactoryCompiler.compileFactory();
		boolean timeoutHandling = userFunction instanceof TimedOutPartialMatchHandler;
		NFACompiler.NFAFactory nfaFactory = NFACompiler.compileFactory(pattern, timeoutHandling);
//		得到工厂的nfa
		NFA<IN> newNFA = nfaFactory.createNFA();
//		这个地方为所有的边transition设置了cepRuntimeContext
		newNFA.open(cepRuntimeContext, new Configuration());
//		覆盖
		nfa = newNFA;
//		清理以前的未完成的数据,以及共享缓存
		cleanBeforeMatch();
		cleanSharedBuffer();
	}
 
Example #2
Source File: CepOperator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void processTimedOutSequences(Collection<Tuple2<Map<String, List<IN>>, Long>> timedOutSequences) throws Exception {
	PatternProcessFunction<IN, OUT> function = getUserFunction();
	if (function instanceof TimedOutPartialMatchHandler) {

		@SuppressWarnings("unchecked")
		TimedOutPartialMatchHandler<IN> timeoutHandler = (TimedOutPartialMatchHandler<IN>) function;

		for (Tuple2<Map<String, List<IN>>, Long> matchingSequence : timedOutSequences) {
			setTimestamp(matchingSequence.f1);
			timeoutHandler.processTimedOutMatch(matchingSequence.f0, context);
		}
	}
}
 
Example #3
Source File: CepOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
private void processTimedOutSequences(Collection<Tuple2<Map<String, List<IN>>, Long>> timedOutSequences) throws Exception {
	PatternProcessFunction<IN, OUT> function = getUserFunction();
	if (function instanceof TimedOutPartialMatchHandler) {

		@SuppressWarnings("unchecked")
		TimedOutPartialMatchHandler<IN> timeoutHandler = (TimedOutPartialMatchHandler<IN>) function;

		for (Tuple2<Map<String, List<IN>>, Long> matchingSequence : timedOutSequences) {
			setTimestamp(matchingSequence.f1);
			timeoutHandler.processTimedOutMatch(matchingSequence.f0, context);
		}
	}
}
 
Example #4
Source File: CepOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
private void processTimedOutSequences(Collection<Tuple2<Map<String, List<IN>>, Long>> timedOutSequences) throws Exception {
	PatternProcessFunction<IN, OUT> function = getUserFunction();
	if (function instanceof TimedOutPartialMatchHandler) {

		@SuppressWarnings("unchecked")
		TimedOutPartialMatchHandler<IN> timeoutHandler = (TimedOutPartialMatchHandler<IN>) function;

		for (Tuple2<Map<String, List<IN>>, Long> matchingSequence : timedOutSequences) {
			setTimestamp(matchingSequence.f1);
			timeoutHandler.processTimedOutMatch(matchingSequence.f0, context);
		}
	}
}
 
Example #5
Source File: PatternStreamBuilder.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a data stream containing results of {@link PatternProcessFunction} to fully matching event patterns.
 *
 * @param processFunction function to be applied to matching event sequences
 * @param outTypeInfo output TypeInformation of
 *        {@link PatternProcessFunction#processMatch(Map, PatternProcessFunction.Context, Collector)}
 * @param <OUT> type of output events
 * @return Data stream containing fully matched event sequence with applied {@link PatternProcessFunction}
 */
<OUT, K> SingleOutputStreamOperator<OUT> build(
		final TypeInformation<OUT> outTypeInfo,
		final PatternProcessFunction<IN, OUT> processFunction) {

	checkNotNull(outTypeInfo);
	checkNotNull(processFunction);

	final TypeSerializer<IN> inputSerializer = inputStream.getType().createSerializer(inputStream.getExecutionConfig());
	final boolean isProcessingTime = inputStream.getExecutionEnvironment().getStreamTimeCharacteristic() == TimeCharacteristic.ProcessingTime;

	final boolean timeoutHandling = processFunction instanceof TimedOutPartialMatchHandler;
	final NFACompiler.NFAFactory<IN> nfaFactory = NFACompiler.compileFactory(pattern, timeoutHandling);

	final CepOperator<IN, K, OUT> operator = new CepOperator<>(
		inputSerializer,
		isProcessingTime,
		nfaFactory,
		comparator,
		pattern.getAfterMatchSkipStrategy(),
		processFunction,
		lateDataOutputTag);

	final SingleOutputStreamOperator<OUT> patternStream;
	if (inputStream instanceof KeyedStream) {
		KeyedStream<IN, K> keyedStream = (KeyedStream<IN, K>) inputStream;

		patternStream = keyedStream.transform(
			"CepOperator",
			outTypeInfo,
			operator);
	} else {
		KeySelector<IN, Byte> keySelector = new NullByteKeySelector<>();

		patternStream = inputStream.keyBy(keySelector).transform(
			"GlobalCepOperator",
			outTypeInfo,
			operator
		).forceNonParallel();
	}

	return patternStream;
}
 
Example #6
Source File: PatternStreamBuilder.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a data stream containing results of {@link PatternProcessFunction} to fully matching event patterns.
 *
 * @param processFunction function to be applied to matching event sequences
 * @param outTypeInfo output TypeInformation of
 *        {@link PatternProcessFunction#processMatch(Map, PatternProcessFunction.Context, Collector)}
 * @param <OUT> type of output events
 * @return Data stream containing fully matched event sequence with applied {@link PatternProcessFunction}
 */
<OUT, K> SingleOutputStreamOperator<OUT> build(
		final TypeInformation<OUT> outTypeInfo,
		final PatternProcessFunction<IN, OUT> processFunction) {

	checkNotNull(outTypeInfo);
	checkNotNull(processFunction);

	final TypeSerializer<IN> inputSerializer = inputStream.getType().createSerializer(inputStream.getExecutionConfig());
	final boolean isProcessingTime = inputStream.getExecutionEnvironment().getStreamTimeCharacteristic() == TimeCharacteristic.ProcessingTime;

	final boolean timeoutHandling = processFunction instanceof TimedOutPartialMatchHandler;
	final NFACompiler.NFAFactory<IN> nfaFactory = NFACompiler.compileFactory(pattern, timeoutHandling);

	final CepOperator<IN, K, OUT> operator = new CepOperator<>(
		inputSerializer,
		isProcessingTime,
		nfaFactory,
		comparator,
		pattern.getAfterMatchSkipStrategy(),
		processFunction,
		lateDataOutputTag);

	final SingleOutputStreamOperator<OUT> patternStream;
	if (inputStream instanceof KeyedStream) {
		KeyedStream<IN, K> keyedStream = (KeyedStream<IN, K>) inputStream;

		patternStream = keyedStream.transform(
			"CepOperator",
			outTypeInfo,
			operator);
	} else {
		KeySelector<IN, Byte> keySelector = new NullByteKeySelector<>();

		patternStream = inputStream.keyBy(keySelector).transform(
			"GlobalCepOperator",
			outTypeInfo,
			operator
		).forceNonParallel();
	}

	return patternStream;
}
 
Example #7
Source File: PatternStreamBuilder.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a data stream containing results of {@link PatternProcessFunction} to fully matching event patterns.
 *
 * @param processFunction function to be applied to matching event sequences
 * @param outTypeInfo output TypeInformation of
 *        {@link PatternProcessFunction#processMatch(Map, PatternProcessFunction.Context, Collector)}
 * @param <OUT> type of output events
 * @return Data stream containing fully matched event sequence with applied {@link PatternProcessFunction}
 */
<OUT, K> SingleOutputStreamOperator<OUT> build(
		final TypeInformation<OUT> outTypeInfo,
		final PatternProcessFunction<IN, OUT> processFunction) {

	checkNotNull(outTypeInfo);
	checkNotNull(processFunction);

	final TypeSerializer<IN> inputSerializer = inputStream.getType().createSerializer(inputStream.getExecutionConfig());
	final boolean isProcessingTime = inputStream.getExecutionEnvironment().getStreamTimeCharacteristic() == TimeCharacteristic.ProcessingTime;

	final boolean timeoutHandling = processFunction instanceof TimedOutPartialMatchHandler;
	final NFACompiler.NFAFactory<IN> nfaFactory = NFACompiler.compileFactory(pattern, timeoutHandling);

	final CepOperator<IN, K, OUT> operator = new CepOperator<>(
		inputSerializer,
		isProcessingTime,
		nfaFactory,
		comparator,
		pattern.getAfterMatchSkipStrategy(),
		processFunction,
		lateDataOutputTag);

	final SingleOutputStreamOperator<OUT> patternStream;
	if (inputStream instanceof KeyedStream) {
		KeyedStream<IN, K> keyedStream = (KeyedStream<IN, K>) inputStream;

		patternStream = keyedStream.transform(
			"CepOperator",
			outTypeInfo,
			operator);
	} else {
		KeySelector<IN, Byte> keySelector = new NullByteKeySelector<>();

		patternStream = inputStream.keyBy(keySelector).transform(
			"GlobalCepOperator",
			outTypeInfo,
			operator
		).forceNonParallel();
	}

	return patternStream;
}