Java Code Examples for org.apache.flink.cep.pattern.conditions.IterativeCondition#Context

The following examples show how to use org.apache.flink.cep.pattern.conditions.IterativeCondition#Context . 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: Expression.java    From flink-cep-dsl with Apache License 2.0 5 votes vote down vote up
public boolean matches(Event event, IterativeCondition.Context<Event> context) {
    try {
        Object attribute = event.getAttribute(this.attribute).orElseThrow((Supplier<Throwable>) () -> new RuntimeException("Attribute does not exiyt"));
        return operator.evaluate(attribute, getValue(context));
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    }
}
 
Example 2
Source File: Expression.java    From flink-cep-dsl with Apache License 2.0 5 votes vote down vote up
private Object getValue(IterativeCondition.Context<Event> context) {
   if (Strings.isNullOrEmpty(valueClassIdentifier) || Strings.isNullOrEmpty(valueAttribute)) {
       return value;
   }
   try {
       List<Event> contextEvents = Lists.newArrayList(context.getEventsForPattern(valueClassIdentifier));
       if (contextEvents.size() > 0) {
           Event first = contextEvents.get(0);
           return first.getAttribute(valueAttribute).orElseThrow((Supplier<Throwable>) () -> new RuntimeException("Attribute does not exist"));
       }
   } catch (Throwable throwable) {
       throw new RuntimeException(throwable);
   }
   return null;
}
 
Example 3
Source File: AggregatingContextMatcher.java    From flink-cep-dsl with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluate the event and compare it with the context.
 * @param event The event which should be matched
 * @param context The context of the CEP engine which provides events already matched.
 * @return True if the event matches according to its context, otherwise false.
 */
@Override
public boolean matches(Event event, IterativeCondition.Context<Event> context) {
    if (isAnd) {
        return this.stream().allMatch(k -> k.matches(event, context));
    }
    else {
        return this.stream().anyMatch(k -> k.matches(event, context));
    }
}
 
Example 4
Source File: ContextMatcher.java    From flink-cep-dsl with Apache License 2.0 2 votes vote down vote up
/**
 * Evaluate the event and compare it with the context.
 * @param event The event which should be matched
 * @param context The context of the CEP engine which provides events already matched.
 * @return True if the event matches according to its context, otherwise false.
 */
boolean matches(Event event, IterativeCondition.Context<Event> context);