Interface RuleManager


@NonNullByDefault public interface RuleManager
This class is responsible to provide a RegistryChangeListener logic. An instance of it is added to RuleRegistry service, to listen for changes when a single Rule has been added, updated, enabled, disabled or removed and to involve Rule Engine to process these changes. Also to send a run command for a single Rule to the Rule Engine.
Author:
Kai Kreuzer - Initial contribution
  • Method Details

    • isEnabled

      @Nullable Boolean isEnabled(String ruleUID)
      This method gets enabled RuleStatus for a Rule. The enabled rule statuses are RuleStatus.UNINITIALIZED, RuleStatus.IDLE and RuleStatus.RUNNING. The disabled rule status is RuleStatus.UNINITIALIZED with RuleStatusDetail.DISABLED.
      Parameters:
      ruleUID - UID of the Rule
      Returns:
      true when the RuleStatus is one of the RuleStatus.UNINITIALIZED with any other RuleStatusDetail than RuleStatusDetail.DISABLED, RuleStatus.IDLE and RuleStatus.RUNNING, false when it is RuleStatus.UNINITIALIZED with RuleStatusDetail.DISABLED and null when it is not available.
    • setEnabled

      void setEnabled(String uid, boolean isEnabled)
      This method is used for changing enabled state of the Rule. The enabled rule statuses are RuleStatus.UNINITIALIZED, RuleStatus.IDLE and RuleStatus.RUNNING. The disabled rule status is RuleStatus.UNINITIALIZED with RuleStatusDetail.DISABLED.
      Parameters:
      uid - the unique identifier of the Rule.
      isEnabled - a new enabled / disabled state of the Rule.
    • getStatusInfo

      @Nullable RuleStatusInfo getStatusInfo(String ruleUID)
      This method gets RuleStatusInfo of the specified Rule.
      Parameters:
      ruleUID - UID of the Rule
      Returns:
      RuleStatusInfo object containing status of the looking Rule or null when a rule with specified UID does not exist.
    • getStatus

      @Nullable RuleStatus getStatus(String ruleUID)
      Utility method which gets RuleStatus of the specified Rule.
      Parameters:
      ruleUID - UID of the Rule
      Returns:
      RuleStatus object containing status of the looking Rule or null when a rule with specified UID does not exist.
    • runNow

      Map<String,@Nullable Object> runNow(String uid)
      The method skips the triggers and the conditions and directly executes the actions of the rule. This should always be possible unless an action has a mandatory input that is linked to a trigger. In that case the action is skipped and the rule engine continues execution of rest actions.
      Parameters:
      uid - id of the rule whose actions have to be executed.
      Returns:
      a copy of the rule context, including possible return values
    • runNow

      Map<String,@Nullable Object> runNow(String uid, boolean considerConditions, @Nullable Map<String,@Nullable Object> context)
      Same as runNow(String) with the additional option to enable/disable evaluation of conditions defined in the target rule. The context can be set here, too, but also might be null.
      Parameters:
      uid - id of the rule whose actions have to be executed.
      considerConditions - if true the conditions of the rule will be checked.
      context - the context that is passed to the conditions and the actions of the rule.
      Returns:
      a copy of the rule context, including possible return values
    • runAsync

      default Future<Map<String,@Nullable Object>> runAsync(String ruleUID)
      The method skips triggers and conditions and executes the actions of the rule asynchronously. This should always be possible unless an action has a mandatory input that is linked to a trigger. In that case the action is skipped and the rule engine continues execution of remaining actions.

      Note: Unlike runNow(String), this method will return immediately. To wait for the execution to be completed, call Future.get() on the returned Future.

      Parameters:
      ruleUID - uid of the rule whose actions should be executed.
      Returns:
      A Future containing the copy of the rule context after completion, including possible return values.
      Throws:
      UnsupportedOperationException - If asynchronous execution isn't supported by the RuleManager implementation.
      Implementation note:
      The default implementation simply calls runAsync(String, boolean, Map).
    • runAsync

      default Future<Map<String,@Nullable Object>> runAsync(String ruleUID, boolean considerConditions, @Nullable Map<String,@Nullable Object> context)
      Same as runAsync(String) with the additional option to enable/disable evaluation of conditions defined in the target rule. The context can be set here, too, but might also be null.

      Note: Unlike runNow(String, boolean, Map), this method will return immediately. To wait for the execution to be completed, call Future.get() on the returned Future.

      Parameters:
      ruleUID - uid of the rule whose actions should be executed.
      considerConditions - if true the conditions of the rule will be checked.
      context - the context that is passed to the conditions and the actions of the rule.
      Returns:
      a copy of the rule context, including possible return values
      Throws:
      UnsupportedOperationException - If asynchronous execution isn't supported by the RuleManager implementation.
      Implementation note:
      The default implementation throws an UnsupportedOperationException.
    • simulateRuleExecutions

      Stream<RuleExecution> simulateRuleExecutions(ZonedDateTime from, ZonedDateTime until)
      Simulates the execution of all rules with tag 'Schedule' for the given time interval. The result is sorted ascending by execution time.
      Parameters:
      from - ZonedDateTime earliest time to be contained in the rule simulation.
      until - ZonedDateTime latest time to be contained in the rule simulation.
      Returns:
      A Stream with all expected RuleExecution.