Пример #1
0
  public void closeLiveQuery(final InternalFactHandle factHandle) {

    try {
      startOperation();
      this.ruleBase.readLock();
      this.lock.lock();

      final PropagationContext pCtx =
          new PropagationContextImpl(
              getNextPropagationIdCounter(),
              PropagationContext.INSERTION,
              null,
              null,
              factHandle,
              getEntryPoint());

      if (this.ruleBase.getConfiguration().isPhreakEnabled()) {
        LeftInputAdapterNode lian =
            (LeftInputAdapterNode)
                factHandle.getFirstLeftTuple().getLeftTupleSink().getLeftTupleSource();
        LiaNodeMemory lmem = (LiaNodeMemory) getNodeMemory((MemoryFactory) lian);
        SegmentMemory lsmem = lmem.getSegmentMemory();

        LeftTuple childLeftTuple =
            factHandle.getFirstLeftTuple(); // there is only one, all other LTs are peers
        LeftInputAdapterNode.doDeleteObject(
            childLeftTuple, childLeftTuple.getPropagationContext(), lsmem, this, lian, false, lmem);

        List<PathMemory> rmems = lmem.getSegmentMemory().getPathMemories();
        for (int i = 0, length = rmems.size(); i < length; i++) {
          PathMemory rm = rmems.get(i);

          RuleNetworkEvaluatorActivation evaluator =
              agenda.createRuleNetworkEvaluatorActivation(
                  Integer.MAX_VALUE, rm, (TerminalNode) rm.getNetworkNode());
          evaluator.evaluateNetwork(this, 0, -1);
        }
      } else {
        getEntryPointNode().retractQuery(factHandle, pCtx, this);

        pCtx.evaluateActionQueue(this);
      }

      getFactHandleFactory().destroyFactHandle(factHandle);

    } finally {
      this.lock.unlock();
      this.ruleBase.readUnlock();
      endOperation();
    }
  }
Пример #2
0
  private BaseNode[] evalQuery(
      String queryName,
      DroolsQuery queryObject,
      InternalFactHandle handle,
      PropagationContext pCtx) {
    BaseNode[] tnodes = (BaseNode[]) ruleBase.getReteooBuilder().getTerminalNodes(queryName);
    if (this.ruleBase.getConfiguration().isPhreakEnabled()) {
      if (tnodes == null) {
        throw new RuntimeException("Query '" + queryName + "' does not exist");
      }

      QueryTerminalNode tnode = (QueryTerminalNode) tnodes[0];
      LeftTupleSource lts = tnode.getLeftTupleSource();
      while (lts.getType() != NodeTypeEnums.LeftInputAdapterNode) {
        lts = lts.getLeftTupleSource();
      }
      LeftInputAdapterNode lian = (LeftInputAdapterNode) lts;
      LiaNodeMemory lmem = (LiaNodeMemory) getNodeMemory((MemoryFactory) lts);
      SegmentMemory lsmem = lmem.getSegmentMemory();
      if (lsmem == null) {
        lsmem = SegmentUtilities.createSegmentMemory(lts, this);
      }
      LeftInputAdapterNode.doInsertObject(
          handle, pCtx, lian, this, lmem, false, queryObject.isOpen());

      List<PathMemory> rmems = lmem.getSegmentMemory().getPathMemories();
      for (int i = 0, length = rmems.size(); i < length; i++) {
        PathMemory rm = rmems.get(i);

        RuleNetworkEvaluatorActivation evaluator =
            agenda.createRuleNetworkEvaluatorActivation(
                Integer.MAX_VALUE, rm, (TerminalNode) rm.getNetworkNode());
        evaluator.evaluateNetwork(this, 0, -1);
      }
    } else {
      // no need to call retract, as no leftmemory used.
      getEntryPointNode().assertQuery(handle, pCtx, this);

      pCtx.evaluateActionQueue(this);
    }
    return tnodes;
  }