org.apache.flink.cep.pattern.MalformedPatternException Java Examples

The following examples show how to use org.apache.flink.cep.pattern.MalformedPatternException. 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: NFACompiler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
		 * Compiles the given pattern into a {@link NFAFactory}. The NFA factory can be used to create
		 * multiple NFAs.
		 */
//		修改default->public
		public void compileFactory() {
			if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) {
				throw new MalformedPatternException("NotFollowedBy is not supported as a last part of a Pattern!");
			}

			checkPatternNameUniqueness();

			checkPatternSkipStrategy();

			// we're traversing the pattern from the end to the beginning --> the first state is the final state
			State<T> sinkState = createEndingState();
			// add all the normal states
			sinkState = createMiddleStates(sinkState);
			// add the beginning state
			createStartState(sinkState);
		}
 
Example #2
Source File: NFACompiler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Check pattern after match skip strategy.
 */
private void checkPatternSkipStrategy() {
	if (afterMatchSkipStrategy.getPatternName().isPresent()) {
		String patternName = afterMatchSkipStrategy.getPatternName().get();
		Pattern<T, ?> pattern = currentPattern;
		while (pattern.getPrevious() != null && !pattern.getName().equals(patternName)) {
			pattern = pattern.getPrevious();
		}

		// pattern name match check.
		if (!pattern.getName().equals(patternName)) {
			throw new MalformedPatternException("The pattern name specified in AfterMatchSkipStrategy " +
				"can not be found in the given Pattern");
		}
	}
}
 
Example #3
Source File: NFACompiler.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Compiles the given pattern into a {@link NFAFactory}. The NFA factory can be used to create
 * multiple NFAs.
 */
void compileFactory() {
	if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) {
		throw new MalformedPatternException("NotFollowedBy is not supported as a last part of a Pattern!");
	}

	checkPatternNameUniqueness();

	checkPatternSkipStrategy();

	// we're traversing the pattern from the end to the beginning --> the first state is the final state
	State<T> sinkState = createEndingState();
	// add all the normal states
	sinkState = createMiddleStates(sinkState);
	// add the beginning state
	createStartState(sinkState);
}
 
Example #4
Source File: NFACompiler.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Check pattern after match skip strategy.
 */
private void checkPatternSkipStrategy() {
	if (afterMatchSkipStrategy.getPatternName().isPresent()) {
		String patternName = afterMatchSkipStrategy.getPatternName().get();
		Pattern<T, ?> pattern = currentPattern;
		while (pattern.getPrevious() != null && !pattern.getName().equals(patternName)) {
			pattern = pattern.getPrevious();
		}

		// pattern name match check.
		if (!pattern.getName().equals(patternName)) {
			throw new MalformedPatternException("The pattern name specified in AfterMatchSkipStrategy " +
				"can not be found in the given Pattern");
		}
	}
}
 
Example #5
Source File: NFACompiler.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Compiles the given pattern into a {@link NFAFactory}. The NFA factory can be used to create
 * multiple NFAs.
 */
void compileFactory() {
	if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) {
		throw new MalformedPatternException("NotFollowedBy is not supported as a last part of a Pattern!");
	}

	checkPatternNameUniqueness();

	checkPatternSkipStrategy();

	// we're traversing the pattern from the end to the beginning --> the first state is the final state
	State<T> sinkState = createEndingState();
	// add all the normal states
	sinkState = createMiddleStates(sinkState);
	// add the beginning state
	createStartState(sinkState);
}
 
Example #6
Source File: NFACompiler.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Check pattern after match skip strategy.
 */
private void checkPatternSkipStrategy() {
	if (afterMatchSkipStrategy.getPatternName().isPresent()) {
		String patternName = afterMatchSkipStrategy.getPatternName().get();
		Pattern<T, ?> pattern = currentPattern;
		while (pattern.getPrevious() != null && !pattern.getName().equals(patternName)) {
			pattern = pattern.getPrevious();
		}

		// pattern name match check.
		if (!pattern.getName().equals(patternName)) {
			throw new MalformedPatternException("The pattern name specified in AfterMatchSkipStrategy " +
				"can not be found in the given Pattern");
		}
	}
}
 
Example #7
Source File: NFAStateNameHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the given name is already used or not. If yes, it
 * throws a {@link MalformedPatternException}.
 *
 * @param name The name to be checked.
 */
