Esempio n. 1
0
  public static void writeLeftTuples(
      MarshallerWriteContext context, InternalFactHandle[] factHandles) throws IOException {
    ObjectOutputStream stream = context.stream;
    InternalWorkingMemory wm = context.wm;

    // Write out LeftTuples
    // context.out.println( "LeftTuples Start" );
    for (InternalFactHandle handle : factHandles) {
      // InternalFactHandle handle = (InternalFactHandle) it.next();

      for (LeftTuple leftTuple = handle.getFirstLeftTuple();
          leftTuple != null;
          leftTuple = (LeftTuple) leftTuple.getLeftParentNext()) {
        stream.writeShort(PersisterEnums.LEFT_TUPLE);
        int sinkId = leftTuple.getLeftTupleSink().getId();
        stream.writeInt(sinkId);
        stream.writeInt(handle.getId());

        // context.out.println( "LeftTuple sinkId:" + leftTuple.getLeftTupleSink().getId() + "
        // handleId:" + handle.getId() );
        writeLeftTuple(leftTuple, context, true);
      }
    }

    stream.writeShort(PersisterEnums.END);
    // context.out.println( "LeftTuples End" );
  }
Esempio n. 2
0
 /**
  * OTN needs to override remove to avoid releasing the node ID, since OTN are never removed from
  * the rulebase in the current implementation
  */
 protected void doRemove(
     final RuleRemovalContext context,
     final ReteooBuilder builder,
     final BaseNode node,
     final InternalWorkingMemory[] workingMemories) {
   if (context.getCleanupAdapter() != null) {
     for (InternalWorkingMemory workingMemory : workingMemories) {
       CleanupAdapter adapter = context.getCleanupAdapter();
       final ObjectHashSet memory = (ObjectHashSet) workingMemory.getNodeMemory(this);
       Iterator it = memory.iterator();
       for (ObjectEntry entry = (ObjectEntry) it.next();
           entry != null;
           entry = (ObjectEntry) it.next()) {
         InternalFactHandle handle = (InternalFactHandle) entry.getValue();
         for (LeftTuple leftTuple = handle.getFirstLeftTuple();
             leftTuple != null;
             leftTuple = leftTuple.getLeftParentNext()) {
           adapter.cleanUp(leftTuple, workingMemory);
         }
       }
     }
     context.setCleanupAdapter(null);
   }
   if (!node.isInUse()) {
     removeObjectSink((ObjectSink) node);
   }
 }
Esempio n. 3
0
  public static void writeInitialFactHandleLeftTuples(MarshallerWriteContext context)
      throws IOException {
    ObjectOutputStream stream = context.stream;

    // context.out.println( "InitialFact LeftTuples Start" );
    InternalFactHandle handle = context.wm.getInitialFactHandle();
    for (LeftTuple leftTuple = handle.getFirstLeftTuple();
        leftTuple != null;
        leftTuple = (LeftTuple) leftTuple.getLeftParentNext()) {
      stream.writeShort(PersisterEnums.LEFT_TUPLE);

      stream.writeInt(leftTuple.getLeftTupleSink().getId());
      // context.out.println( "LeftTuple sinkId:" + leftTuple.getLeftTupleSink().getId() );
      writeLeftTuple(leftTuple, context, true);
    }
    stream.writeShort(PersisterEnums.END);
    // context.out.println( "InitialFact LeftTuples End" );
  }
Esempio n. 4
0
  public void modifyActivation(
      final InternalFactHandle factHandle,
      final PropagationContext context,
      final InternalWorkingMemory workingMemory) {
    if (activationNode == null) {
      this.activationNode = objectTypeNodes.get(ClassObjectType.Activation_ObjectType);
    }

    if (activationNode != null) {
      ModifyPreviousTuples modifyPreviousTuples =
          new ModifyPreviousTuples(factHandle.getFirstLeftTuple(), factHandle.getFirstRightTuple());
      factHandle.clearLeftTuples();
      factHandle.clearRightTuples();

      // There may be no queries defined
      this.activationNode.modifyObject(factHandle, modifyPreviousTuples, context, workingMemory);
      modifyPreviousTuples.retractTuples(context, workingMemory);
    }
  }
Esempio n. 5
0
  /**
   * Retract the <code>FactHandleimpl</code> from the <code>Rete</code> network. Also remove the
   * <code>FactHandleImpl</code> from the node memory.
   *
   * @param rightTuple The fact handle.
   * @param object The object to assert.
   * @param workingMemory The working memory session.
   */
  public void retractObject(
      final InternalFactHandle factHandle,
      final PropagationContext context,
      final InternalWorkingMemory workingMemory) {
    if (objectMemoryEnabled && !(queryNode && !((DroolsQuery) factHandle.getObject()).isOpen())) {
      final ObjectHashSet memory = (ObjectHashSet) workingMemory.getNodeMemory(this);
      memory.remove(factHandle);
    }

    for (RightTuple rightTuple = factHandle.getFirstRightTuple();
        rightTuple != null;
        rightTuple = (RightTuple) rightTuple.getHandleNext()) {
      rightTuple.getRightTupleSink().retractRightTuple(rightTuple, context, workingMemory);
    }
    factHandle.clearRightTuples();

    for (LeftTuple leftTuple = factHandle.getFirstLeftTuple();
        leftTuple != null;
        leftTuple = (LeftTuple) leftTuple.getLeftParentNext()) {
      leftTuple.getLeftTupleSink().retractLeftTuple(leftTuple, context, workingMemory);
    }
    factHandle.clearLeftTuples();
  }
Esempio n. 6
0
  public void modifyObject(
      final InternalFactHandle handle,
      final PropagationContext context,
      final ObjectTypeConf objectTypeConf,
      final InternalWorkingMemory workingMemory) {
    // checks if shadow is enabled
    if (objectTypeConf.isShadowEnabled()) {
      // the user has implemented the ShadowProxy interface, let their implementation
      // know it is safe to update the information the engine can see.
      ((ShadowProxy) handle.getObject()).updateProxy();
    }

    ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();

    // make a reference to the previous tuples, then null then on the handle
    ModifyPreviousTuples modifyPreviousTuples =
        new ModifyPreviousTuples(handle.getFirstLeftTuple(), handle.getFirstRightTuple());
    handle.clearLeftTuples();
    handle.clearRightTuples();

    for (int i = 0, length = cachedNodes.length; i < length; i++) {
      cachedNodes[i].modifyObject(handle, modifyPreviousTuples, context, workingMemory);

      // remove any right tuples that matches the current OTN before continue the modify on the next
      // OTN cache entry
      if (i < cachedNodes.length - 1) {
        RightTuple rightTuple = modifyPreviousTuples.peekRightTuple();
        while (rightTuple != null
            && rightTuple.getRightTupleSink() instanceof BetaNode
            && ((BetaNode) rightTuple.getRightTupleSink()).getObjectTypeNode() == cachedNodes[i]) {
          modifyPreviousTuples.removeRightTuple();
          rightTuple = modifyPreviousTuples.peekRightTuple();
        }
      }
    }
    modifyPreviousTuples.retractTuples(context, workingMemory);
  }