Esempio n. 1
0
  public void attach(final InternalWorkingMemory[] workingMemories) {
    attach();

    // we need to call updateSink on Rete, because someone
    // might have already added facts matching this ObjectTypeNode
    // to working memories
    for (int i = 0, length = workingMemories.length; i < length; i++) {
      final InternalWorkingMemory workingMemory = workingMemories[i];
      final PropagationContextImpl propagationContext =
          new PropagationContextImpl(
              workingMemory.getNextPropagationIdCounter(),
              PropagationContext.RULE_ADDITION,
              null,
              null,
              null);
      propagationContext.setEntryPoint(((EntryPointNode) this.source).getEntryPoint());
      this.source.updateSink(this, propagationContext, workingMemory);
    }
  }
Esempio n. 2
0
  /** @inheritDoc If an object is retract, call modify tuple for each tuple match. */
  public void retractRightTuple(
      final RightTuple rightTuple,
      final PropagationContext context,
      final InternalWorkingMemory workingMemory) {
    final AccumulateMemory memory = (AccumulateMemory) workingMemory.getNodeMemory(this);
    final InternalFactHandle origin = (InternalFactHandle) context.getFactHandleOrigin();
    if (context.getType() == PropagationContext.EXPIRATION) {
      ((PropagationContextImpl) context).setFactHandle(null);
    }

    BetaMemory bm = memory.getBetaMemory();

    if (isUnlinkingEnabled()) {

      StagedRightTuples stagedRightTuples = bm.getStagedRightTuples();
      switch (rightTuple.getStagedType()) {
          // handle clash with already staged entries
        case LeftTuple.INSERT:
          stagedRightTuples.removeInsert(rightTuple);
          break;
        case LeftTuple.UPDATE:
          stagedRightTuples.removeUpdate(rightTuple);
          break;
      }
      stagedRightTuples.addDelete(rightTuple);
      if (bm.getDecAndGetCounter() == 0 && !isRightInputIsRiaNode()) {
        bm.unlinkNode(workingMemory);
      }
      return;
    }

    bm.getRightTupleMemory().remove(rightTuple);

    removePreviousMatchesForRightTuple(
        rightTuple, context, workingMemory, memory, rightTuple.firstChild);

    if (context.getType() == PropagationContext.EXPIRATION) {
      ((PropagationContextImpl) context).setFactHandle(origin);
    }
  }