Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
/**
 * Base class for a rule definition.
 *
 * <p>A rule defines a {@link Pattern}, how to match the pattern, and how to process the found
 * matches.
 *
 * @param <IN> Base type of the elements appearing in the pattern.
 * @param <OUT> Type of produced elements based on found matches.
 */
@PublicEvolving
public interface Rule<IN, OUT> extends Serializable, Versioned {
    /**
     * Returns the ID of the rule.
     *
     * @return The ID of the rule.
     */
    String getId();

    /**
     * Returns the scheduled time at which the rule should come into effective.
     *
     * <p>If the scheduled time is earlier than current event/processing time, the rule will
     * immediately become effective.
     *
     * <p>If the rule should always become effective immediately, the scheduled time can be set to
     * {@code Long.MIN_VALUE}: {@value Long#MIN_VALUE}.
     *
     * @return The scheduled time.
     */
    default Long getScheduledTimegetTimestamp() {
        return Long.MIN_VALUE;
    }

    /**
     * Returns the {@link Pattern} to be matched.
     *
     * @return The pattern of the rule.
     */
    Pattern<IN, ?> getPattern();

    /**
     * Returns the {@link KeySelector} to extract the key of the elements appearing in the pattern.
     *
     * <p>Only data with the same key can be chained to match a pattern. If extracted key is null,
     * the behavior is to reuse current key if is {@link KeyedStream}, or allocate the same key for
     * all input data if is not {@link KeyedStream}.
     *
     * @return The key selector of the rule.
     */
    @Nullable
    KeySelector<IN, ?> getKeySelector();

    /**
     * Get the {@link PatternProcessFunction} to process the found matches for the pattern.
     *
     * @return The pattern process function of the rule.
     */
    PatternProcessFunction<IN, OUT> getPatternProcessFunction();
}

...

Code Block
public class DummyRule implements Rule<Event, Object> {
    
    public DummyRule(int a) {...}

    @Override
    public String getId() {...}
    
    @Override
    public int getVersion() {...}

    @Override
    public Pattern<Event, ?> getPattern() {...}

    @Nullable
    @Override
    public KeySelector<Event, ?> getKeySelector() {...}

    @Override
    public PatternProcessFunction<Event, Object> getPatternProcessFunction() {...}
}

It is recommended that users override the implementations' toString(), equals(), and hashCode() methods. Overriding toString() provides better readability when monitoring the rules through logs, and overriding equals() and hashCode() can help to avoid reloading existing rules during a rule update.

In order to use PeriodDBRuleDiscoverer, users need to create an instance of PeriodDBRuleDiscovererFactory.

...

In order to make the behavior of rule updates more deterministic, users can schedule the time at which an updated rule should come into effect, which is reflected by the getScheduledTimegetTimestamp() method in Rule .

When a new set of rules is provided by RuleDiscoverer , they will first be cached in operators. When a watermark arrived at the operator, it will check the timestamp of the watermark against the scheduled time of cached rules and update rules accordingly.

...