public void checkNameUniqueness(String name) {
	if (usedNames.contains(name)) {
		throw new MalformedPatternException("Duplicate pattern name: " + name + ". Names must be unique.");
	}
	usedNames.add(name);
}
 
Example #8
Source File: NFACompilerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNFACompilerUniquePatternName() {

	// adjust the rule
	expectedException.expect(MalformedPatternException.class);
	expectedException.expectMessage("Duplicate pattern name: start. Names must be unique.");

	Pattern<Event, ?> invalidPattern = Pattern.<Event>begin("start").where(new TestFilter())
		.followedBy("middle").where(new TestFilter())
		.followedBy("start").where(new TestFilter());

	// here we must have an exception because of the two "start" patterns with the same name.
	compile(invalidPattern, false);
}
 
Example #9
Source File: NFACompilerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNFACompilerPatternEndsWithNotFollowedBy() {

	// adjust the rule
	expectedException.expect(MalformedPatternException.class);
	expectedException.expectMessage("NotFollowedBy is not supported as a last part of a Pattern!");

	Pattern<Event, ?> invalidPattern = Pattern.<Event>begin("start").where(new TestFilter())
		.followedBy("middle").where(new TestFilter())
		.notFollowedBy("end").where(new TestFilter());

	// here we must have an exception because of the two "start" patterns with the same name.
	compile(invalidPattern, false);
}
 
Example #10
Source File: NFAStateNameHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the given name is already used or not. If yes, it
 * throws a {@link MalformedPatternException}.
 *
 * @param name The name to be checked.
 */
public void checkNameUniqueness(String name) {
	if (usedNames.contains(name)) {
		throw new MalformedPatternException("Duplicate pattern name: " + name + ". Names must be unique.");
	}
	usedNames.add(name);
}
 
Example #11
Source File: NFACompilerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNFACompilerUniquePatternName() {

	// adjust the rule
	expectedException.expect(MalformedPatternException.class);
	expectedException.expectMessage("Duplicate pattern name: start. Names must be unique.");

	Pattern<Event, ?> invalidPattern = Pattern.<Event>begin("start").where(new TestFilter())
		.followedBy("middle").where(new TestFilter())
		.followedBy("start").where(new TestFilter());

	// here we must have an exception because of the two "start" patterns with the same name.
	compile(invalidPattern, false);
}
 
Example #12
Source File: NFACompilerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNFACompilerPatternEndsWithNotFollowedBy() {

	// adjust the rule
	expectedException.expect(MalformedPatternException.class);
	expectedException.expectMessage("NotFollowedBy is not supported as a last part of a Pattern!");

	Pattern<Event, ?> invalidPattern = Pattern.<Event>begin("start").where(new TestFilter())
		.followedBy("middle").where(new TestFilter())
		.notFollowedBy("end").where(new TestFilter());

	// here we must have an exception because of the two "start" patterns with the same name.
	compile(invalidPattern, false);
}
 
Example #13
Source File: NFAStateNameHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the given name is already used or not. If yes, it
 * throws a {@link MalformedPatternException}.
 *
 * @param name The name to be checked.
 */
public void checkNameUniqueness(String name) {
	if (usedNames.contains(name)) {
		throw new MalformedPatternException("Duplicate pattern name: " + name + ". Names must be unique.");
	}
	usedNames.add(name);
}
 
Example #14
Source File: NFACompilerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNFACompilerUniquePatternName() {

	// adjust the rule
	expectedException.expect(MalformedPatternException.class);
	expectedException.expectMessage("Duplicate pattern name: start. Names must be unique.");

	Pattern<Event, ?> invalidPattern = Pattern.<Event>begin("start").where(new TestFilter())
		.followedBy("middle").where(new TestFilter())
		.followedBy("start").where(new TestFilter());

	// here we must have an exception because of the two "start" patterns with the same name.
	compile(invalidPattern, false);
}
 
Example #15
Source File: NFACompilerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNFACompilerPatternEndsWithNotFollowedBy() {

	// adjust the rule
	expectedException.expect(MalformedPatternException.class);
	expectedException.expectMessage("NotFollowedBy is not supported as a last part of a Pattern!");

	Pattern<Event, ?> invalidPattern = Pattern.<Event>begin("start").where(new TestFilter())
		.followedBy("middle").where(new TestFilter())
		.notFollowedBy("end").where(new TestFilter());

	// here we must have an exception because of the two "start" patterns with the same name.
	compile(invalidPattern, false);
}