Skip to content

Commit

Permalink
Use specific iterator for TMS, everything else is an AbstractTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
lucamolteni committed Sep 4, 2023
1 parent 4bdfc45 commit f5575bf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.drools.core.reteoo.LeftTuple;
import org.drools.core.reteoo.ObjectTypeNode;
import org.drools.core.reteoo.RightTuple;
import org.drools.core.reteoo.RightTupleImpl;
import org.drools.core.reteoo.Tuple;
import org.drools.core.util.AbstractBaseLinkedListNode;
import org.drools.util.StringUtils;
Expand Down Expand Up @@ -629,8 +630,8 @@ public void addLastRightTuple( RightTuple rightTuple ) {

@Override
public void removeRightTuple( RightTuple rightTuple ) {
RightTuple previous = rightTuple.getHandlePrevious();
RightTuple next = rightTuple.getHandleNext();
RightTupleImpl previous = rightTuple.getHandlePrevious();
RightTupleImpl next = rightTuple.getHandleNext();

if ( previous != null && next != null ) {
// remove from middle
Expand Down Expand Up @@ -667,8 +668,8 @@ public void clearRightTuples() {

@Override
public void forEachRightTuple(Consumer<RightTuple> rightTupleConsumer) {
for (RightTuple rightTuple = firstRightTuple; rightTuple != null; ) {
RightTuple nextRightTuple = rightTuple.getHandleNext();
for (RightTupleImpl rightTuple = (RightTupleImpl) firstRightTuple; rightTuple != null; ) {
RightTupleImpl nextRightTuple = rightTuple.getHandleNext();
rightTupleConsumer.accept( rightTuple );
rightTuple = nextRightTuple;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.drools.core.reteoo.RightInputAdapterNode;
import org.drools.core.reteoo.RightInputAdapterNode.RiaPathMemory;
import org.drools.core.reteoo.RightTuple;
import org.drools.core.reteoo.RightTupleImpl;
import org.drools.core.reteoo.SegmentMemory;
import org.drools.core.reteoo.SubnetworkTuple;
import org.drools.core.reteoo.TerminalNode;
Expand Down
15 changes: 13 additions & 2 deletions drools-core/src/main/java/org/drools/core/util/LinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,9 @@ public FastIterator fastIterator() {
return fastIterator;
}

public static class LinkedListFastIterator<K extends Entry<K>> implements FastIterator<K> {
public K next(K object) {
public static class LinkedListFastIterator implements FastIterator<AbstractTuple> {

public AbstractTuple next(AbstractTuple object) {
return object.getNext();
}

Expand All @@ -366,6 +367,16 @@ public boolean isFullIterator() {
}
}

public static class TMSLinkedListFastIterator<K extends Entry<K>> implements FastIterator<K> {
public K next(K object) {
return object.getNext();
}

public boolean isFullIterator() {
return false;
}
}

public java.util.Iterator<T> javaUtilIterator() {
return new JavaUtilIterator<>( this );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.drools.core.time.impl.PseudoClockScheduler;
import org.drools.core.time.impl.TimerJobInstance;
import org.drools.core.util.FastIterator;
import org.drools.core.util.LinkedList;
import org.drools.core.util.LinkedListEntry;
import org.drools.kiesession.entrypoints.NamedEntryPoint;
import org.drools.kiesession.session.StatefulKnowledgeSessionImpl;
Expand Down Expand Up @@ -458,7 +459,7 @@ public static void writeTruthMaintenanceSystem( MarshallerWriteContext context,

if ( key.size() > 1 ) {
// add all the other key's if they exist
FastIterator keyIter = key.fastIterator();
FastIterator keyIter = new LinkedList.TMSLinkedListFastIterator();
for ( DefaultFactHandle handle = key.getFirst().getNext(); handle != null; handle = (DefaultFactHandle) keyIter.next( handle ) ) {
_key.addOtherHandle( handle.getId() );
}
Expand All @@ -485,7 +486,7 @@ private static void writeBeliefSet( MarshallerWriteContext context,
ObjectMarshallingStrategyStore objectMarshallingStrategyStore = context.getObjectMarshallingStrategyStore();

// for ( LinkedListEntry node = (LinkedListEntry) beliefSet.getFirst(); node != null; node = (LinkedListEntry) node.getNext() ) {
FastIterator it = beliefSet.iterator();
FastIterator it = new LinkedList.TMSLinkedListFastIterator();
for ( LinkedListEntry node = (LinkedListEntry) beliefSet.getFirst(); node != null; node = (LinkedListEntry) it.next(node) ) {
LogicalDependency belief = (LogicalDependency) node.getObject();
ProtobufMessages.LogicalDependency.Builder _logicalDependency = ProtobufMessages.LogicalDependency.newBuilder();
Expand Down

0 comments on commit f5575bf

Please sign in to comment.