org.apache.flink.cep.pattern.Quantifier.ConsumingStrategy Java Examples

The following examples show how to use org.apache.flink.cep.pattern.Quantifier.ConsumingStrategy. 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: PatternTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testPatternWithSubtypingAndFilter() {
	Pattern<Event, Event> pattern = Pattern.<Event>begin("start").next("subevent").subtype(SubEvent.class).where(new SimpleCondition<SubEvent>() {
		private static final long serialVersionUID = -4118591291880230304L;

		@Override
		public boolean filter(SubEvent value) throws Exception {
			return false;
		}
	}).followedBy("end");

	Pattern<Event, ?> previous;
	Pattern<Event, ?> previous2;

	assertNotNull(previous = pattern.getPrevious());
	assertNotNull(previous2 = previous.getPrevious());
	assertNull(previous2.getPrevious());

	assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, pattern.getQuantifier().getConsumingStrategy());
	assertNotNull(previous.getCondition());

	assertEquals(pattern.getName(), "end");
	assertEquals(previous.getName(), "subevent");
	assertEquals(previous2.getName(), "start");
}
 
Example #2
Source File: PatternTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonStrictContiguity() {
	Pattern<Object, ?> pattern = Pattern.begin("start").followedBy("next").followedBy("end");
	Pattern<Object, ?> previous;
	Pattern<Object, ?> previous2;

	assertNotNull(previous = pattern.getPrevious());
	assertNotNull(previous2 = previous.getPrevious());
	assertNull(previous2.getPrevious());

	assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, pattern.getQuantifier().getConsumingStrategy());
	assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, previous.getQuantifier().getConsumingStrategy());

	assertEquals(pattern.getName(), "end");
	assertEquals(previous.getName(), "next");
	assertEquals(previous2.getName(), "start");
}
 
Example #3
Source File: PatternTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testPatternWithSubtypingAndFilter() {
	Pattern<Event, Event> pattern = Pattern.<Event>begin("start").next("subevent").subtype(SubEvent.class).where(new SimpleCondition<SubEvent>() {
		private static final long serialVersionUID = -4118591291880230304L;

		@Override
		public boolean filter(SubEvent value) throws Exception {
			return false;
		}
	}).followedBy("end");

	Pattern<Event, ?> previous;
	Pattern<Event, ?> previous2;

	assertNotNull(previous = pattern.getPrevious());
	assertNotNull(previous2 = previous.getPrevious());
	assertNull(previous2.getPrevious());

	assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, pattern.getQuantifier().getConsumingStrategy());
	assertNotNull(previous.getCondition());

	assertEquals(pattern.getName(), "end");
	assertEquals(previous.getName(), "subevent");
	assertEquals(previous2.getName(), "start");
}
 
Example #4
Source File: PatternTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testPatternWithSubtypingAndFilter() {
	Pattern<Event, Event> pattern = Pattern.<Event>begin("start").next("subevent").subtype(SubEvent.class).where(new SimpleCondition<SubEvent>() {
		private static final long serialVersionUID = -4118591291880230304L;

		@Override
		public boolean filter(SubEvent value) throws Exception {
			return false;
		}
	}).followedBy("end");

	Pattern<Event, ?> previous;
	Pattern<Event, ?> previous2;

	assertNotNull(previous = pattern.getPrevious());
	assertNotNull(previous2 = previous.getPrevious());
	assertNull(previous2.getPrevious());

	assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, pattern.getQuantifier().getConsumingStrategy());
	assertNotNull(previous.getCondition());

	assertEquals(pattern.getName(), "end");
	assertEquals(previous.getName(), "subevent");
	assertEquals(previous2.getName(), "start");
}
 
Example #5
Source File: PatternTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonStrictContiguity() {
	Pattern<Object, ?> pattern = Pattern.begin("start").followedBy("next").followedBy("end");
	Pattern<Object, ?> previous;
	Pattern<Object, ?> previous2;

	assertNotNull(previous = pattern.getPrevious());
	assertNotNull(previous2 = previous.getPrevious());
	assertNull(previous2.getPrevious());

	assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, pattern.getQuantifier().getConsumingStrategy());
	assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, previous.getQuantifier().getConsumingStrategy());

	assertEquals(pattern.getName(), "end");
	assertEquals(previous.getName(), "next");
	assertEquals(previous2.getName(), "start");
}
 
Example #6
Source File: PatternTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonStrictContiguity() {
	Pattern<Object, ?> pattern = Pattern.begin("start").followedBy("next").followedBy("end");
	Pattern<Object, ?> previous;
	Pattern<Object, ?> previous2;

	assertNotNull(previous = pattern.getPrevious());
	assertNotNull(previous2 = previous.getPrevious());
	assertNull(previous2.getPrevious());

	assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, pattern.getQuantifier().getConsumingStrategy());
	assertEquals(ConsumingStrategy.SKIP_TILL_NEXT, previous.getQuantifier().getConsumingStrategy());

	assertEquals(pattern.getName(), "end");
	assertEquals(previous.getName(), "next");
	assertEquals(previous2.getName(), "start");
}
 
