Beispiel #1
0
  private void runStartupRules() {
    if (triggerManager != null) {
      Iterable<Rule> startupRules = triggerManager.getRules(STARTUP);
      List<Rule> executedRules = Lists.newArrayList();

      for (Rule rule : startupRules) {
        try {
          Script script = scriptEngine.newScriptFromXExpression(rule.getScript());
          logger.debug("Executing startup rule '{}'", rule.getName());
          RuleEvaluationContext context = new RuleEvaluationContext();
          context.setGlobalContext(RuleContextHelper.getContext(rule));
          script.execute(context);
          executedRules.add(rule);
        } catch (ScriptExecutionException e) {
          String causeMessage = getCauseMessage(e);
          if (e.getCause() instanceof ItemNotFoundException
              || causeMessage.contains("cannot be resolved to an item or type")) {
            logger.debug(
                "Not all required items in place yet for rule {}, trying again later: {}",
                new Object[] {rule.getName(), causeMessage});
            // we do not seem to have all required items in place yet
            // so we keep the rule in the list and try it again later
          } else {
            logger.error(
                "Error during the execution of startup rule '{}': {}",
                new Object[] {rule.getName(), causeMessage});
            executedRules.add(rule);
          }
        }
      }
      for (Rule rule : executedRules) {
        triggerManager.removeRule(STARTUP, rule);
      }
    }
  }
Beispiel #2
0
  protected synchronized void executeRule(Rule rule, RuleEvaluationContext context) {
    Script script = scriptEngine.newScriptFromXExpression(rule.getScript());

    logger.debug("Executing rule '{}'", rule.getName());

    context.setGlobalContext(RuleContextHelper.getContext(rule));

    ScriptExecutionThread thread = new ScriptExecutionThread(rule.getName(), script, context);
    thread.start();
  }