public void doPropagateAssertLeftTuple(
     PropagationContext context,
     InternalWorkingMemory workingMemory,
     LeftTuple leftTuple,
     LeftTupleSink sink) {
   sink.assertLeftTuple(leftTuple, context, workingMemory);
 }
 /**
  * This is a hook method that may be overriden by subclasses. Please keep it protected.
  *
  * @param context
  * @param workingMemory
  * @param leftTuple
  * @param sink
  */
 protected void doPropagateRetractLeftTuple(
     PropagationContext context,
     InternalWorkingMemory workingMemory,
     LeftTuple leftTuple,
     LeftTupleSink sink) {
   sink.retractLeftTuple(leftTuple, context, workingMemory);
 }
 public void doPropagateModifyObject(
     InternalFactHandle factHandle,
     ModifyPreviousTuples modifyPreviousTuples,
     PropagationContext context,
     InternalWorkingMemory workingMemory,
     LeftTupleSink sink) {
   sink.modifyLeftTuple(factHandle, modifyPreviousTuples, context, workingMemory);
 }
 protected void doPropagateRetractLeftTuple(
     PropagationContext context,
     InternalWorkingMemory workingMemory,
     LeftTuple leftTuple,
     LeftTupleSink sink) {
   // composite propagators need to check each node to decide if the propagation
   // must be asynchronous or may eventually be synchronous
   if (this.partitionId.equals(sink.getPartitionId())) {
     // same partition, so synchronous propagation is fine
     sink.retractLeftTuple(leftTuple, context, workingMemory);
   } else {
     // different partition, so use asynchronous propagation
     PartitionTaskManager manager = workingMemory.getPartitionTaskManager(this.partitionId);
     manager.enqueue(
         new PartitionTaskManager.LeftTupleRetractAction(
             leftTuple, context, sink, Action.PRIORITY_HIGH));
   }
 }
예제 #5
0
  /** Updates the given sink propagating all previously propagated tuples to it */
  public void updateSink(
      final LeftTupleSink sink,
      final PropagationContext context,
      final InternalWorkingMemory workingMemory) {
    final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory(this);
    Iterator it = memory.getRightTupleMemory().iterator();

    // Relies on the fact that any propagated LeftTuples are blocked, but due to lazy blocking
    // they will only be blocked once. So we can iterate the right memory to find the left tuples to
    // propagate
    for (RightTuple rightTuple = (RightTuple) it.next();
        rightTuple != null;
        rightTuple = (RightTuple) it.next()) {
      LeftTuple leftTuple = rightTuple.getBlocked();
      while (leftTuple != null) {
        sink.assertLeftTuple(sink.createLeftTuple(leftTuple, sink, true), context, workingMemory);
        leftTuple = leftTuple.getBlockedNext();
      }
    }
  }
  public static void doModifyLeftTuple(
      InternalFactHandle factHandle,
      ModifyPreviousTuples modifyPreviousTuples,
      PropagationContext context,
      InternalWorkingMemory workingMemory,
      LeftTupleSink sink,
      ObjectTypeNode.Id leftInputOtnId,
      BitMask leftInferredMask) {
    LeftTuple leftTuple = modifyPreviousTuples.peekLeftTuple();
    while (leftTuple != null
        && leftTuple.getLeftTupleSink().getLeftInputOtnId() != null
        && leftTuple.getLeftTupleSink().getLeftInputOtnId().before(leftInputOtnId)) {
      modifyPreviousTuples.removeLeftTuple();

      // we skipped this node, due to alpha hashing, so retract now
      ((LeftInputAdapterNode) leftTuple.getLeftTupleSink().getLeftTupleSource())
          .retractLeftTuple(leftTuple, context, workingMemory);

      leftTuple = modifyPreviousTuples.peekLeftTuple();
    }

    if (leftTuple != null
        && leftTuple.getLeftTupleSink().getLeftInputOtnId() != null
        && leftTuple.getLeftTupleSink().getLeftInputOtnId().equals(leftInputOtnId)) {
      modifyPreviousTuples.removeLeftTuple();
      leftTuple.reAdd();
      if (context.getModificationMask().intersects(leftInferredMask)) {
        // LeftTuple previously existed, so continue as modify, unless it's currently staged
        sink.modifyLeftTuple(leftTuple, context, workingMemory);
      }
    } else {
      if (context.getModificationMask().intersects(leftInferredMask)) {
        // LeftTuple does not exist, so create and continue as assert
        LeftTuple newLeftTuple = sink.createLeftTuple(factHandle, sink, true);

        sink.assertLeftTuple(newLeftTuple, context, workingMemory);
      }
    }
  }
예제 #7
0
  public void updateSink(
      final LeftTupleSink sink,
      final PropagationContext context,
      final InternalWorkingMemory workingMemory) {
    final AccumulateMemory memory = (AccumulateMemory) workingMemory.getNodeMemory(this);

    final Iterator tupleIter = memory.betaMemory.getLeftTupleMemory().iterator();
    for (LeftTuple leftTuple = (LeftTuple) tupleIter.next();
        leftTuple != null;
        leftTuple = (LeftTuple) tupleIter.next()) {
      AccumulateContext accctx = (AccumulateContext) leftTuple.getObject();
      if (accctx.propagated) {
        // temporarily break the linked list to avoid wrong interactions
        LeftTuple[] matchings = splitList(leftTuple, accctx, true);
        sink.assertLeftTuple(
            sink.createLeftTuple(leftTuple, accctx.result, null, null, sink, true),
            context,
            workingMemory);
        restoreList(leftTuple, matchings);
      }
    }
  }
예제 #8
0
  public void updateSink(
      final LeftTupleSink sink,
      final PropagationContext context,
      final InternalWorkingMemory workingMemory) {
    LeftTupleIterator it = LeftTupleIterator.iterator(workingMemory, this);

    for (LeftTuple leftTuple = (LeftTuple) it.next();
        leftTuple != null;
        leftTuple = (LeftTuple) it.next()) {
      LeftTuple childLeftTuple = leftTuple.getFirstChild();
      while (childLeftTuple != null) {
        RightTuple rightParent = childLeftTuple.getRightParent();
        sink.assertLeftTuple(
            sink.createLeftTuple(leftTuple, rightParent, childLeftTuple, null, sink, true),
            context,
            workingMemory);

        while (childLeftTuple != null && childLeftTuple.getRightParent() == rightParent) {
          // skip to the next child that has a different right parent
          childLeftTuple = childLeftTuple.getLeftParentNext();
        }
      }
    }
  }
예제 #9
0
 public RuleBasePartitionId getPartitionId() {
   return sink.getPartitionId();
 }
예제 #10
0
 public final void setPartitionIdWithSinks(RuleBasePartitionId partitionId) {
   this.partitionId = partitionId;
   for (LeftTupleSink sink : getSinkPropagator().getSinks()) {
     sink.setPartitionIdWithSinks(partitionId);
   }
 }