示例#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, injector));
          script.execute(context);
          executedRules.add(rule);
        } catch (ScriptExecutionException e) {
          if (!e.getMessage().contains("cannot be resolved to an item or type")) {
            logger.error(
                "Error during the execution of startup rule '{}': {}",
                new Object[] {rule.getName(), e.getCause().getMessage()});
            executedRules.add(rule);
          } else {
            logger.debug(
                "Execution of startup rule '{}' has been postponed as items are still missing.",
                rule.getName());
          }
        }
      }
      for (Rule rule : executedRules) {
        triggerManager.removeRule(STARTUP, rule);
      }
    }
  }
示例#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, injector));

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