Ejemplo n.º 1
0
  /**
   * Fire the next scheduled <code>Agenda</code> item, skipping items that are not allowed by the
   * agenda filter.
   *
   * @return true if an activation was fired. false if no more activations to fire
   * @throws org.drools.core.spi.ConsequenceException If an error occurs while firing an agenda
   *     item.
   */
  public int fireNextItem(final AgendaFilter filter, int fireCount, int fireLimit)
      throws ConsequenceException {
    boolean tryagain;
    int localFireCount = 0;
    try {
      do {
        evaluateEagerList();
        this.workingMemory.prepareToFireActivation();
        tryagain = false;
        final InternalAgendaGroup group = (InternalAgendaGroup) getNextFocus();
        // if there is a group with focus
        if (group != null) {
          final AgendaItem item = (AgendaItem) group.remove();
          // if there is an item to fire from that group
          if (item != null) {
            // if that item is allowed to fire
            if (filter == null || filter.accept(item)) {
              // fire it
              fireActivation(item);
              localFireCount++;
            } else {
              // otherwise cancel it and try the next

              // necessary to perfom queued actions like signal to a next node in a ruleflow/jbpm
              // process
              this.workingMemory.executeQueuedActions();

              final EventSupport eventsupport = (EventSupport) this.workingMemory;
              eventsupport
                  .getAgendaEventSupport()
                  .fireActivationCancelled(item, this.workingMemory, MatchCancelledCause.FILTER);
              tryagain = true;
            }
          }
          if ((AgendaItem) group.peek() == null
              || !((AgendaItem) group.peek()).getTerminalNode().isFireDirect()) {
            // make sure the "fireDirect" meta rules have all impacted first, before unstaging.
            unstageActivations();
          }
        }
      } while (tryagain);
    } finally {
      this.workingMemory.activationFired();
    }
    return localFireCount;
  }
Ejemplo n.º 2
0
  private boolean cancelAndContinue(
      InternalWorkingMemory wm,
      RuleTerminalNode rtn,
      RuleImpl rule,
      LeftTuple leftTuple,
      PropagationContext pctx,
      AgendaFilter filter) {
    // NB. stopped setting the LT.object to Boolean.TRUE, that Reteoo did.
    if (!rule.isEffective(leftTuple, rtn, wm)) {
      return true;
    }

    if (rule.getCalendars() != null) {
      long timestamp = wm.getSessionClock().getCurrentTime();
      for (String cal : rule.getCalendars()) {
        if (!wm.getCalendars().get(cal).isTimeIncluded(timestamp)) {
          return true;
        }
      }
    }

    return filter != null && !filter.accept((Activation) leftTuple);
  }