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

The following examples show how to use org.apache.flink.cep.functions.PatternProcessFunction. 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
public CepOperator(
		final TypeSerializer<IN> inputSerializer,
		final boolean isProcessingTime,
		final NFACompiler.NFAFactory<IN> nfaFactory,
		@Nullable final EventComparator<IN> comparator,
		@Nullable final AfterMatchSkipStrategy afterMatchSkipStrategy,
		final PatternProcessFunction<IN, OUT> function,
		@Nullable final OutputTag<IN> lateDataOutputTag) {
	super(function);

	this.inputSerializer = Preconditions.checkNotNull(inputSerializer);
	this.nfaFactory = Preconditions.checkNotNull(nfaFactory);

	this.isProcessingTime = isProcessingTime;
	this.comparator = comparator;
	this.lateDataOutputTag = lateDataOutputTag;

	if (afterMatchSkipStrategy == null) {
		this.afterMatchSkipStrategy = AfterMatchSkipStrategy.noSkip();
	} else {
		this.afterMatchSkipStrategy = afterMatchSkipStrategy;
	}
}
 
Example #2
Source File: CepOperatorBuilder.java    From flink with Apache License 2.0 6 votes vote down vote up
public static CepOperatorBuilder<Map<String, List<Event>>> createOperatorForNFAFactory(NFACompiler.NFAFactory<Event> nfaFactory) {
	return new CepOperatorBuilder<>(
		true,
		nfaFactory,
		null,
		null,
		new PatternProcessFunction<Event, Map<String, List<Event>>>() {
			private static final long serialVersionUID = -7143807777582726991L;

			@Override
			public void processMatch(
				Map<String, List<Event>> match,
				Context ctx,
				Collector<Map<String, List<Event>>> out) throws Exception {
				out.collect(match);
			}
		},
		null);
}
 
Example #3
Source File: CepOperatorTestUtilities.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static <K> CepOperator<Event, K, Map<String, List<Event>>> getKeyedCepOpearator(
		boolean isProcessingTime,
		NFACompiler.NFAFactory<Event> nfaFactory,
		EventComparator<Event> comparator,
		OutputTag<Event> outputTag) {

	return new CepOperator<>(
		Event.createTypeSerializer(),
		isProcessingTime,
		nfaFactory,
		comparator,
		null,
		new PatternProcessFunction<Event, Map<String, List<Event>>>() {
			private static final long serialVersionUID = -7143807777582726991L;

			@Override
			public void processMatch(
					Map<String, List<Event>> match,
					Context ctx,
					Collector<Map<String, List<Event>>> out) throws Exception {
				out.collect(match);
			}
		},
		outputTag);
}
 
Example #4
Source File: CepOperatorTestUtilities.java    From flink with Apache License 2.0 6 votes vote down vote up
public static <K> CepOperator<Event, K, Map<String, List<Event>>> getKeyedCepOpearator(
		boolean isProcessingTime,
		NFACompiler.NFAFactory<Event> nfaFactory,
		EventComparator<Event> comparator,
		OutputTag<Event> outputTag) {

	return new CepOperator<>(
		Event.createTypeSerializer(),
		isProcessingTime,
		nfaFactory,
		comparator,
		null,
		new PatternProcessFunction<Event, Map<String, List<Event>>>() {
			private static final long serialVersionUID = -7143807777582726991L;

			@Override
			public void processMatch(
					Map<String, List<Event>> match,
					Context ctx,
					Collector<Map<String, List<Event>>> out) throws Exception {
				out.collect(match);
			}
		},
		outputTag);
}
 
Example #5
Source File: CepOperatorBuilder.java    From flink with Apache License 2.0 6 votes vote down vote up
public static CepOperatorBuilder<Map<String, List<Event>>> createOperatorForNFAFactory(NFACompiler.NFAFactory<Event> nfaFactory) {
	return new CepOperatorBuilder<>(
		true,
		nfaFactory,
		null,
		null,
		new PatternProcessFunction<Event, Map<String, List<Event>>>() {
			private static final long serialVersionUID = -7143807777582726991L;

			@Override
			public void processMatch(
				Map<String, List<Event>> match,
				Context ctx,
				Collector<Map<String, List<Event>>> out) throws Exception {
				out.collect(match);
			}
		},
		null);
}
 
Example #6
Source File: CepOperatorBuilder.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static CepOperatorBuilder<Map<String, List<Event>>> createOperatorForNFA(NFA<Event> nfa) {
	return new CepOperatorBuilder<>(
		true,
		new NFACompiler.NFAFactory<Event>() {
			@Override
			public NFA<Event> createNFA() {
				return nfa;
			}
		},
		null,
		null,
		new PatternProcessFunction<Event, Map<String, List<Event>>>() {
			private static final long serialVersionUID = -7143807777582726991L;

			@Override
			public void processMatch(
				Map<String, List<Event>> match,
				Context ctx,
				Collector<Map<String, List<Event>>> out) throws Exception {
				out.collect(match);
			}
		},
		null);
}
 