Example #7
Source File: Pattern.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a new pattern to the existing one. The new pattern enforces that there is no event matching this pattern
 * between the preceding pattern and succeeding this one.
 *
 * <p><b>NOTE:</b> There has to be other pattern after this one.
 *
 * @param name Name of the new pattern
 * @return A new pattern which is appended to this one
 */
public Pattern<T, T> notFollowedBy(final String name) {
	if (quantifier.hasProperty(Quantifier.QuantifierProperty.OPTIONAL)) {
		throw new UnsupportedOperationException(
				"Specifying a pattern with an optional path to NOT condition is not supported yet. " +
				"You can simulate such pattern with two independent patterns, one with and the other without " +
				"the optional part.");
	}
	return new Pattern<>(name, this, ConsumingStrategy.NOT_FOLLOW, afterMatchSkipStrategy);
}
 
Example #8
Source File: Pattern.java    From flink with Apache License 2.0 5 votes vote down vote up
protected Pattern(
	final String name,
	final Pattern<T, ? extends T> previous,
	final ConsumingStrategy consumingStrategy,
	final AfterMatchSkipStrategy afterMatchSkipStrategy) {
	this.name = name;
	this.previous = previous;
	this.quantifier = Quantifier.one(consumingStrategy);
	this.afterMatchSkipStrategy = afterMatchSkipStrategy;
}
 
Example #9
Source File: Pattern.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
protected Pattern(
	final String name,
	final Pattern<T, ? extends T> previous,
	final ConsumingStrategy consumingStrategy,
	final AfterMatchSkipStrategy afterMatchSkipStrategy) {
	this.name = name;
	this.previous = previous;
	this.quantifier = Quantifier.one(consumingStrategy);
	this.afterMatchSkipStrategy = afterMatchSkipStrategy;
}
 
Example #10
Source File: Pattern.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a new pattern to the existing one. The new pattern enforces that there is no event matching this pattern
 * between the preceding pattern and succeeding this one.
 *
 * <p><b>NOTE:</b> There has to be other pattern after this one.
 *
 * @param name Name of the new pattern
 * @return A new pattern which is appended to this one
 */
public Pattern<T, T> notFollowedBy(final String name) {
	if (quantifier.hasProperty(Quantifier.QuantifierProperty.OPTIONAL)) {
		throw new UnsupportedOperationException(
				"Specifying a pattern with an optional path to NOT condition is not supported yet. " +
				"You can simulate such pattern with two independent patterns, one with and the other without " +
				"the optional part.");
	}
	return new Pattern<>(name, this, ConsumingStrategy.NOT_FOLLOW, afterMatchSkipStrategy);
}
 
Example #11
Source File: Pattern.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a new pattern to the existing one. The new pattern enforces that there is no event matching this pattern
 * right after the preceding matched event.
 *
 * @param name Name of the new pattern
 * @return A new pattern which is appended to this one
 */
public Pattern<T, T> notNext(final String name) {
	if (quantifier.hasProperty(Quantifier.QuantifierProperty.OPTIONAL)) {
		throw new UnsupportedOperationException(
				"Specifying a pattern with an optional path to NOT condition is not supported yet. " +
				"You can simulate such pattern with two independent patterns, one with and the other without " +
				"the optional part.");
	}
	return new Pattern<>(name, this, ConsumingStrategy.NOT_NEXT, afterMatchSkipStrategy);
}
 
Example #12
Source File: Pattern.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a new pattern to the existing one. The new pattern enforces that there is no event matching this pattern
 * between the preceding pattern and succeeding this one.
 *
 * <p><b>NOTE:</b> There has to be other pattern after this one.
 *
 * @param name Name of the new pattern
 * @return A new pattern which is appended to this one
 */
public Pattern<T, T> notFollowedBy(final String name) {
	if (quantifier.hasProperty(Quantifier.QuantifierProperty.OPTIONAL)) {
		throw new UnsupportedOperationException(
				"Specifying a pattern with an optional path to NOT condition is not supported yet. " +
				"You can simulate such pattern with two independent patterns, one with and the other without " +
				"the optional part.");
	}
	return new Pattern<>(name, this, ConsumingStrategy.NOT_FOLLOW, afterMatchSkipStrategy);
}
 
Example #13
Source File: Pattern.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a new pattern to the existing one. The new pattern enforces that there is no event matching this pattern
 * right after the preceding matched event.
 *
 * @param name Name of the new pattern
 * @return A new pattern which is appended to this one
 */
