Skip to content

Commit

Permalink
Revert "[DROOLS-7528] Avoid casting to unnecessary interfaces (Fix th…
Browse files Browse the repository at this point in the history
…e secondary super cache problem in Drools) (apache#5451)"

This reverts commit abbfa6f.
  • Loading branch information
lucamolteni committed Sep 13, 2023
1 parent 3fe085e commit 2d38873
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ private static int updateRiaAndTerminalMemory( LeftTupleSource lt,
}

} else if (NodeTypeEnums.isTerminalNode(sink)) {
pmem = reteEvaluator.getNodeMemory((AbstractTerminalNode) sink);
pmem = (PathMemory) reteEvaluator.getNodeMemory((MemoryFactory) sink);
}

if (pmem != null && smem.getPos() < pmem.getSegmentMemories().length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.drools.core.common.ReteEvaluator;
import org.drools.core.common.TupleSets;
import org.drools.core.common.TupleSetsImpl;
import org.drools.core.reteoo.AbstractTerminalNode;
import org.drools.core.reteoo.AccumulateNode;
import org.drools.core.reteoo.AccumulateNode.AccumulateMemory;
import org.drools.core.reteoo.AsyncReceiveNode;
Expand Down Expand Up @@ -328,7 +327,7 @@ public void innerEval(PathMemory pmem,
boolean terminalNode = true;
switch (node.getType()) {
case NodeTypeEnums.RuleTerminalNode:
pRtNode.doNode((AbstractTerminalNode) node, activationsManager, srcTuples, executor);
pRtNode.doNode(( TerminalNode ) node, activationsManager, srcTuples, executor);
break;
case NodeTypeEnums.QueryTerminalNode:
pQtNode.doNode((QueryTerminalNode) node, activationsManager, srcTuples, stack);
Expand Down
14 changes: 1 addition & 13 deletions drools-core/src/main/java/org/drools/core/reteoo/LeftTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,20 +343,8 @@ public int getIndex() {
}

@Override
// It's better to always cast to a concrete or abstract class to avoid
// secondary super cache problem. See https://issues.redhat.com/browse/DROOLS-7521
public LeftTupleSink getTupleSink() {
Object sink = getSink();
if (sink instanceof AccumulateNode) {
return (AccumulateNode) sink;
} else if (sink instanceof RuleTerminalNode) {
return (RuleTerminalNode) sink;
} else if (sink instanceof RightInputAdapterNode) {
return (RightInputAdapterNode) sink;
} else if (sink instanceof ExistsNode) {
return (ExistsNode) sink;
}
return (LeftTupleSink)sink;
return (LeftTupleSink)getSink();
}

/* Had to add the set method because sink adapters must override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public RuleAgendaItem getOrCreateRuleAgendaItem(ActivationsManager activationsMa
}

private TerminalNode ensureAgendaItemCreated(ActivationsManager activationsManager) {
AbstractTerminalNode rtn = (AbstractTerminalNode) getPathEndNode();
TerminalNode rtn = (TerminalNode) getPathEndNode();
if (agendaItem == null) {
int salience = rtn.getRule().getSalience().isDynamic() ? 0 : rtn.getRule().getSalience().getValue();
agendaItem = activationsManager.createRuleAgendaItem(salience, this, rtn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,8 @@ public RightTupleImpl(InternalFactHandle handle,
handle.addLastRightTuple( this );
}

// It's better to always cast to a concrete or abstract class to avoid
// secondary super cache problem. See https://issues.redhat.com/browse/DROOLS-7521
public RightTupleSink getTupleSink() {
Object sink = getSink();
if(sink instanceof BetaNode) {
return (BetaNode)sink;
} else {
return (RightTupleSink) sink;
}
return (RightTupleSink) getSink();
}

public void reAdd() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void setActivationNode(final ActivationNode activationNode) {
}

public TerminalNode getTerminalNode() {
return (AbstractTerminalNode) getTupleSink();
return (TerminalNode) getTupleSink();
}

public List<FactHandle> getFactHandles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,9 @@ public BaseNode getMatchingNode(BaseNode candidate) {
public LeftTupleSink[] getSinks() {
return sinkArray;
}

// See LeftTuple.getTupleSink() or https://issues.redhat.com/browse/DROOLS-7521

public LeftTupleSinkNode getFirstLeftTupleSink() {
if (sink instanceof AccumulateNode) {
return (AccumulateNode) sink;
} else if (sink instanceof RuleTerminalNode) {
return (RuleTerminalNode) sink;
} else if (sink instanceof RightInputAdapterNode) {
return (RightInputAdapterNode) sink;
} else if (sink instanceof ExistsNode) {
return (ExistsNode) sink;
}
return (LeftTupleSinkNode) sink;
return ( LeftTupleSinkNode ) sink;
}

public LeftTupleSinkNode getLastLeftTupleSink() {
Expand Down

0 comments on commit 2d38873

Please sign in to comment.