Example #7
Source File: CepOperatorBuilder.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static CepOperatorBuilder<Map<String, List<Event>>> createOperatorForNFAFactory(NFACompiler.NFAFactory<Event> nfaFactory) {
	return new CepOperatorBuilder<>(
		true,
		nfaFactory,
		null,
		null,
		new PatternProcessFunction<Event, Map<String, List<Event>>>() {
			private static final long serialVersionUID = -7143807777582726991L;

			@Override
			public void processMatch(
				Map<String, List<Event>> match,
				Context ctx,
				Collector<Map<String, List<Event>>> out) throws Exception {
				out.collect(match);
			}
		},
		null);
}
 
Example #8
Source File: CepOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
public CepOperator(
		final TypeSerializer<IN> inputSerializer,
		final boolean isProcessingTime,
		final NFACompiler.NFAFactory<IN> nfaFactory,
		@Nullable final EventComparator<IN> comparator,
		@Nullable final AfterMatchSkipStrategy afterMatchSkipStrategy,
		final PatternProcessFunction<IN, OUT> function,
		@Nullable final OutputTag<IN> lateDataOutputTag) {
	super(function);

	this.inputSerializer = Preconditions.checkNotNull(inputSerializer);
	this.nfaFactory = Preconditions.checkNotNull(nfaFactory);

	this.isProcessingTime = isProcessingTime;
	this.comparator = comparator;
	this.lateDataOutputTag = lateDataOutputTag;

	if (afterMatchSkipStrategy == null) {
		this.afterMatchSkipStrategy = AfterMatchSkipStrategy.noSkip();
	} else {
		this.afterMatchSkipStrategy = afterMatchSkipStrategy;
	}
}
 
Example #9
Source File: CepOperatorBuilder.java    From flink with Apache License 2.0 6 votes vote down vote up
public static CepOperatorBuilder<Map<String, List<Event>>> createOperatorForNFA(NFA<Event> nfa) {
	return new CepOperatorBuilder<>(
		true,
		new NFACompiler.NFAFactory<Event>() {
			@Override
			public NFA<Event> createNFA() {
				return nfa;
			}
		},
		null,
		null,
		new PatternProcessFunction<Event, Map<String, List<Event>>>() {
			private static final long serialVersionUID = -7143807777582726991L;

			@Override
			public void processMatch(
				Map<String, List<Event>> match,
				Context ctx,
				Collector<Map<String, List<Event>>> out) throws Exception {
				out.collect(match);
			}
		},
		null);
}
 
Example #10
Source File: CepOperatorBuilder.java    From flink with Apache License 2.0 6 votes vote down vote up
public static CepOperatorBuilder<Map<String, List<Event>>> createOperatorForNFA(NFA<Event> nfa) {
	return new CepOperatorBuilder<>(
		true,
		new NFACompiler.NFAFactory<Event>() {
			@Override
			public NFA<Event> createNFA() {
				return nfa;
			}
		},
		null,
		null,
		new PatternProcessFunction<Event, Map<String, List<Event>>>() {
			private static final long serialVersionUID = -7143807777582726991L;

			@Override
			public void processMatch(
				Map<String, List<Event>> match,
				Context ctx,
				Collector<Map<String, List<Event>>> out) throws Exception {
				out.collect(match);
			}
		},
		null);
}
 
Example #11
Source File: PatternStream.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
	 * Applies a process function to the detected pattern sequence. For each pattern sequence the
	 * provided {@link PatternProcessFunction} is called. In order to process timed out partial matches as well one can
	 * use {@link TimedOutPartialMatchHandler} as additional interface.
	 *
	 * @param patternProcessFunction The pattern process function which is called for each detected
	 *                              pattern sequence.
	 * @param <R> Type of the resulting elements
	 * @param outTypeInfo Explicit specification of output type.
	 * @return {@link DataStream} which contains the resulting elements from the pattern process
	 *         function.
	 */
	public <R> SingleOutputStreamOperator<R> process(
			final PatternProcessFunction<T, R> patternProcessFunction,
			final TypeInformation<R> outTypeInfo) {

//    这个方法会创建真正的nfafactory包含nfa.statue
//	  先判断client端是否register了,然后就注入进去了
//		------------
		if (hasListener){
			patternProcessFunction.registerListener(cepListener);
		}
//		------------

		return builder.build(
			outTypeInfo,
			builder.clean(patternProcessFunction));
	}
 