public Pattern<T, T> notNext(final String name) {
	if (quantifier.hasProperty(Quantifier.QuantifierProperty.OPTIONAL)) {
		throw new UnsupportedOperationException(
				"Specifying a pattern with an optional path to NOT condition is not supported yet. " +
				"You can simulate such pattern with two independent patterns, one with and the other without " +
				"the optional part.");
	}
	return new Pattern<>(name, this, ConsumingStrategy.NOT_NEXT, afterMatchSkipStrategy);
}
 
Example #14
Source File: Pattern.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a new pattern to the existing one. The new pattern enforces that there is no event matching this pattern
 * right after the preceding matched event.
 *
 * @param name Name of the new pattern
 * @return A new pattern which is appended to this one
 */
public Pattern<T, T> notNext(final String name) {
	if (quantifier.hasProperty(Quantifier.QuantifierProperty.OPTIONAL)) {
		throw new UnsupportedOperationException(
				"Specifying a pattern with an optional path to NOT condition is not supported yet. " +
				"You can simulate such pattern with two independent patterns, one with and the other without " +
				"the optional part.");
	}
	return new Pattern<>(name, this, ConsumingStrategy.NOT_NEXT, afterMatchSkipStrategy);
}
 
Example #15
Source File: Pattern.java    From flink with Apache License 2.0 5 votes vote down vote up
protected Pattern(
	final String name,
	final Pattern<T, ? extends T> previous,
	final ConsumingStrategy consumingStrategy,
	final AfterMatchSkipStrategy afterMatchSkipStrategy) {
	this.name = name;
	this.previous = previous;
	this.quantifier = Quantifier.one(consumingStrategy);
	this.afterMatchSkipStrategy = afterMatchSkipStrategy;
}
 
Example #16
Source File: Pattern.java    From flink with Apache License 2.0 4 votes vote down vote up
private void checkIfNoNotPattern() {
	if (quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_FOLLOW ||
			quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_NEXT) {
		throw new MalformedPatternException("Option not applicable to NOT pattern");
	}
}
 
Example #17
Source File: Pattern.java    From flink with Apache License 2.0 4 votes vote down vote up
private void checkIfNoNotPattern() {
	if (quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_FOLLOW ||
			quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_NEXT) {
		throw new MalformedPatternException("Option not applicable to NOT pattern");
	}
}
 
Example #18
Source File: Pattern.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private void checkIfNoNotPattern() {
	if (quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_FOLLOW ||
			quantifier.getConsumingStrategy() == ConsumingStrategy.NOT_NEXT) {
		throw new MalformedPatternException("Option not applicable to NOT pattern");
	}
}
 
Example #19
Source File: Pattern.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Appends a new pattern to the existing one. The new pattern enforces non-strict
 * temporal contiguity. This means that a matching event of this pattern and the
 * preceding matching event might be interleaved with other events which are ignored.
 *
 * @param name Name of the new pattern
 * @return A new pattern which is appended to this one
 */
public Pattern<T, T> followedBy(final String name) {
	return new Pattern<>(name, this, ConsumingStrategy.SKIP_TILL_NEXT, afterMatchSkipStrategy);
}
 
Example #20
Source File: Pattern.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Appends a new pattern to the existing one. The new pattern enforces strict
 * temporal contiguity. This means that the whole pattern sequence matches only
 * if an event which matches this pattern directly follows the preceding matching
 * event. Thus, there cannot be any events in between two matching events.
 *
 * @param name Name of the new pattern
 * @return A new pattern which is appended to this one
 */
public Pattern<T, T> next(final String name) {
	return new Pattern<>(name, this, ConsumingStrategy.STRICT, afterMatchSkipStrategy);
}
 
Example #21
Source File: Pattern.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Appends a new pattern to the existing one. The new pattern enforces non-strict
 * temporal contiguity. This means that a matching event of this pattern and the
 * preceding matching event might be interleaved with other events which are ignored.
 *
 * @param name Name of the new pattern
 * @return A new pattern which is appended to this one
 */
public Pattern<T, T> followedByAny(final String name) {
	return new Pattern<>(name, this, ConsumingStrategy.SKIP_TILL_ANY, afterMatchSkipStrategy);
}
 
Example #22
Source File: Pattern.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Starts a new pattern sequence. The provided name is the one of the initial pattern
 * of the new sequence. Furthermore, the base type of the event sequence is set.
 *
 * @param name The name of starting pattern of the new pattern sequence
 * @param afterMatchSkipStrategy the {@link AfterMatchSkipStrategy.SkipStrategy} to use after each match.
 * @param <X> Base type of the event pattern
 * @return The first pattern of a pattern sequence
 */
