Java Code Examples for org.apache.flink.cep.nfa.compiler.NFACompiler#NFAFactory
The following examples show how to use
org.apache.flink.cep.nfa.compiler.NFACompiler#NFAFactory .
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 |
/** * @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: CepOperatorTestUtilities.java From flink with Apache License 2.0 | 6 votes |
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 3
Source File: CepOperatorTestUtilities.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
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 |
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 |
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 6
Source File: CepOperatorBuilder.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
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 |
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: CepOperatorBuilder.java From flink with Apache License 2.0 | 6 votes |
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 9
Source File: CepOperator.java From flink with Apache License 2.0 | 6 votes |
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 10
Source File: CepOperatorBuilder.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
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 11
Source File: CepOperatorTestUtilities.java From flink with Apache License 2.0 | 5 votes |
public static <K> CepOperator<Event, K, Map<String, List<Event>>> getKeyedCepOpearator( boolean isProcessingTime, NFACompiler.NFAFactory<Event> nfaFactory, EventComparator<Event> comparator) { return getKeyedCepOpearator(isProcessingTime, nfaFactory, comparator, null); }
Example 12
Source File: CepProcessFunctionContextTest.java From flink with Apache License 2.0 | 5 votes |
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 13
Source File: CepOperatorBuilder.java From flink with Apache License 2.0 | 5 votes |
public CepOperatorBuilder<OUT> withNFA(NFA<Event> nfa) { return new CepOperatorBuilder<>( false, new NFACompiler.NFAFactory<Event>() { @Override public NFA<Event> createNFA() { return nfa; } }, comparator, skipStrategy, function, lateDataOutputTag); }
Example 14
Source File: CepOperatorTestUtilities.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public static <K> CepOperator<Event, K, Map<String, List<Event>>> getKeyedCepOpearator( boolean isProcessingTime, NFACompiler.NFAFactory<Event> nfaFactory, EventComparator<Event> comparator) { return getKeyedCepOpearator(isProcessingTime, nfaFactory, comparator, null); }
Example 15
Source File: CepOperatorBuilder.java From flink with Apache License 2.0 | 5 votes |
public CepOperatorBuilder<OUT> withNFA(NFA<Event> nfa) { return new CepOperatorBuilder<>( false, new NFACompiler.NFAFactory<Event>() { @Override public NFA<Event> createNFA() { return nfa; } }, comparator, skipStrategy, function, lateDataOutputTag); }
Example 16
Source File: PatternStreamBuilder.java From flink with Apache License 2.0 | 4 votes |
/** * 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 17
Source File: CepOperatorTestUtilities.java From flink with Apache License 2.0 | 4 votes |
public static <K> CepOperator<Event, K, Map<String, List<Event>>> getKeyedCepOpearator( boolean isProcessingTime, NFACompiler.NFAFactory<Event> nfaFactory) { return getKeyedCepOpearator(isProcessingTime, nfaFactory, null); }
Example 18
Source File: PatternStreamBuilder.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * 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 19
Source File: CepOperatorTestUtilities.java From flink with Apache License 2.0 | 4 votes |
public static <K> CepOperator<Event, K, Map<String, List<Event>>> getKeyedCepOpearator( boolean isProcessingTime, NFACompiler.NFAFactory<Event> nfaFactory) { return getKeyedCepOpearator(isProcessingTime, nfaFactory, null); }
Example 20
Source File: NFAUtils.java From flink with Apache License 2.0 | 2 votes |
/** * Compiles the given pattern into a {@link NFA}. * * @param pattern Definition of sequence pattern * @param timeoutHandling True if the NFA shall return timed out event patterns * @param <T> Type of the input events * @return Non-deterministic finite automaton representing the given pattern */ public static <T> NFA<T> compile(Pattern<T, ?> pattern, boolean timeoutHandling) { NFACompiler.NFAFactory<T> factory = compileFactory(pattern, timeoutHandling); return factory.createNFA(); }