Example #12
Source File: CepOperatorTestUtilities.java    From flink with Apache License 2.0 6 votes vote down vote up
public static <K> CepOperator<Event, K, Map<String, List<Event>>> getKeyedCepOpearator(
		boolean isProcessingTime,
		NFACompiler.NFAFactory<Event> nfaFactory,
		EventComparator<Event> comparator,
		OutputTag<Event> outputTag) {

	return new CepOperator<>(
		Event.createTypeSerializer(),
		isProcessingTime,
		nfaFactory,
		comparator,
		null,
		new PatternProcessFunction<Event, Map<String, List<Event>>>() {
			private static final long serialVersionUID = -7143807777582726991L;

			@Override
			public void processMatch(
					Map<String, List<Event>> match,
					Context ctx,
					Collector<Map<String, List<Event>>> out) throws Exception {
				out.collect(match);
			}
		},
		outputTag);
}
 
Example #13
Source File: CepOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
public CepOperator(
		final TypeSerializer<IN> inputSerializer,
		final boolean isProcessingTime,
		final NFACompiler.NFAFactory<IN> nfaFactory,
		@Nullable final EventComparator<IN> comparator,
		@Nullable final AfterMatchSkipStrategy afterMatchSkipStrategy,
		final PatternProcessFunction<IN, OUT> function,
		@Nullable final OutputTag<IN> lateDataOutputTag) {
	super(function);

	this.inputSerializer = Preconditions.checkNotNull(inputSerializer);
	this.nfaFactory = Preconditions.checkNotNull(nfaFactory);

	this.isProcessingTime = isProcessingTime;
	this.comparator = comparator;
	this.lateDataOutputTag = lateDataOutputTag;

	if (afterMatchSkipStrategy == null) {
		this.afterMatchSkipStrategy = AfterMatchSkipStrategy.noSkip();
	} else {
		this.afterMatchSkipStrategy = afterMatchSkipStrategy;
	}
}
 
Example #14
Source File: CepProcessFunctionContextTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private <T> CepOperator<Event, Integer, T> createCepOperator(
		PatternProcessFunction<Event, T> processFunction,
		NFACompiler.NFAFactory<Event> nfaFactory,
		boolean isProcessingTime) throws Exception {
	return new CepOperator<>(
		Event.createTypeSerializer(),
		isProcessingTime,
		nfaFactory,
		null,
		null,
		processFunction,
		null);
}
 
Example #15
Source File: CepOperatorBuilder.java    From flink with Apache License 2.0 5 votes vote down vote up
private CepOperatorBuilder(
	boolean isProcessingTime,
	NFACompiler.NFAFactory<Event> nfaFactory,
	EventComparator<Event> comparator,
	AfterMatchSkipStrategy skipStrategy,
	PatternProcessFunction<Event, OUT> processFunction,
	OutputTag<Event> lateDataOutputTag) {
	this.isProcessingTime = isProcessingTime;
	this.nfaFactory = nfaFactory;
	this.comparator = comparator;
	this.skipStrategy = skipStrategy;
	function = processFunction;
	this.lateDataOutputTag = lateDataOutputTag;
}
 
Example #16
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 #17
Source File: PatternStream.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Applies a process function to the detected pattern sequence. For each pattern sequence the
 * provided {@link PatternProcessFunction} is called. In order to process timed out partial matches as well one can
 * use {@link TimedOutPartialMatchHandler} as additional interface.
 *
 * @param patternProcessFunction The pattern process function which is called for each detected
 *                               pattern sequence.
 * @param <R> Type of the resulting elements
 * @return {@link DataStream} which contains the resulting elements from the pattern process
 *         function.
 */
public <R> SingleOutputStreamOperator<R> process(final PatternProcessFunction<T, R> patternProcessFunction) {
	final TypeInformation<R> returnType = TypeExtractor.getUnaryOperatorReturnType(
		patternProcessFunction,
		PatternProcessFunction.class,
		0,
		1,
		TypeExtractor.NO_INDEX,
		builder.getInputType(),
		null,
		false);

	return process(patternProcessFunction, returnType);
}
 
Example #18
Source File: CepOperatorBuilder.java    From flink with Apache License 2.0 5 votes vote down vote up
public <T> CepOperatorBuilder<T> withFunction(PatternProcessFunction<Event, T> processFunction) {
	return new CepOperatorBuilder<>(
		isProcessingTime,
		nfaFactory,
		comparator,
		skipStrategy,
		processFunction,
		lateDataOutputTag);
}
 
