Exemplo n.º 1
0
  public void updateSink(
      final ObjectSink sink,
      final PropagationContext context,
      final InternalWorkingMemory workingMemory) {
    // @todo
    // JBRULES-612: the cache MUST be invalidated when a new node type is added to the network, so
    // iterate and reset all caches.
    final ObjectTypeNode node = (ObjectTypeNode) sink;

    final ObjectType newObjectType = node.getObjectType();

    InternalWorkingMemoryEntryPoint wmEntryPoint =
        (InternalWorkingMemoryEntryPoint)
            workingMemory.getWorkingMemoryEntryPoint(this.entryPoint.getEntryPointId());

    for (ObjectTypeConf objectTypeConf :
        wmEntryPoint.getObjectTypeConfigurationRegistry().values()) {
      if (newObjectType.isAssignableFrom(
          objectTypeConf.getConcreteObjectTypeNode().getObjectType())) {
        objectTypeConf.resetCache();
        ObjectTypeNode sourceNode = objectTypeConf.getConcreteObjectTypeNode();
        Iterator it =
            ((ObjectTypeNodeMemory) workingMemory.getNodeMemory(sourceNode)).memory.iterator();
        for (ObjectEntry entry = (ObjectEntry) it.next();
            entry != null;
            entry = (ObjectEntry) it.next()) {
          sink.assertObject((InternalFactHandle) entry.getValue(), context, workingMemory);
        }
      }
    }
  }
Exemplo n.º 2
0
 public void dispose() {
   if (dynamicFacts != null) {
     // first we check for facts that were inserted into the working memory
     // using the old API and setting a per instance dynamic flag and remove the
     // session from the listeners list in the bean
     for (InternalFactHandle handle : dynamicFacts) {
       removePropertyChangeListener(handle, false);
     }
     dynamicFacts = null;
   }
   for (ObjectTypeConf conf : this.typeConfReg.values()) {
     // then, we check if any of the object types were configured using the
     // @propertyChangeSupport annotation, and clean them up
     if (conf.isDynamic() && conf.isSupportsPropertyChangeListeners()) {
       // it is enough to iterate the facts on the concrete object type nodes
       // only, as the facts will always be in their concrete object type nodes
       // even if they were also asserted into higher level OTNs as well
       ObjectTypeNode otn = conf.getConcreteObjectTypeNode();
       final ObjectHashSet memory =
           ((ObjectTypeNodeMemory) this.getInternalWorkingMemory().getNodeMemory(otn)).memory;
       Iterator it = memory.iterator();
       for (ObjectEntry entry = (ObjectEntry) it.next();
           entry != null;
           entry = (ObjectEntry) it.next()) {
         InternalFactHandle handle = (InternalFactHandle) entry.getValue();
         removePropertyChangeListener(handle, false);
       }
     }
   }
 }
Exemplo n.º 3
0
  /**
   * When L&R Unlinking is enabled, updateSink() is used to populate a node's memory, but it has to
   * take into account if it's propagating.
   */
  private void updateLRUnlinking(
      final ObjectSink sink,
      final PropagationContext context,
      final InternalWorkingMemory workingMemory) {

    final ObjectHashSet memory = (ObjectHashSet) workingMemory.getNodeMemory(this);

    Iterator it = memory.iterator();

    InternalFactHandle ctxHandle = (InternalFactHandle) context.getFactHandle();

    if (!context.isPropagating(this)
        || (context.isPropagating(this) && context.shouldPropagateAll())) {

      for (ObjectEntry entry = (ObjectEntry) it.next();
          entry != null;
          entry = (ObjectEntry) it.next()) {
        // Assert everything
        sink.assertObject((InternalFactHandle) entry.getValue(), context, workingMemory);
      }

    } else {

      for (ObjectEntry entry = (ObjectEntry) it.next();
          entry != null;
          entry = (ObjectEntry) it.next()) {
        InternalFactHandle handle = (InternalFactHandle) entry.getValue();
        // Exclude the current fact propagation
        if (handle.getId() != ctxHandle.getId()) {
          sink.assertObject(handle, context, workingMemory);
        }
      }
    }
  }
Exemplo n.º 4
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);
   }
 }
Exemplo n.º 5
0
  public void updateSink(
      final ObjectSink sink,
      final PropagationContext context,
      final InternalWorkingMemory workingMemory) {
    if (lrUnlinkingEnabled) {
      // Update sink taking into account L&R unlinking peculiarities
      updateLRUnlinking(sink, context, workingMemory);

    } else {
      // Regular updateSink
      final ObjectHashSet memory = (ObjectHashSet) workingMemory.getNodeMemory(this);
      Iterator it = memory.iterator();

      for (ObjectEntry entry = (ObjectEntry) it.next();
          entry != null;
          entry = (ObjectEntry) it.next()) {
        sink.assertObject((InternalFactHandle) entry.getValue(), context, workingMemory);
      }
    }
  }