本文整理汇总了Java中org.apache.flink.cep.pattern.Pattern类的典型用法代码示例。如果您正苦于以下问题:Java Pattern类的具体用法?Java Pattern怎么用?Java Pattern使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pattern类属于org.apache.flink.cep.pattern包,在下文中一共展示了Pattern类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testNoUnnecessaryStateCopiesCreated
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
@Test
public void testNoUnnecessaryStateCopiesCreated() {
final Pattern<Event, Event> pattern = Pattern.<Event>begin("start").where(startFilter)
.notFollowedBy("not").where(startFilter)
.followedBy("oneOrMore").where(startFilter).oneOrMore()
.followedBy("end").where(endFilter);
final NFACompiler.NFAFactoryCompiler<Event> nfaFactoryCompiler = new NFACompiler.NFAFactoryCompiler<>(pattern);
nfaFactoryCompiler.compileFactory();
int endStateCount = 0;
for (State<Event> state : nfaFactoryCompiler.getStates()) {
if (state.getName().equals("end")) {
endStateCount++;
}
}
assertEquals(1, endStateCount);
}
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:NFACompilerTest.java
示例2: main
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
Properties properties = new Properties();
properties.setProperty("bootstrap.servers", "localhost:9092");
properties.setProperty("group.id", "test");
DataStream<TemperatureEvent> inputEventStream = env.addSource(
new FlinkKafkaConsumer09<TemperatureEvent>("test", new EventDeserializationSchema(), properties));
Pattern<TemperatureEvent, ?> warningPattern = Pattern.<TemperatureEvent> begin("first")
.subtype(TemperatureEvent.class).where(new FilterFunction<TemperatureEvent>() {
private static final long serialVersionUID = 1L;
public boolean filter(TemperatureEvent value) {
if (value.getTemperature() >= 26.0) {
return true;
}
return false;
}
}).within(Time.seconds(10));
DataStream<Alert> patternStream = CEP.pattern(inputEventStream, warningPattern)
.select(new PatternSelectFunction<TemperatureEvent, Alert>() {
private static final long serialVersionUID = 1L;
public Alert select(Map<String, TemperatureEvent> event) throws Exception {
return new Alert("Temperature Rise Detected:" + event.get("first").getTemperature()
+ " on machine name:" + event.get("first").getMachineName());
}
});
patternStream.print();
env.execute("CEP on Temperature Sensor");
}
开发者ID:PacktPublishing,项目名称:Mastering-Apache-Flink,代码行数:38,代码来源:KafkaApp.java
示例3: testLambdaSelectFunction
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* Tests that a Java8 lambda can be passed as a CEP select function.
*/
@Test
public void testLambdaSelectFunction() {
TypeInformation<EventA> eventTypeInformation = TypeExtractor.getForClass(EventA.class);
TypeInformation<EventB> outputTypeInformation = TypeExtractor.getForClass(EventB.class);
DataStream<EventA> inputStream = new DataStream<>(
StreamExecutionEnvironment.getExecutionEnvironment(),
new SourceTransformation<>(
"source",
null,
eventTypeInformation,
1));
Pattern<EventA, ?> dummyPattern = Pattern.begin("start");
PatternStream<EventA> patternStream = new PatternStream<>(inputStream, dummyPattern);
DataStream<EventB> result = patternStream.select(
(Map<String, List<EventA>> map) -> new EventB()
);
assertEquals(outputTypeInformation, result.getType());
}
开发者ID:axbaretto,项目名称:flink,代码行数:27,代码来源:CEPLambdaTest.java
示例4: testLambdaFlatSelectFunction
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* Tests that a Java8 lambda can be passed as a CEP flat select function.
*/
@Test
public void testLambdaFlatSelectFunction() {
TypeInformation<EventA> eventTypeInformation = TypeExtractor.getForClass(EventA.class);
TypeInformation<EventB> outputTypeInformation = TypeExtractor.getForClass(EventB.class);
DataStream<EventA> inputStream = new DataStream<>(
StreamExecutionEnvironment.getExecutionEnvironment(),
new SourceTransformation<>(
"source",
null,
eventTypeInformation,
1));
Pattern<EventA, ?> dummyPattern = Pattern.begin("start");
PatternStream<EventA> patternStream = new PatternStream<>(inputStream, dummyPattern);
DataStream<EventB> result = patternStream.flatSelect(
(Map<String, List<EventA>> map, Collector<EventB> collector) -> collector.collect(new EventB())
);
assertEquals(outputTypeInformation, result.getType());
}
开发者ID:axbaretto,项目名称:flink,代码行数:27,代码来源:CEPLambdaTest.java
示例5: checkPatternSkipStrategy
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* Check pattern after match skip strategy.
*/
private void checkPatternSkipStrategy() {
if (afterMatchSkipStrategy.getStrategy() == AfterMatchSkipStrategy.SkipStrategy.SKIP_TO_FIRST ||
afterMatchSkipStrategy.getStrategy() == AfterMatchSkipStrategy.SkipStrategy.SKIP_TO_LAST) {
Pattern<T, ?> pattern = currentPattern;
while (pattern.getPrevious() != null && !pattern.getName().equals(afterMatchSkipStrategy.getPatternName())) {
pattern = pattern.getPrevious();
}
// pattern name match check.
if (!pattern.getName().equals(afterMatchSkipStrategy.getPatternName())) {
throw new MalformedPatternException("The pattern name specified in AfterMatchSkipStrategy " +
"can not be found in the given Pattern");
}
}
}
开发者ID:axbaretto,项目名称:flink,代码行数:19,代码来源:NFACompiler.java
示例6: getCurrentNotCondition
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* Retrieves list of conditions resulting in Stop state and names of the corresponding NOT patterns.
*
* <p>A current not condition can be produced in two cases:
* <ol>
* <li>the previous pattern is a {@link Quantifier.ConsumingStrategy#NOT_FOLLOW}</li>
* <li>exists a backward path of {@link Quantifier.QuantifierProperty#OPTIONAL} patterns to
* {@link Quantifier.ConsumingStrategy#NOT_FOLLOW}</li>
* </ol>
*
* <p><b>WARNING:</b> for more info on the second case see: {@link NFAFactoryCompiler#copyWithoutTransitiveNots(State)}
*
* @return list of not conditions with corresponding names
*/
private List<Tuple2<IterativeCondition<T>, String>> getCurrentNotCondition() {
List<Tuple2<IterativeCondition<T>, String>> notConditions = new ArrayList<>();
Pattern<T, ? extends T> previousPattern = currentPattern;
while (previousPattern.getPrevious() != null && (
previousPattern.getPrevious().getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL) ||
previousPattern.getPrevious().getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW)) {
previousPattern = previousPattern.getPrevious();
if (previousPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) {
final IterativeCondition<T> notCondition = getTakeCondition(previousPattern);
notConditions.add(Tuple2.of(notCondition, previousPattern.getName()));
}
}
return notConditions;
}
开发者ID:axbaretto,项目名称:flink,代码行数:32,代码来源:NFACompiler.java
示例7: createLoopingGroupPatternState
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* Create the states for the group pattern as a looping one.
*
* @param groupPattern the group pattern to create the states for
* @param sinkState the state that the group pattern being converted should point to
* @return the first state of the states of the group pattern
*/
private State<T> createLoopingGroupPatternState(
final GroupPattern<T, ?> groupPattern,
final State<T> sinkState) {
final IterativeCondition<T> proceedCondition = getTrueFunction();
Pattern<T, ?> oldCurrentPattern = currentPattern;
Pattern<T, ?> oldFollowingPattern = followingPattern;
GroupPattern<T, ?> oldGroupPattern = currentGroupPattern;
final State<T> dummyState = createState(currentPattern.getName(), State.StateType.Normal);
State<T> lastSink = dummyState;
currentGroupPattern = groupPattern;
currentPattern = groupPattern.getRawPattern();
lastSink = createMiddleStates(lastSink);
lastSink = convertPattern(lastSink);
lastSink.addProceed(sinkState, proceedCondition);
dummyState.addProceed(lastSink, proceedCondition);
currentPattern = oldCurrentPattern;
followingPattern = oldFollowingPattern;
currentGroupPattern = oldGroupPattern;
return lastSink;
}
开发者ID:axbaretto,项目名称:flink,代码行数:30,代码来源:NFACompiler.java
示例8: testStartWithOneOrZeroOrMoreStrict
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
private void testStartWithOneOrZeroOrMoreStrict(Pattern<Event, ?> pattern) {
List<StreamRecord<Event>> inputEvents = new ArrayList<>();
inputEvents.add(new StreamRecord<>(ConsecutiveData.startEvent, 1));
inputEvents.add(new StreamRecord<>(ConsecutiveData.middleEvent1, 3));
inputEvents.add(new StreamRecord<>(ConsecutiveData.startEvent, 4));
inputEvents.add(new StreamRecord<>(ConsecutiveData.middleEvent2, 5));
inputEvents.add(new StreamRecord<>(ConsecutiveData.middleEvent3, 6));
NFA<Event> nfa = NFACompiler.compile(pattern, Event.createTypeSerializer(), false);
List<List<Event>> resultingPatterns = feedNFA(inputEvents, nfa);
compareMaps(resultingPatterns, Lists.<List<Event>>newArrayList(
Lists.newArrayList(ConsecutiveData.middleEvent1),
Lists.newArrayList(ConsecutiveData.middleEvent2, ConsecutiveData.middleEvent3),
Lists.newArrayList(ConsecutiveData.middleEvent2),
Lists.newArrayList(ConsecutiveData.middleEvent3)
));
}
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:NFAITCase.java
示例9: main
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStream<TemperatureEvent> inputEventStream = env.fromElements(new TemperatureEvent("xyz", 22.0),
new TemperatureEvent("xyz", 20.1), new TemperatureEvent("xyz", 21.1), new TemperatureEvent("xyz", 22.2),
new TemperatureEvent("xyz", 29.1), new TemperatureEvent("xyz", 22.3), new TemperatureEvent("xyz", 22.1),
new TemperatureEvent("xyz", 22.4), new TemperatureEvent("xyz", 22.7),
new TemperatureEvent("xyz", 27.0));
Pattern<TemperatureEvent, ?> warningPattern = Pattern.<TemperatureEvent> begin("first")
.subtype(TemperatureEvent.class).where(new FilterFunction<TemperatureEvent>() {
private static final long serialVersionUID = 1L;
public boolean filter(TemperatureEvent value) {
if (value.getTemperature() >= 26.0) {
return true;
}
return false;
}
}).within(Time.seconds(10));
DataStream<Alert> patternStream = CEP.pattern(inputEventStream, warningPattern)
.select(new PatternSelectFunction<TemperatureEvent, Alert>() {
private static final long serialVersionUID = 1L;
public Alert select(Map<String, TemperatureEvent> event) throws Exception {
return new Alert("Temperature Rise Detected");
}
});
patternStream.print();
env.execute("CEP on Temperature Sensor");
}
开发者ID:PacktPublishing,项目名称:Mastering-Apache-Flink,代码行数:35,代码来源:App.java
示例10: getEventPattern
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
@Override
public Pattern<LocalWeatherData, ?> getEventPattern() {
return Pattern
.<LocalWeatherData>begin("First Event").where(
new SimpleCondition<LocalWeatherData>() {
@Override
public boolean filter(LocalWeatherData event) throws Exception {
return event.getWindSpeed() > 110;
}
});
}
开发者ID:bytefish,项目名称:FlinkExperiments,代码行数:12,代码来源:ExtremeWindWarningPattern.java
示例11: getEventPattern
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
@Override
public Pattern<LocalWeatherData, ?> getEventPattern() {
return Pattern
.<LocalWeatherData>begin("First Event").where(
new SimpleCondition<LocalWeatherData>() {
@Override
public boolean filter(LocalWeatherData event) throws Exception {
return event.getWindSpeed() >= 39 && event.getWindSpeed() <= 110;
}
});
}
开发者ID:bytefish,项目名称:FlinkExperiments,代码行数:12,代码来源:HighWindWarningPattern.java
示例12: compileFactory
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* Compiles the given pattern into a {@link NFAFactory}. The NFA factory can be used to create
* multiple NFAs.
*
* @param pattern Definition of sequence pattern
* @param inputTypeSerializer Serializer for the input type
* @param timeoutHandling True if the NFA shall return timed out event patterns
* @param <T> Type of the input events
* @return Factory for NFAs corresponding to the given pattern
*/
@SuppressWarnings("unchecked")
public static <T> NFAFactory<T> compileFactory(
final Pattern<T, ?> pattern,
final TypeSerializer<T> inputTypeSerializer,
boolean timeoutHandling) {
if (pattern == null) {
// return a factory for empty NFAs
return new NFAFactoryImpl<>(inputTypeSerializer, 0, Collections.<State<T>>emptyList(), timeoutHandling);
} else {
final NFAFactoryCompiler<T> nfaFactoryCompiler = new NFAFactoryCompiler<>(pattern);
nfaFactoryCompiler.compileFactory();
return new NFAFactoryImpl<>(inputTypeSerializer, nfaFactoryCompiler.getWindowTime(), nfaFactoryCompiler.getStates(), timeoutHandling);
}
}
开发者ID:axbaretto,项目名称:flink,代码行数:25,代码来源:NFACompiler.java
示例13: checkPatternNameUniqueness
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* Check if there are duplicate pattern names. If yes, it
* throws a {@link MalformedPatternException}.
*/
private void checkPatternNameUniqueness() {
// make sure there is no pattern with name "$endState$"
stateNameHandler.checkNameUniqueness(ENDING_STATE_NAME);
Pattern patternToCheck = currentPattern;
while (patternToCheck != null) {
checkPatternNameUniqueness(patternToCheck);
patternToCheck = patternToCheck.getPrevious();
}
stateNameHandler.clear();
}
开发者ID:axbaretto,项目名称:flink,代码行数:15,代码来源:NFACompiler.java
示例14: isPatternOptional
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* Checks if the given pattern is optional. If the given pattern is the head of a group pattern,
* the optional status depends on the group pattern.
*/
private boolean isPatternOptional(Pattern<T, ?> pattern) {
if (headOfGroup(pattern)) {
return isCurrentGroupPatternFirstOfLoop() &&
currentGroupPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL);
} else {
return pattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL);
}
}
开发者ID:axbaretto,项目名称:flink,代码行数:13,代码来源:NFACompiler.java
示例15: createGroupPatternState
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* Create all the states for the group pattern.
*
* @param groupPattern the group pattern to create the states for
* @param sinkState the state that the group pattern being converted should point to
* @param proceedState the state that the group pattern being converted should proceed to
* @param isOptional whether the group pattern being converted is optional
* @return the first state of the states of the group pattern
*/
private State<T> createGroupPatternState(
final GroupPattern<T, ?> groupPattern,
final State<T> sinkState,
final State<T> proceedState,
final boolean isOptional) {
final IterativeCondition<T> proceedCondition = getTrueFunction();
Pattern<T, ?> oldCurrentPattern = currentPattern;
Pattern<T, ?> oldFollowingPattern = followingPattern;
GroupPattern<T, ?> oldGroupPattern = currentGroupPattern;
State<T> lastSink = sinkState;
currentGroupPattern = groupPattern;
currentPattern = groupPattern.getRawPattern();
lastSink = createMiddleStates(lastSink);
lastSink = convertPattern(lastSink);
if (isOptional) {
// for the first state of a group pattern, its PROCEED edge should point to
// the following state of that group pattern
lastSink.addProceed(proceedState, proceedCondition);
}
currentPattern = oldCurrentPattern;
followingPattern = oldFollowingPattern;
currentGroupPattern = oldGroupPattern;
return lastSink;
}
开发者ID:axbaretto,项目名称:flink,代码行数:36,代码来源:NFACompiler.java
示例16: getInnerIgnoreCondition
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* @return The {@link IterativeCondition condition} for the {@code IGNORE} edge
* that corresponds to the specified {@link Pattern} and extended with stop(until) condition
* if necessary. It is applicable only for inner states of a complex state like looping or times.
*/
@SuppressWarnings("unchecked")
private IterativeCondition<T> getInnerIgnoreCondition(Pattern<T, ?> pattern) {
Quantifier.ConsumingStrategy consumingStrategy = pattern.getQuantifier().getInnerConsumingStrategy();
if (headOfGroup(pattern)) {
// for the head pattern of a group pattern, we should consider the
// inner consume strategy of the group pattern
consumingStrategy = currentGroupPattern.getQuantifier().getInnerConsumingStrategy();
}
IterativeCondition<T> innerIgnoreCondition = null;
switch (consumingStrategy) {
case STRICT:
innerIgnoreCondition = null;
break;
case SKIP_TILL_NEXT:
innerIgnoreCondition = new NotCondition<>((IterativeCondition<T>) pattern.getCondition());
break;
case SKIP_TILL_ANY:
innerIgnoreCondition = BooleanConditions.trueFunction();
break;
}
if (currentGroupPattern != null && currentGroupPattern.getUntilCondition() != null) {
innerIgnoreCondition = extendWithUntilCondition(
innerIgnoreCondition,
(IterativeCondition<T>) currentGroupPattern.getUntilCondition(),
false);
}
return innerIgnoreCondition;
}
开发者ID:axbaretto,项目名称:flink,代码行数:36,代码来源:NFACompiler.java
示例17: getIgnoreCondition
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* @return The {@link IterativeCondition condition} for the {@code IGNORE} edge
* that corresponds to the specified {@link Pattern} and extended with
* stop(until) condition if necessary. For more on strategy see {@link Quantifier}
*/
@SuppressWarnings("unchecked")
private IterativeCondition<T> getIgnoreCondition(Pattern<T, ?> pattern) {
Quantifier.ConsumingStrategy consumingStrategy = pattern.getQuantifier().getConsumingStrategy();
if (headOfGroup(pattern)) {
// for the head pattern of a group pattern, we should consider the inner consume strategy
// of the group pattern if the group pattern is not the head of the TIMES/LOOPING quantifier;
// otherwise, we should consider the consume strategy of the group pattern
if (isCurrentGroupPatternFirstOfLoop()) {
consumingStrategy = currentGroupPattern.getQuantifier().getConsumingStrategy();
} else {
consumingStrategy = currentGroupPattern.getQuantifier().getInnerConsumingStrategy();
}
}
IterativeCondition<T> ignoreCondition = null;
switch (consumingStrategy) {
case STRICT:
ignoreCondition = null;
break;
case SKIP_TILL_NEXT:
ignoreCondition = new NotCondition<>((IterativeCondition<T>) pattern.getCondition());
break;
case SKIP_TILL_ANY:
ignoreCondition = BooleanConditions.trueFunction();
break;
}
if (currentGroupPattern != null && currentGroupPattern.getUntilCondition() != null) {
ignoreCondition = extendWithUntilCondition(
ignoreCondition,
(IterativeCondition<T>) currentGroupPattern.getUntilCondition(),
false);
}
return ignoreCondition;
}
开发者ID:axbaretto,项目名称:flink,代码行数:41,代码来源:NFACompiler.java
示例18: getTakeCondition
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
/**
* @return the {@link IterativeCondition condition} for the {@code TAKE} edge
* that corresponds to the specified {@link Pattern} and extended with
* stop(until) condition if necessary.
*/
@SuppressWarnings("unchecked")
private IterativeCondition<T> getTakeCondition(Pattern<T, ?> pattern) {
IterativeCondition<T> takeCondition = (IterativeCondition<T>) pattern.getCondition();
if (currentGroupPattern != null && currentGroupPattern.getUntilCondition() != null) {
takeCondition = extendWithUntilCondition(
takeCondition,
(IterativeCondition<T>) currentGroupPattern.getUntilCondition(),
true);
}
return takeCondition;
}
开发者ID:axbaretto,项目名称:flink,代码行数:17,代码来源:NFACompiler.java
示例19: createNFA
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
@Override
public NFA<Event> createNFA() {
Pattern<Event, ?> pattern = Pattern.<Event>begin("start").where(new StartFilter())
.followedBy("middle").subtype(SubEvent.class).where(new MiddleFilter())
.followedBy("end").where(new EndFilter())
// add a window timeout to test whether timestamps of elements in the
// priority queue in CEP operator are correctly checkpointed/restored
.within(Time.milliseconds(10L));
return NFACompiler.compile(pattern, Event.createTypeSerializer(), handleTimeout);
}
开发者ID:axbaretto,项目名称:flink,代码行数:13,代码来源:CEPMigration11to13Test.java
示例20: createNFA
import org.apache.flink.cep.pattern.Pattern; //导入依赖的package包/类
@Override
public NFA<Event> createNFA() {
Pattern<Event, ?> pattern = Pattern.<Event>begin("start").where(new StartFilter())
.within(Time.milliseconds(10L));
return NFACompiler.compile(pattern, Event.createTypeSerializer(), handleTimeout);
}
开发者ID:axbaretto,项目名称:flink,代码行数:9,代码来源:CEPMigrationTest.java
注:本文中的org.apache.flink.cep.pattern.Pattern类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论