Example #19
Source File: CepOperatorBuilder.java    From flink with Apache License 2.0 5 votes vote down vote up
private CepOperatorBuilder(
	boolean isProcessingTime,
	NFACompiler.NFAFactory<Event> nfaFactory,
	EventComparator<Event> comparator,
	AfterMatchSkipStrategy skipStrategy,
	PatternProcessFunction<Event, OUT> processFunction,
	OutputTag<Event> lateDataOutputTag) {
	this.isProcessingTime = isProcessingTime;
	this.nfaFactory = nfaFactory;
	this.comparator = comparator;
	this.skipStrategy = skipStrategy;
	function = processFunction;
	this.lateDataOutputTag = lateDataOutputTag;
}
 
Example #20
Source File: PatternStream.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Applies a process function to the detected pattern sequence. For each pattern sequence the
 * provided {@link PatternProcessFunction} is called. In order to process timed out partial matches as well one can
 * use {@link TimedOutPartialMatchHandler} as additional interface.
 *
 * @param patternProcessFunction The pattern process function which is called for each detected
 *                               pattern sequence.
 * @param <R> Type of the resulting elements
 * @return {@link DataStream} which contains the resulting elements from the pattern process
 *         function.
 */
public <R> SingleOutputStreamOperator<R> process(final PatternProcessFunction<T, R> patternProcessFunction) {

	final TypeInformation<R> returnType = TypeExtractor.getUnaryOperatorReturnType(
		patternProcessFunction,
		PatternProcessFunction.class,
		0,
		1,
		TypeExtractor.NO_INDEX,
		builder.getInputType(),
		null,
		false);

	return process(patternProcessFunction, returnType);
}
 
Example #21
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 #22
Source File: CepOperator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void processMatchedSequences(Iterable<Map<String, List<IN>>> matchingSequences, long timestamp) throws Exception {
	PatternProcessFunction<IN, OUT> function = getUserFunction();
	setTimestamp(timestamp);
	for (Map<String, List<IN>> matchingSequence : matchingSequences) {
		function.processMatch(matchingSequence, context, collector);
	}
}
 
Example #23
Source File: CepProcessFunctionContextTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private <T> CepOperator<Event, Integer, T> createCepOperator(
		PatternProcessFunction<Event, T> processFunction,
		NFACompiler.NFAFactory<Event> nfaFactory,
		boolean isProcessingTime) throws Exception {
	return new CepOperator<>(
		Event.createTypeSerializer(),
		isProcessingTime,
		nfaFactory,
		null,
		null,
		processFunction,
		null);
}
 
Example #24
Source File: CEPOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processMatch(
	Map<String, List<Event>> match,
	PatternProcessFunction.Context ctx,
	Collector<Map<String, List<Event>>> out) throws Exception {
	out.collect(match);
}
 
Example #25
Source File: CepProcessFunctionContextTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private <T> CepOperator<Event, Integer, T> createCepOperator(
		PatternProcessFunction<Event, T> processFunction,
		NFACompiler.NFAFactory<Event> nfaFactory,
		boolean isProcessingTime) throws Exception {
	return new CepOperator<>(
		Event.createTypeSerializer(),
		isProcessingTime,
		nfaFactory,
		null,
		null,
		processFunction,
		null);
}
 
Example #26
Source File: CEPOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processMatch(
	Map<String, List<Event>> match,
	PatternProcessFunction.Context ctx,
	Collector<Map<String, List<Event>>> out) throws Exception {
	out.collect(match);
}
 
Example #27
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 #28
Source File: CepOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
private void processMatchedSequences(Iterable<Map<String, List<IN>>> matchingSequences, long timestamp) throws Exception {
	PatternProcessFunction<IN, OUT> function = getUserFunction();
	setTimestamp(timestamp);
	for (Map<String, List<IN>> matchingSequence : matchingSequences) {
		function.processMatch(matchingSequence, context, collector);
	}
}
 
Example #29
Source File: CepOperatorBuilder.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private CepOperatorBuilder(
	boolean isProcessingTime,
	NFACompiler.NFAFactory<Event> nfaFactory,
	EventComparator<Event> comparator,
	AfterMatchSkipStrategy skipStrategy,
	PatternProcessFunction<Event, OUT> processFunction,
	OutputTag<Event> lateDataOutputTag) {
	this.isProcessingTime = isProcessingTime;
	this.nfaFactory = nfaFactory;
	this.comparator = comparator;
	this.skipStrategy = skipStrategy;
	function = processFunction;
	this.lateDataOutputTag = lateDataOutputTag;
}
 
Example #30
Source File: CepOperatorBuilder.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public <T> CepOperatorBuilder<T> withFunction(PatternProcessFunction<Event, T> processFunction) {
	return new CepOperatorBuilder<>(
		isProcessingTime,
		nfaFactory,
		comparator,
		skipStrategy,
		processFunction,
		lateDataOutputTag);
}