Class BaseRule

java.lang.Object
com.helixframework.rules.rule.BaseRule
All Implemented Interfaces:
Rule
Direct Known Subclasses:
JavaRule, RestRule, SpelRule

public abstract class BaseRule extends Object implements Rule
Base rule that provides a default timeout for rule subclasses.
  • Constructor Details

    • BaseRule

      public BaseRule(String name, String classification, Set<Rule> dependencies, String description, Map<String,String> tags, Duration timeout, Integer maxRetries)
      Creates a new instance of BaseRule.
      Parameters:
      name - rule name
      classification - rule classification
      dependencies - rule dependencies
      description - rule description
      tags - rule tags
      timeout - rule timeout
      maxRetries - rule max retry count
  • Method Details

    • applyInternal

      protected abstract void applyInternal(RuleContext<?> ctx)
      Applies the logic of the implementing rule and modifies the root object in the context.
      Parameters:
      ctx - rule context
    • applyInternal

      protected abstract <T> T applyInternal(RuleContext<?> ctx, Class<T> outputType)
      Applies the logic of the implementing rule and returns the result.
      Type Parameters:
      T - type of rule output
      Parameters:
      ctx - rule context
      outputType - type of rule output
      Returns:
      rule result
    • apply

      public void apply(RuleContext<?> ctx)
      Description copied from interface: Rule
      Executes the rule with a default timeout.
      Specified by:
      apply in interface Rule
      Parameters:
      ctx - rule context
    • apply

      public void apply(RuleContext<?> ctx, Duration timeout)
      Description copied from interface: Rule
      Executes the rule with a custom timeout.
      Specified by:
      apply in interface Rule
      Parameters:
      ctx - rule context
      timeout - timeout
    • apply

      public <T> T apply(RuleContext<?> ctx, Class<T> outputType)
      Description copied from interface: Rule
      Executes the rules and returns a result.
      Specified by:
      apply in interface Rule
      Type Parameters:
      T - return type
      Parameters:
      ctx - rule contect
      outputType - rule output type
      Returns:
      result of rule
    • apply

      public <T> T apply(RuleContext<?> ctx, Class<T> outputType, Duration timeout)
      Description copied from interface: Rule
      Executes the rules, with a custom timeout, and returns a result.
      Specified by:
      apply in interface Rule
      Type Parameters:
      T - return type
      Parameters:
      ctx - rule context
      outputType - rule output type
      timeout - timeout
      Returns:
      result of rule
    • getName

      public String getName()
      Description copied from interface: Rule
      Gets the name of the rule.
      Specified by:
      getName in interface Rule
      Returns:
      rule name
    • getClassification

      public String getClassification()
      Description copied from interface: Rule
      Gets the classification of the rule.
      Specified by:
      getClassification in interface Rule
      Returns:
      rule classification
    • getDependencies

      public Set<Rule> getDependencies()
      Description copied from interface: Rule
      Gets a set of rules for which this rule depends upon.
      Specified by:
      getDependencies in interface Rule
      Returns:
      rule dependencies
    • getDescription

      public String getDescription()
      Description copied from interface: Rule
      Gets the description of the rule.
      Specified by:
      getDescription in interface Rule
      Returns:
      rule description
    • getTags

      public Map<String,String> getTags()
      Description copied from interface: Rule
      Gets the rule's tags.
      Specified by:
      getTags in interface Rule
      Returns:
      rule tags
    • getTimeout

      public Duration getTimeout()
      Description copied from interface: Rule
      Gets the timeout.
      Specified by:
      getTimeout in interface Rule
      Returns:
      timeout
    • getMaxRetries

      public Integer getMaxRetries()
      Description copied from interface: Rule
      Gets the number of times the rule should be retried in the event of a failure.
      Specified by:
      getMaxRetries in interface Rule
      Returns:
      max retries