public static <X> Pattern<X, X> begin(final String name, final AfterMatchSkipStrategy afterMatchSkipStrategy) {
	return new Pattern<X, X>(name, null, ConsumingStrategy.STRICT, afterMatchSkipStrategy);
}
 
Example #23
Source File: Pattern.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Starts a new pattern sequence. The provided pattern is the initial pattern
 * of the new sequence.
 *
 *
 * @param group the pattern to begin with
 * @param afterMatchSkipStrategy the {@link AfterMatchSkipStrategy.SkipStrategy} to use after each match.
 * @return The first pattern of a pattern sequence
 */
public static <T, F extends T> GroupPattern<T, F> begin(final Pattern<T, F> group, final AfterMatchSkipStrategy afterMatchSkipStrategy) {
	return new GroupPattern<>(null, group, ConsumingStrategy.STRICT, afterMatchSkipStrategy);
}
 
Example #24
Source File: Pattern.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Starts a new pattern sequence. The provided name is the one of the initial pattern
 * of the new sequence. Furthermore, the base type of the event sequence is set.
 *
 * @param name The name of starting pattern of the new pattern sequence
 * @param <X> Base type of the event pattern
 * @return The first pattern of a pattern sequence
 */
public static <X> Pattern<X, X> begin(final String name) {
	return new Pattern<>(name, null, ConsumingStrategy.STRICT, AfterMatchSkipStrategy.noSkip());
}
 
Example #25
Source File: Pattern.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Starts a new pattern sequence. The provided pattern is the initial pattern
 * of the new sequence.
 *
 * @param group the pattern to begin with
 * @return the first pattern of a pattern sequence
 */
public static <T, F extends T> GroupPattern<T, F> begin(Pattern<T, F> group) {
	return new GroupPattern<>(null, group, ConsumingStrategy.STRICT, AfterMatchSkipStrategy.noSkip());
}
 
Example #26
Source File: Pattern.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Appends a new group pattern to the existing one. The new pattern enforces non-strict
 * temporal contiguity. This means that a matching event of this pattern and the
 * preceding matching event might be interleaved with other events which are ignored.
 *
 * @param group the pattern to append
 * @return A new pattern which is appended to this one
 */
public GroupPattern<T, F> followedBy(Pattern<T, F> group) {
	return new GroupPattern<>(this, group, ConsumingStrategy.SKIP_TILL_NEXT, afterMatchSkipStrategy);
}
 
Example #27
Source File: Pattern.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Appends a new group pattern to the existing one. The new pattern enforces non-strict
 * temporal contiguity. This means that a matching event of this pattern and the
 * preceding matching event might be interleaved with other events which are ignored.
 *
 * @param group the pattern to append
 * @return A new pattern which is appended to this one
 */
public GroupPattern<T, F> followedByAny(Pattern<T, F> group) {
	return new GroupPattern<>(this, group, ConsumingStrategy.SKIP_TILL_ANY, afterMatchSkipStrategy);
}
 
Example #28
Source File: Pattern.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Starts a new pattern sequence. The provided pattern is the initial pattern
 * of the new sequence.
 *
 *
 * @param group the pattern to begin with
 * @param afterMatchSkipStrategy the {@link AfterMatchSkipStrategy.SkipStrategy} to use after each match.
 * @return The first pattern of a pattern sequence
 */
public static <T, F extends T> GroupPattern<T, F> begin(final Pattern<T, F> group, final AfterMatchSkipStrategy afterMatchSkipStrategy) {
	return new GroupPattern<>(null, group, ConsumingStrategy.STRICT, afterMatchSkipStrategy);
}
 
Example #29
Source File: Pattern.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Appends a new group pattern to the existing one. The new pattern enforces strict
 * temporal contiguity. This means that the whole pattern sequence matches only
 * if an event which matches this pattern directly follows the preceding matching
 * event. Thus, there cannot be any events in between two matching events.
 *
 * @param group the pattern to append
 * @return A new pattern which is appended to this one
 */
public GroupPattern<T, F> next(Pattern<T, F> group) {
	return new GroupPattern<>(this, group, ConsumingStrategy.STRICT, afterMatchSkipStrategy);
}
 
Example #30
Source File: Pattern.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Appends a new group pattern to the existing one. The new pattern enforces strict
 * temporal contiguity. This means that the whole pattern sequence matches only
 * if an event which matches this pattern directly follows the preceding matching
 * event. Thus, there cannot be any events in between two matching events.
 *
 * @param group the pattern to append
 * @return A new pattern which is appended to this one
 */
public GroupPattern<T, F> next(Pattern<T, F> group) {
	return new GroupPattern<>(this, group, ConsumingStrategy.STRICT, afterMatchSkipStrategy);
}