From 4929779d9fbe8e0cb9bf57fa6109ae74398022f9 Mon Sep 17 00:00:00 2001 From: Mark Proctor Date: Wed, 14 Feb 2024 23:35:18 +0000 Subject: [PATCH 1/5] Split Beta Nodes #5787 --- .../org/drools/ancompiler/AssertHandler.java | 7 +- .../drools/ancompiler/CompiledNetwork.java | 8 +- .../org/drools/ancompiler/ModifyHandler.java | 11 +- .../ancompiler/ObjectTypeNodeParser.java | 5 +- .../org/drools/base/common/NetworkNode.java | 2 +- .../drools/base/reteoo/BaseTerminalNode.java | 10 - .../org/drools/base/reteoo/NodeTypeEnums.java | 27 +- .../java/org/drools/core/common/BaseNode.java | 11 +- .../drools/core/common/SuperCacheFixer.java | 62 +- .../drools/core/impl/KnowledgeBaseImpl.java | 4 + .../phreak/BuildtimeSegmentUtilities.java | 36 +- .../core/phreak/EagerPhreakBuilder.java | 37 +- .../drools/core/phreak/LazyPhreakBuilder.java | 132 ++-- .../core/phreak/PhreakAccumulateNode.java | 16 +- .../drools/core/phreak/PhreakExistsNode.java | 2 +- .../drools/core/phreak/PhreakGroupByNode.java | 2 +- .../org/drools/core/phreak/PhreakNotNode.java | 2 +- .../core/phreak/RuleNetworkEvaluator.java | 98 +-- .../core/phreak/RuntimeSegmentUtilities.java | 28 +- .../drools/core/phreak/SegmentPropagator.java | 4 +- .../org/drools/core/phreak/StackEntry.java | 28 +- .../core/phreak/TupleEvaluationUtil.java | 11 +- .../core/reteoo/AbstractTerminalNode.java | 39 +- .../drools/core/reteoo/AccumulateNode.java | 41 +- .../drools/core/reteoo/AccumulateRight.java | 42 ++ .../org/drools/core/reteoo/AlphaNode.java | 4 +- .../drools/core/reteoo/AlphaTerminalNode.java | 10 +- .../drools/core/reteoo/AsyncReceiveNode.java | 2 +- .../org/drools/core/reteoo/AsyncSendNode.java | 2 +- .../org/drools/core/reteoo/BetaMemory.java | 24 +- .../java/org/drools/core/reteoo/BetaNode.java | 357 ++--------- .../reteoo/CompositeObjectSinkAdapter.java | 20 +- ...positePartitionAwareObjectSinkAdapter.java | 8 +- .../core/reteoo/ConditionalBranchNode.java | 6 +- .../core/reteoo/EmptyObjectSinkAdapter.java | 4 +- .../drools/core/reteoo/EvalConditionNode.java | 12 +- .../org/drools/core/reteoo/ExistsNode.java | 32 +- .../org/drools/core/reteoo/ExistsRight.java | 32 + .../java/org/drools/core/reteoo/FromNode.java | 15 +- .../java/org/drools/core/reteoo/JoinNode.java | 26 +- .../core/reteoo/JoinRightAdapterNode.java | 32 + .../core/reteoo/LeftInputAdapterNode.java | 19 +- .../org/drools/core/reteoo/LeftTupleSink.java | 10 +- .../drools/core/reteoo/LeftTupleSource.java | 84 +-- .../java/org/drools/core/reteoo/NotNode.java | 85 +-- .../java/org/drools/core/reteoo/NotRight.java | 96 +++ .../core/reteoo/ObjectSinkPropagator.java | 4 +- .../org/drools/core/reteoo/ObjectSource.java | 26 +- .../drools/core/reteoo/ObjectTypeNode.java | 6 +- .../org/drools/core/reteoo/PathEndNode.java | 6 +- .../org/drools/core/reteoo/PathMemory.java | 2 +- .../drools/core/reteoo/QueryElementNode.java | 2 +- .../drools/core/reteoo/QueryTerminalNode.java | 8 +- .../org/drools/core/reteoo/ReteooBuilder.java | 57 +- .../core/reteoo/RightInputAdapterNode.java | 591 +++++++++--------- .../org/drools/core/reteoo/RightTuple.java | 2 +- .../drools/core/reteoo/RightTupleSink.java | 2 +- .../drools/core/reteoo/RuleTerminalNode.java | 6 +- .../org/drools/core/reteoo/SegmentMemory.java | 22 +- .../core/reteoo/SingleObjectSinkAdapter.java | 43 +- .../org/drools/core/reteoo/TimerNode.java | 2 +- .../org/drools/core/reteoo/TupleFactory.java | 12 +- .../drools/core/reteoo/TupleToObjectNode.java | 437 +++++++++++++ .../org/drools/core/reteoo/WindowNode.java | 6 +- .../reteoo/builder/AccumulateBuilder.java | 12 +- .../core/reteoo/builder/BuildUtils.java | 6 +- .../core/reteoo/builder/CollectBuilder.java | 12 +- .../reteoo/builder/GroupElementBuilder.java | 28 +- .../core/reteoo/builder/NodeFactory.java | 10 +- .../reteoo/builder/PhreakNodeFactory.java | 22 +- .../reteoo/builder/ReteooRuleBuilder.java | 11 +- .../org/drools/core/reteoo/BaseNodeTest.java | 16 + .../org/drools/core/reteoo/BetaNodeTest.java | 11 +- .../drools/core/reteoo/MockLeftTupleSink.java | 17 + .../drools/core/reteoo/NodeTypeEnumTest.java | 12 +- .../drools/core/util/RightTupleListTest.java | 7 +- .../debug/BetaRightAdapterNodeVisitor.java | 60 ++ .../debug/RightInputAdapterNodeVisitor.java | 7 +- .../kiesession/debug/SessionInspector.java | 17 +- .../kiesession/NodeSegmentUnlinkingTest.java | 107 ++-- .../drools/kiesession/RuleUnlinkingTest.java | 79 +-- .../RuleUnlinkingWithSegmentMemoryTest.java | 69 +- .../model/codegen/execmodel/IndexTest.java | 9 +- .../execmodel/PropertyReactivityTest.java | 2 +- .../mvel/MVELConsequenceBuilderTest.java | 79 +-- .../org/drools/retediagram/ReteDiagram.java | 10 +- .../protobuf/iterators/LeftTupleIterator.java | 5 +- .../iterators/PhreakActivationIterator.java | 4 + .../protobuf/marshalling/RuleBaseNodes.java | 5 + .../protobuf/MarshallingTest.java | 9 +- .../AccumulateMvelDialectTest.java | 10 +- .../AlphaNetworkModifyTest.java | 10 +- .../BackwardChainingTest.java | 26 +- .../compiler/integrationtests/CepEspTest.java | 7 +- .../JoinNodeRangeIndexingTest.java | 5 +- .../NegativePatternsTest.java | 5 +- .../integrationtests/operators/NotTest.java | 3 +- .../mvel/CompositeObjectSinkAdapterTest.java | 17 +- .../LeftTupleIndexHashTableIteratorTest.java | 32 +- .../java/org/drools/mvel/MockBetaNode.java | 31 +- .../drools/mvel/compiler/MemoryLeakTest.java | 3 +- .../util/debug/SessionInspectorTest.java | 36 +- .../mvel/integrationtests/LinkingTest.java | 37 +- .../NodePositionInPathTest.java | 6 +- .../NodesPartitioningTest.java | 12 +- .../integrationtests/PathEndNodeTest.java | 9 +- .../PropertySpecificTest.java | 435 ++++++------- .../integrationtests/SegmentCreationTest.java | 25 +- .../integrationtests/phreak/AddRuleTest.java | 44 +- .../phreak/BetaNodeBuilder.java | 10 +- .../integrationtests/phreak/RightBuilder.java | 10 +- .../integrationtests/phreak/RightMemory.java | 2 +- .../util/RightTupleIndexHashTableTest.java | 32 +- 113 files changed, 2296 insertions(+), 1916 deletions(-) create mode 100644 drools-core/src/main/java/org/drools/core/reteoo/AccumulateRight.java create mode 100644 drools-core/src/main/java/org/drools/core/reteoo/ExistsRight.java create mode 100644 drools-core/src/main/java/org/drools/core/reteoo/JoinRightAdapterNode.java create mode 100644 drools-core/src/main/java/org/drools/core/reteoo/NotRight.java create mode 100644 drools-core/src/main/java/org/drools/core/reteoo/TupleToObjectNode.java create mode 100755 drools-kiesession/src/main/java/org/drools/kiesession/debug/BetaRightAdapterNodeVisitor.java diff --git a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AssertHandler.java b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AssertHandler.java index 11c4519ae70..b7a112ac586 100644 --- a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AssertHandler.java +++ b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AssertHandler.java @@ -23,6 +23,7 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.stmt.Statement; +import org.drools.base.reteoo.NodeTypeEnums; import org.drools.core.reteoo.Sink; import static com.github.javaparser.StaticJavaParser.parseStatement; @@ -40,7 +41,11 @@ protected Statement propagateMethod(Sink sink) { if (sinkCanBeInlined(sink)) { assertStatement = parseStatement("ALPHATERMINALNODE.collectObject();"); } else { - assertStatement = parseStatement("ALPHATERMINALNODE.assertObject(handle, context, wm);"); + String g = ""; + if (NodeTypeEnums.isBetaNode(sink)) { + g = "getRightInput()."; + } + assertStatement = parseStatement("ALPHATERMINALNODE." + g + "assertObject(handle, context, wm);"); } replaceNameExpr(assertStatement, "ALPHATERMINALNODE", getVariableName(sink)); return assertStatement; diff --git a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/CompiledNetwork.java b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/CompiledNetwork.java index a5b9d3eabe8..e88f0563998 100644 --- a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/CompiledNetwork.java +++ b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/CompiledNetwork.java @@ -218,13 +218,13 @@ public boolean isEmpty() { } @Override - public void doLinkRiaNode(ReteEvaluator reteEvaluator) { - originalSinkPropagator.doLinkRiaNode(reteEvaluator); + public void doLinkSubnetwork(ReteEvaluator reteEvaluator) { + originalSinkPropagator.doLinkSubnetwork(reteEvaluator); } @Override - public void doUnlinkRiaNode(ReteEvaluator reteEvaluator) { - originalSinkPropagator.doUnlinkRiaNode(reteEvaluator); + public void doUnlinkSubnetwork(ReteEvaluator reteEvaluator) { + originalSinkPropagator.doUnlinkSubnetwork(reteEvaluator); } public abstract void init(Object... args); diff --git a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ModifyHandler.java b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ModifyHandler.java index f5091fd2431..b4518fb0924 100644 --- a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ModifyHandler.java +++ b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ModifyHandler.java @@ -23,6 +23,7 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.stmt.Statement; +import org.drools.base.reteoo.NodeTypeEnums; import org.drools.core.reteoo.Sink; import static com.github.javaparser.StaticJavaParser.parseStatement; @@ -40,8 +41,16 @@ protected Statement propagateMethod(Sink sink) { if (sinkCanBeInlined(sink)) { modifyStatement = parseStatement("ALPHATERMINALNODE.collectObject();"); } else { - modifyStatement = parseStatement("ALPHATERMINALNODE.modifyObject(handle, modifyPreviousTuples, context, wm);"); + String g = ""; + if (NodeTypeEnums.isBetaNode(sink)) { + g = "getRightInput()."; + } + + modifyStatement = parseStatement("ALPHATERMINALNODE." + g + "modifyObject(handle, modifyPreviousTuples, context, wm);"); } + + + replaceNameExpr(modifyStatement, "ALPHATERMINALNODE", getVariableName(sink)); return modifyStatement; } diff --git a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ObjectTypeNodeParser.java b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ObjectTypeNodeParser.java index 9069121b14c..e5dc061dcb0 100644 --- a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ObjectTypeNodeParser.java +++ b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ObjectTypeNodeParser.java @@ -27,6 +27,7 @@ import org.drools.core.reteoo.AlphaNode; import org.drools.core.reteoo.BetaNode; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.CompositeObjectSinkAdapter; import org.drools.core.reteoo.CompositeObjectSinkAdapter.FieldIndex; import org.drools.core.reteoo.CompositePartitionAwareObjectSinkAdapter; @@ -201,8 +202,8 @@ private void traverseSink(ObjectSink sink, NetworkHandler handler) { traversePropagator(alphaNode.getObjectSinkPropagator(), handler); handler.endNonHashedAlphaNode(alphaNode); - } else if (NodeTypeEnums.isBetaNode( sink ) ) { - BetaNode betaNode = (BetaNode) sink; + } else if (NodeTypeEnums.isBetaRightNode( sink ) ) { + BetaNode betaNode = ((RightInputAdapterNode) sink).getBetaNode(); handler.startBetaNode(betaNode); handler.endBetaNode(betaNode); diff --git a/drools-base/src/main/java/org/drools/base/common/NetworkNode.java b/drools-base/src/main/java/org/drools/base/common/NetworkNode.java index 5d0288312cd..0bb1b229ddc 100644 --- a/drools-base/src/main/java/org/drools/base/common/NetworkNode.java +++ b/drools-base/src/main/java/org/drools/base/common/NetworkNode.java @@ -54,7 +54,7 @@ public interface NetworkNode extends Serializable { NetworkNode[] getSinks(); - default boolean isRightInputIsRiaNode() { + default boolean inputIsTupleToObjectNode() { // not ideal, but this was here to allow NetworkNode to be in drools-base return false; } diff --git a/drools-base/src/main/java/org/drools/base/reteoo/BaseTerminalNode.java b/drools-base/src/main/java/org/drools/base/reteoo/BaseTerminalNode.java index 66f2b6b4d7b..cec8893e962 100644 --- a/drools-base/src/main/java/org/drools/base/reteoo/BaseTerminalNode.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/BaseTerminalNode.java @@ -33,18 +33,8 @@ public interface BaseTerminalNode extends NetworkNode { void initInferredMask(); - BitMask getDeclaredMask(); - - void setDeclaredMask(BitMask mask); - - BitMask getInferredMask(); - - void setInferredMask(BitMask mask); - BitMask getNegativeMask(); - void setNegativeMask(BitMask mask); - RuleImpl getRule(); GroupElement getSubRule(); diff --git a/drools-base/src/main/java/org/drools/base/reteoo/NodeTypeEnums.java b/drools-base/src/main/java/org/drools/base/reteoo/NodeTypeEnums.java index 83b09a16291..ce509eb8516 100644 --- a/drools-base/src/main/java/org/drools/base/reteoo/NodeTypeEnums.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/NodeTypeEnums.java @@ -34,7 +34,9 @@ public class NodeTypeEnums { public static final int EndNodeMask = 1 << 8; public static final int BetaMask = 1 << 9; - public static final int MemoryFactoryMask = 1 << 10; + public static final int BetaRightMask = 1 << 10; + + public static final int MemoryFactoryMask = 1 << 11; public static final int shift = 15; // This must shift the node IDs, enough so their bits are not mutated by the masks. @@ -46,8 +48,15 @@ public class NodeTypeEnums { public static final int WindowNode = (150 << shift) | ObjectSourceMask | ObjectSinkMask | MemoryFactoryMask; // ObjectSource, LeftTupleSink - public static final int RightInputAdapterNode = (160 << shift) | ObjectSourceMask | TupleSinkMask | - TupleNodeMask | EndNodeMask | MemoryFactoryMask; + public static final int TupleToObjectNode = (160 << shift) | ObjectSourceMask | TupleSinkMask | + TupleNodeMask | EndNodeMask | MemoryFactoryMask; + + public static final int JoinRightAdapterNode = (162 << shift) | ObjectSinkMask | BetaRightMask; + public static final int ExistsRightAdapterNode = (164 << shift) | ObjectSinkMask | BetaRightMask; + public static final int NotRightAdapterNode = (166 << shift) | ObjectSinkMask | BetaRightMask; + public static final int AccumulateRightAdapterNode = (168 << shift) | ObjectSinkMask | BetaRightMask; + + // LefTTupleSink, LeftTupleNode public static final int RuleTerminalNode = (180 << shift) | TupleSinkMask | TerminalNodeMask | TupleNodeMask | EndNodeMask | MemoryFactoryMask; @@ -97,8 +106,12 @@ public static boolean isBetaNode(NetworkNode node) { return (node.getType() & BetaMask) != 0; } - public static boolean isBetaNodeWithRian(NetworkNode node) { - return isBetaNode(node) && node.isRightInputIsRiaNode(); + public static boolean isBetaNodeWithSubnetwork(NetworkNode node) { + return isBetaNode(node) && node.inputIsTupleToObjectNode(); + } + + public static boolean isBetaNodeWithoutSubnetwork(NetworkNode node) { + return isBetaNode(node) && !node.inputIsTupleToObjectNode(); } public static boolean isTerminalNode(NetworkNode node) { @@ -130,4 +143,8 @@ public static boolean isLeftInputAdapterNode(NetworkNode node) { return (node.getType() & LeftInputAdapterMask) != 0; } + public static boolean isBetaRightNode(NetworkNode node) { + return (node.getType() & BetaRightMask) != 0; + } + } diff --git a/drools-core/src/main/java/org/drools/core/common/BaseNode.java b/drools-core/src/main/java/org/drools/core/common/BaseNode.java index 9677f359451..fd151c12918 100644 --- a/drools-core/src/main/java/org/drools/core/common/BaseNode.java +++ b/drools-core/src/main/java/org/drools/core/common/BaseNode.java @@ -36,6 +36,7 @@ import org.drools.core.reteoo.Sink; import org.drools.core.reteoo.TerminalNode; import org.drools.core.reteoo.builder.BuildContext; +import org.drools.util.bitmask.BitMask; import org.kie.api.definition.rule.Rule; import org.drools.base.reteoo.NodeTypeEnums; @@ -110,6 +111,8 @@ protected void setStreamMode(boolean streamMode) { this.streamMode = streamMode; } + public abstract BaseNode getParent(); + /** * Attaches the node into the network. Usually to the parent ObjectSource or TupleSource */ @@ -174,14 +177,10 @@ public void setPartitionId(BuildContext context, RuleBasePartitionId partitionId /** * Associates this node with the give rule */ - public void addAssociation( Rule rule ) { + public void addAssociation(Rule rule, BuildContext context) { this.associations.add( rule ); } - public void addAssociation( BuildContext context, Rule rule ) { - addAssociation( rule ); - } - /** * Removes the association to the given rule from the * associations map. @@ -242,4 +241,6 @@ public NetworkNode[] getSinks() { } + public abstract BitMask getDeclaredMask(); + public abstract BitMask getInferredMask(); } diff --git a/drools-core/src/main/java/org/drools/core/common/SuperCacheFixer.java b/drools-core/src/main/java/org/drools/core/common/SuperCacheFixer.java index c98789a52ec..b08a1f10f75 100644 --- a/drools-core/src/main/java/org/drools/core/common/SuperCacheFixer.java +++ b/drools-core/src/main/java/org/drools/core/common/SuperCacheFixer.java @@ -21,24 +21,28 @@ import org.drools.base.common.NetworkNode; import org.drools.base.reteoo.NodeTypeEnums; import org.drools.core.reteoo.AccumulateNode; +import org.drools.core.reteoo.AccumulateRight; import org.drools.core.reteoo.AlphaTerminalNode; import org.drools.core.reteoo.AsyncReceiveNode; import org.drools.core.reteoo.AsyncSendNode; import org.drools.core.reteoo.ConditionalBranchNode; import org.drools.core.reteoo.EvalConditionNode; import org.drools.core.reteoo.ExistsNode; +import org.drools.core.reteoo.ExistsRight; import org.drools.core.reteoo.FromNode; import org.drools.core.reteoo.JoinNode; +import org.drools.core.reteoo.JoinRightAdapterNode; import org.drools.core.reteoo.LeftInputAdapterNode; import org.drools.core.reteoo.LeftTupleNode; import org.drools.core.reteoo.LeftTupleSinkNode; import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.NotNode; +import org.drools.core.reteoo.NotRight; import org.drools.core.reteoo.ObjectTypeNodeId; import org.drools.core.reteoo.QueryElementNode; import org.drools.core.reteoo.QueryTerminalNode; import org.drools.core.reteoo.ReactiveFromNode; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.RightTuple; import org.drools.core.reteoo.RightTupleSink; import org.drools.core.reteoo.RuleTerminalNode; @@ -57,7 +61,7 @@ public static LeftTupleNode getLeftTupleNode(TupleImpl t) { switch (s.getType()) { case NodeTypeEnums.RuleTerminalNode : return (RuleTerminalNode) s; case NodeTypeEnums.QueryTerminalNode: return (QueryTerminalNode) s; - case NodeTypeEnums.RightInputAdapterNode: return (RightInputAdapterNode) s; + case NodeTypeEnums.TupleToObjectNode: return (TupleToObjectNode) s; case NodeTypeEnums.LeftInputAdapterNode: return (LeftInputAdapterNode) s; case NodeTypeEnums.AlphaTerminalNode: return (AlphaTerminalNode) s; case NodeTypeEnums.AccumulateNode : return (AccumulateNode) s; @@ -81,10 +85,10 @@ public static LeftTupleNode getLeftTupleNode(TupleImpl t) { public static RightTupleSink getRightTupleSink(RightTuple t) { Sink s = t.getSink(); switch (s.getType()) { - case NodeTypeEnums.AccumulateNode : return (AccumulateNode) s; - case NodeTypeEnums.ExistsNode: return (ExistsNode) s; - case NodeTypeEnums.NotNode: return (NotNode) s; - case NodeTypeEnums.JoinNode: return (JoinNode) s; + case NodeTypeEnums.AccumulateRightAdapterNode: return (AccumulateRight) s; + case NodeTypeEnums.ExistsRightAdapterNode: return (ExistsRight) s; + case NodeTypeEnums.NotRightAdapterNode: return (NotRight) s; + case NodeTypeEnums.JoinRightAdapterNode: return (JoinRightAdapterNode) s; case NodeTypeEnums.WindowNode: return (WindowNode) s; case NodeTypeEnums.MockBetaNode: return (RightTupleSink) s; case NodeTypeEnums.MockAlphaNode: return (RightTupleSink) s; @@ -97,7 +101,7 @@ public static LeftTupleSinkNode asLeftTupleSink(NetworkNode n) { switch (n.getType()) { case NodeTypeEnums.RuleTerminalNode : return (RuleTerminalNode) n; case NodeTypeEnums.QueryTerminalNode: return (QueryTerminalNode) n; - case NodeTypeEnums.RightInputAdapterNode: return (RightInputAdapterNode) n; + case NodeTypeEnums.TupleToObjectNode: return (TupleToObjectNode) n; case NodeTypeEnums.AccumulateNode : return (AccumulateNode) n; case NodeTypeEnums.ExistsNode: return (ExistsNode) n; case NodeTypeEnums.NotNode: return (NotNode) n; @@ -119,22 +123,22 @@ public static LeftTupleSinkNode asLeftTupleSink(NetworkNode n) { public static ObjectTypeNodeId getLeftInputOtnId(TupleImpl t) { Sink s = t.getSink(); switch (s.getType()) { - case NodeTypeEnums.RuleTerminalNode : return ((RuleTerminalNode) s).getLeftInputOtnId(); - case NodeTypeEnums.QueryTerminalNode: return ((QueryTerminalNode) s).getLeftInputOtnId(); - case NodeTypeEnums.RightInputAdapterNode: return ((RightInputAdapterNode) s).getLeftInputOtnId(); - case NodeTypeEnums.AccumulateNode : return ((AccumulateNode) s).getLeftInputOtnId(); - case NodeTypeEnums.ExistsNode: return ((ExistsNode) s).getLeftInputOtnId(); - case NodeTypeEnums.NotNode: return ((NotNode) s).getLeftInputOtnId(); - case NodeTypeEnums.JoinNode: return ((JoinNode) s).getLeftInputOtnId(); - case NodeTypeEnums.FromNode: return ((FromNode) s).getLeftInputOtnId(); - case NodeTypeEnums.EvalConditionNode: return ((EvalConditionNode) s).getLeftInputOtnId(); - case NodeTypeEnums.AsyncReceiveNode: return ((AsyncReceiveNode) s).getLeftInputOtnId(); - case NodeTypeEnums.AsyncSendNode: return ((AsyncSendNode) s).getLeftInputOtnId(); - case NodeTypeEnums.ReactiveFromNode: return ((ReactiveFromNode) s).getLeftInputOtnId(); - case NodeTypeEnums.ConditionalBranchNode: return ((ConditionalBranchNode) s).getLeftInputOtnId(); - case NodeTypeEnums.QueryElementNode: return ((QueryElementNode) s).getLeftInputOtnId(); - case NodeTypeEnums.TimerConditionNode: return ((TimerNode) s).getLeftInputOtnId(); - case NodeTypeEnums.MockBetaNode: return ((LeftTupleSource)s).getLeftInputOtnId(); + case NodeTypeEnums.RuleTerminalNode : return ((RuleTerminalNode) s).getInputOtnId(); + case NodeTypeEnums.QueryTerminalNode: return ((QueryTerminalNode) s).getInputOtnId(); + case NodeTypeEnums.TupleToObjectNode: return ((TupleToObjectNode) s).getInputOtnId(); + case NodeTypeEnums.AccumulateNode : return ((AccumulateNode) s).getInputOtnId(); + case NodeTypeEnums.ExistsNode: return ((ExistsNode) s).getInputOtnId(); + case NodeTypeEnums.NotNode: return ((NotNode) s).getInputOtnId(); + case NodeTypeEnums.JoinNode: return ((JoinNode) s).getInputOtnId(); + case NodeTypeEnums.FromNode: return ((FromNode) s).getInputOtnId(); + case NodeTypeEnums.EvalConditionNode: return ((EvalConditionNode) s).getInputOtnId(); + case NodeTypeEnums.AsyncReceiveNode: return ((AsyncReceiveNode) s).getInputOtnId(); + case NodeTypeEnums.AsyncSendNode: return ((AsyncSendNode) s).getInputOtnId(); + case NodeTypeEnums.ReactiveFromNode: return ((ReactiveFromNode) s).getInputOtnId(); + case NodeTypeEnums.ConditionalBranchNode: return ((ConditionalBranchNode) s).getInputOtnId(); + case NodeTypeEnums.QueryElementNode: return ((QueryElementNode) s).getInputOtnId(); + case NodeTypeEnums.TimerConditionNode: return ((TimerNode) s).getInputOtnId(); + case NodeTypeEnums.MockBetaNode: return ((LeftTupleSource)s).getInputOtnId(); default: throw new UnsupportedOperationException("Node does not have an LeftInputOtnId: " + s); } @@ -143,11 +147,11 @@ public static ObjectTypeNodeId getLeftInputOtnId(TupleImpl t) { public static ObjectTypeNodeId getRightInputOtnId(TupleImpl t) { Sink s = t.getSink(); switch (s.getType()) { - case NodeTypeEnums.AccumulateNode : return ((AccumulateNode) s).getRightInputOtnId(); - case NodeTypeEnums.ExistsNode: return ((ExistsNode) s).getRightInputOtnId(); - case NodeTypeEnums.NotNode: return ((NotNode) s).getRightInputOtnId(); - case NodeTypeEnums.JoinNode: return ((JoinNode) s).getRightInputOtnId(); - case NodeTypeEnums.WindowNode: return ((WindowNode) s).getRightInputOtnId(); + case NodeTypeEnums.AccumulateRightAdapterNode: return ((AccumulateRight) s).getInputOtnId(); + case NodeTypeEnums.ExistsRightAdapterNode: return ((ExistsRight) s).getInputOtnId(); + case NodeTypeEnums.NotRightAdapterNode: return ((NotRight) s).getInputOtnId(); + case NodeTypeEnums.JoinRightAdapterNode: return ((JoinRightAdapterNode) s).getInputOtnId(); + case NodeTypeEnums.WindowNode: return ((WindowNode) s).getInputOtnId(); default: throw new UnsupportedOperationException("Node does not have an RightInputOtnId: " + s); } @@ -158,7 +162,7 @@ public static LeftTupleSource getLeftTupleSource(TupleImpl t) { switch (s.getType()) { case NodeTypeEnums.RuleTerminalNode : return ((RuleTerminalNode) s).getLeftTupleSource(); case NodeTypeEnums.QueryTerminalNode: return ((QueryTerminalNode) s).getLeftTupleSource(); - case NodeTypeEnums.RightInputAdapterNode: return ((RightInputAdapterNode) s).getLeftTupleSource(); + case NodeTypeEnums.TupleToObjectNode: return ((TupleToObjectNode) s).getLeftTupleSource(); case NodeTypeEnums.AccumulateNode : return ((AccumulateNode) s).getLeftTupleSource(); case NodeTypeEnums.ExistsNode: return ((ExistsNode) s).getLeftTupleSource(); case NodeTypeEnums.NotNode: return ((NotNode) s).getLeftTupleSource(); diff --git a/drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java b/drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java index e14d287f218..9f39ec1c843 100644 --- a/drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java +++ b/drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java @@ -160,6 +160,10 @@ public class KnowledgeBaseImpl implements InternalRuleBase { public KnowledgeBaseImpl() { } + public KnowledgeBaseImpl(String id) { + this(id, (CompositeBaseConfiguration) RuleBaseFactory.newKnowledgeBaseConfiguration()); + } + public KnowledgeBaseImpl(final String id, final CompositeBaseConfiguration config) { this.config = config; diff --git a/drools-core/src/main/java/org/drools/core/phreak/BuildtimeSegmentUtilities.java b/drools-core/src/main/java/org/drools/core/phreak/BuildtimeSegmentUtilities.java index 1c570fdebe0..d3b64d0130e 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/BuildtimeSegmentUtilities.java +++ b/drools-core/src/main/java/org/drools/core/phreak/BuildtimeSegmentUtilities.java @@ -41,7 +41,7 @@ import org.drools.core.reteoo.PathEndNode.PathMemSpec; import org.drools.core.reteoo.QueryElementNode; import org.drools.core.reteoo.ReactiveFromNode; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.SegmentMemory.AccumulateMemoryPrototype; import org.drools.core.reteoo.SegmentMemory.AsyncReceiveMemoryPrototype; import org.drools.core.reteoo.SegmentMemory.AsyncSendMemoryPrototype; @@ -66,7 +66,7 @@ public static void updateSegmentEndNodes(PathEndNode endNode) { SegmentPrototype smproto = endNode.getSegmentPrototypes()[endNode.getSegmentPrototypes().length-1]; if (smproto.getPathEndNodes() != null) { // This is a special check, for shared subnetwork paths. It ensure it's initallysed only once, - // even though the rian is shared with different TNs. + // even though the TupleToObjectNode is shared with different TNs. return; } @@ -88,7 +88,7 @@ public static void updateSegmentEndNodes(PathEndNode endNode) { private static void setSegments(PathEndNode endNode, SegmentPrototype[] smems) { List eager = new ArrayList<>(); for (SegmentPrototype smem : smems) { - // The segments before the start of a subnetwork, will be null for a rian path. + // The segments before the start of a subnetwork, will be null for a TupleToObjectNode path. if (smem != null && smem.requiresEager()) { eager.add(smem); } @@ -162,7 +162,7 @@ public static SegmentPrototype[] createLeftTupleNodeProtoMemories(LeftTupleNode // reset to find the next segments and set their position and their bit mask int ruleSegmentPosMask = 1; for (int i = 0; i < smems.size(); i++) { - if ( start >= 0 && smems.get(i) != null) { // The segments before the start of a subnetwork, will be null for a rian path. + if ( start >= 0 && smems.get(i) != null) { // The segments before the start of a subnetwork, will be null for a TupleToObjectNode path. smems.get(i).setPos(i); if (smems.get(i).getAllLinkedMaskTest() > 0) { smems.get(i).setSegmentPosMaskBit(ruleSegmentPosMask); @@ -239,8 +239,8 @@ public static SegmentPrototype createSegmentMemory(LeftTupleNode segmentRoot, Le case NodeTypeEnums.QueryElementNode: updateNodeBit = processQueryNode((QueryElementNode) node, memories, nodes, nodePosMask); break; - case NodeTypeEnums.RightInputAdapterNode: - processRightInputAdapterNode((RightInputAdapterNode) node, memories, nodes); + case NodeTypeEnums.TupleToObjectNode: + processRightInputAdapterNode((TupleToObjectNode) node, memories, nodes); break; case NodeTypeEnums.RuleTerminalNode: case NodeTypeEnums.QueryTerminalNode: @@ -309,7 +309,7 @@ private static void processConditionalBranchNode(ConditionalBranchNode tupleSour nodes.add(tupleSource); } - private static void processRightInputAdapterNode(RightInputAdapterNode tupleSource, List memories, List nodes) { + private static void processRightInputAdapterNode(TupleToObjectNode tupleSource, List memories, List nodes) { RightInputAdapterPrototype mem = new RightInputAdapterPrototype(); memories.add(mem); nodes.add(tupleSource); @@ -356,16 +356,16 @@ private static long processLiaNode(LeftInputAdapterNode tupleSource, List memories, List nodes, long nodePosMask, long allLinkedTestMask, boolean updateNodeBit, TerminalNode removingTn, InternalRuleBase rbase) { - RightInputAdapterNode riaNode = null; - if (betaNode.isRightInputIsRiaNode()) { + TupleToObjectNode tton = null; + if (betaNode.getRightInput().inputIsTupleToObjectNode()) { // there is a subnetwork, so create all it's segment memory prototypes - riaNode = (RightInputAdapterNode) betaNode.getRightInput(); + tton = (TupleToObjectNode) betaNode.getRightInput().getParent(); - SegmentPrototype[] smems = createLeftTupleNodeProtoMemories(riaNode, removingTn, rbase); - setSegments(riaNode, smems); + SegmentPrototype[] smems = createLeftTupleNodeProtoMemories(tton, removingTn, rbase); + setSegments(tton, smems); - if (updateNodeBit && canBeDisabled(betaNode) && riaNode.getPathMemSpec().allLinkedTestMask() > 0) { - // only ria's with reactive subnetworks can be disabled and thus need checking + if (updateNodeBit && canBeDisabled(betaNode) && tton.getPathMemSpec().allLinkedTestMask() > 0) { + // only TupleToObjectNode's with reactive subnetworks can be disabled and thus need checking allLinkedTestMask = allLinkedTestMask | nodePosMask; } } else if (updateNodeBit && canBeDisabled(betaNode)) { @@ -377,7 +377,7 @@ private static long processBetaNode(BetaNode betaNode, SegmentPrototype smem, Li smem.linkNode(nodePosMask); } - BetaMemoryPrototype bm = new BetaMemoryPrototype(nodePosMask, riaNode); + BetaMemoryPrototype bm = new BetaMemoryPrototype(nodePosMask, tton); if (NodeTypeEnums.AccumulateNode == betaNode.getType()) { AccumulateMemoryPrototype am = new AccumulateMemoryPrototype(bm); @@ -393,7 +393,7 @@ private static long processBetaNode(BetaNode betaNode, SegmentPrototype smem, Li public static boolean canBeDisabled(BetaNode betaNode) { // non empty not nodes and accumulates can never be disabled and thus don't need checking return (!(NodeTypeEnums.NotNode == betaNode.getType() && !((NotNode) betaNode).isEmptyBetaConstraints()) && - NodeTypeEnums.AccumulateNode != betaNode.getType() && !betaNode.isRightInputPassive()); + NodeTypeEnums.AccumulateNode != betaNode.getType() && !betaNode.getRightInput().isRightInputPassive()); } /** @@ -411,7 +411,7 @@ public static boolean isRootNode(LeftTupleNode node, TerminalNode ignoreTn) { /** * Returns whether the node is the tip of a segment. - * EndNodes (rtn and rian) are always the tip of a segment. + * EndNodes (rtn and TupleToObjectNode) are always the tip of a segment. * * node cannot be null. * @@ -466,7 +466,7 @@ public static int updateNodeTypesMask(NetworkNode node, int mask) { mask |= JOIN_NODE_BIT; break; case NodeTypeEnums.ExistsNode: - if ( ( (ExistsNode) node ).isRightInputPassive() ) { + if ( ( (ExistsNode) node ).getRightInput().isRightInputPassive() ) { mask |= PASSIVE_EXISTS_NODE_BIT; } else { mask |= REACTIVE_EXISTS_NODE_BIT; diff --git a/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java b/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java index 2c4e58d806f..1475867533f 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java +++ b/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java @@ -31,6 +31,7 @@ import org.drools.base.common.NetworkNode; import org.drools.base.reteoo.NodeTypeEnums; import org.drools.core.WorkingMemory; +import org.drools.core.common.BaseNode; import org.drools.core.common.DefaultEventHandle; import org.drools.core.common.InternalAgenda; import org.drools.core.common.InternalFactHandle; @@ -61,6 +62,7 @@ import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.QueryElementNode; import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.RightTuple; import org.drools.core.reteoo.RuleTerminalNodeLeftTuple; import org.drools.core.reteoo.RuntimeComponentFactory; @@ -246,8 +248,8 @@ public static List getExclusiveBranchRoots(TerminalNode tn) { } while (node.getLeftTupleSource() != null) { - if (NodeTypeEnums.isBetaNodeWithRian(node) && ((BetaNode)node).getRightInput().getAssociatedTerminalsSize() > 1) { - exclbranchRoots.add( new Pair((LeftTupleNode) ((BetaNode)node).getRightInput(), node)); + if (NodeTypeEnums.isBetaNodeWithSubnetwork(node) && ((BetaNode)node).getRightInput().getParent().getAssociatedTerminalsSize() > 1) { + exclbranchRoots.add( new Pair((LeftTupleNode) ((BetaNode)node).getRightInput().getParent(), node)); } if (node.getLeftTupleSource().getAssociatedTerminalsSize()> 1) { @@ -342,7 +344,7 @@ public static void insertFacts(TerminalNode tn, InternalWorkingMemory wm, Set exclBranchRoots, TerminalNode tn, for (InternalWorkingMemory wm : wms) { for (PathEndNode endNode : tn.getPathEndNodes() ) { if (endNode.getAssociatedTerminalsSize() > 1) { - // can only happen on rians, and we need to notify, incase they are already linked in + // can only happen on TupleToObjectNodes, and we need to notify, incase they are already linked in Memory mem = wm.getNodeMemories().peekNodeMemory(endNode); if (mem != null && mem.getSegmentMemory() != null) { SegmentMemory sm = mem.getSegmentMemory(); @@ -675,8 +677,8 @@ private static void removeExistingPaths(List exclBranchRoots, TerminalNode for (int i = exclBranchRoots.size() - 1; i >= 0; i--) { // last is the most inner LeftTupleNode child = exclBranchRoots.get(i).child; LeftTupleNode parent = exclBranchRoots.get(i).parent; - if (parent.getType() == NodeTypeEnums.RightInputAdapterNode) { - continue; // A RIAN as it's also a PathEnd doesn't have a child segment + if (parent.getType() == NodeTypeEnums.TupleToObjectNode) { + continue; // A TupleToObjectNode as it's also a PathEnd doesn't have a child segment } // If it exists, remove the child segment memory for the path being removed. @@ -999,7 +1001,7 @@ private static void deleteRightInputData(LeftTupleNode node, Memory m, InternalW } private static void deleteFactsFromRightInput(BetaNode bn, InternalWorkingMemory wm) { - ObjectSource source = bn.getRightInput(); + BaseNode source = bn.getRightInput(); if (source.getType() == NodeTypeEnums.WindowNode) { WindowNode.WindowMemory memory = (WindowNode.WindowMemory) wm.getNodeMemories().peekNodeMemory(source); if (memory != null) { @@ -1088,7 +1090,7 @@ private static void processLeftTuples(LeftTupleNode node, boolean insert, Termin visitChild((TupleImpl) accctx.getResultLeftTuple(), insert, wm, tn); } } else if (NodeTypeEnums.ExistsNode == node.getType() && - !((BetaNode) node).isRightInputIsRiaNode()) { // do not process exists with subnetworks + !((BetaNode) node).getRightInput().inputIsTupleToObjectNode()) { // do not process exists with subnetworks // If there is a subnetwork, then there is no populated RTM, but the LTM is populated, // so this would be procsssed in the "else". @@ -1132,9 +1134,9 @@ private static void processLeftTuples(LeftTupleNode node, boolean insert, Termin } private static void processLeftTuplesOnLian( InternalWorkingMemory wm, boolean insert, TerminalNode tn, LeftInputAdapterNode lian ) { - ObjectSource os = lian.getObjectSource(); + BaseNode os = lian.getObjectSource(); while (os.getType() != NodeTypeEnums.ObjectTypeNode) { - os = os.getParentObjectSource(); + os = os.getParent(); } ObjectTypeNode otn = (ObjectTypeNode) os; @@ -1184,7 +1186,7 @@ private static void visitChild(TupleImpl lt, boolean insert, InternalWorkingMemo for ( TupleImpl child = lt.getFirstChild(); child != null; child = child.getHandleNext() ) { visitChild(child, insert, wm, tn); } - } else if (lt.getSink().getType() == NodeTypeEnums.RightInputAdapterNode) { + } else if (lt.getSink().getType() == NodeTypeEnums.TupleToObjectNode) { insertPeerRightTuple(lt, wm, tn, insert); } } else if (!insert) { @@ -1214,10 +1216,10 @@ private static void visitChild(TupleImpl lt, boolean insert, InternalWorkingMemo private static void insertPeerRightTuple(TupleImpl lt, InternalWorkingMemory wm, TerminalNode tn, boolean insert ) { // There's a shared RightInputAdapterNode, so check if one of its sinks is associated only to the new rule - TupleImpl prevLt = null; - RightInputAdapterNode rian = (RightInputAdapterNode) lt.getSink(); + TupleImpl prevLt = null; + TupleToObjectNode tton = (TupleToObjectNode) lt.getSink(); - for (ObjectSink sink : rian.getObjectSinkPropagator().getSinks()) { + for (ObjectSink sink : tton.getObjectSinkPropagator().getSinks()) { if (lt != null) { if (prevLt != null && !insert && isAssociatedWith(sink, tn) && sink.getAssociatedTerminalsSize() == 1) { prevLt.setPeer( null ); @@ -1225,10 +1227,11 @@ private static void insertPeerRightTuple(TupleImpl lt, InternalWorkingMemory wm, prevLt = lt; lt = lt.getPeer(); } else if (insert) { - BetaMemory bm = (BetaMemory) wm.getNodeMemories().peekNodeMemory(sink); + BetaNode betaNode = ((RightInputAdapterNode)sink).getBetaNode(); + BetaMemory bm = (BetaMemory) wm.getNodeMemories().peekNodeMemory(betaNode); if (bm != null) { - prevLt = TupleFactory.createPeer(rian, prevLt); - bm.linkNode((BetaNode) sink, wm); + prevLt = TupleFactory.createPeer(tton, prevLt); + bm.linkNode(betaNode, wm); bm.getStagedRightTuples().addInsert(prevLt); } } diff --git a/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java b/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java index 52e6b86fb83..518f425ba08 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java +++ b/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java @@ -30,6 +30,7 @@ import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.core.common.BaseNode; import org.drools.core.common.DefaultEventHandle; import org.drools.core.common.InternalAgenda; import org.drools.core.common.InternalFactHandle; @@ -51,6 +52,7 @@ import org.drools.core.reteoo.AsyncSendNode; import org.drools.core.reteoo.BetaMemory; import org.drools.core.reteoo.BetaNode; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.ConditionalBranchNode; import org.drools.core.reteoo.EvalConditionNode; import org.drools.core.reteoo.FromNode; @@ -62,13 +64,12 @@ import org.drools.core.reteoo.LeftTupleSinkNode; import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.ObjectSink; -import org.drools.core.reteoo.ObjectSource; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.PathEndNode; import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.QueryElementNode; -import org.drools.core.reteoo.RightInputAdapterNode; -import org.drools.core.reteoo.RightInputAdapterNode.RiaPathMemory; +import org.drools.core.reteoo.TupleToObjectNode; +import org.drools.core.reteoo.TupleToObjectNode.SubnetworkPathMemory; import org.drools.core.reteoo.RightTuple; import org.drools.core.reteoo.RuleTerminalNodeLeftTuple; import org.drools.core.reteoo.RuntimeComponentFactory; @@ -97,7 +98,7 @@ import static org.drools.core.phreak.BuildtimeSegmentUtilities.updateNodeTypesMask; import static org.drools.core.phreak.EagerPhreakBuilder.Add.attachAdapterAndPropagate; import static org.drools.core.phreak.EagerPhreakBuilder.deleteLeftTuple; -import static org.drools.core.phreak.RuntimeSegmentUtilities.createRiaSegmentMemory; +import static org.drools.core.phreak.RuntimeSegmentUtilities.createSubnetworkSegmentMemory; import static org.drools.core.phreak.RuntimeSegmentUtilities.getOrCreateSegmentMemory; import static org.drools.core.phreak.RuntimeSegmentUtilities.getQuerySegmentMemory; import static org.drools.core.phreak.TupleEvaluationUtil.forceFlushLeftTuple; @@ -728,7 +729,7 @@ private static void insertFacts(PathEndNodes endNodes, Collection) node); + if (node.getType() == NodeTypeEnums.TupleToObjectNode) { + SubnetworkPathMemory subnMem = (SubnetworkPathMemory) wm.getNodeMemories().peekNodeMemory(node); + if (subnMem == null && !tnMems.otherPmems.isEmpty()) { + subnMem = (SubnetworkPathMemory) wm.getNodeMemory((MemoryFactory) node); } - if (riaMem != null) { - tnMems.subjectPmems.add(riaMem); + if (subnMem != null) { + tnMems.subjectPmems.add(subnMem); } } else { PathMemory pmem = (PathMemory) wm.getNodeMemories().peekNodeMemory(node); @@ -1311,7 +1313,7 @@ private static void collectPathEndNodes(InternalRuleBase kBase, collectPathEndNodes(kBase, sink, endNodes, tn, processedRule, hasProtos, hasWms, isBelowNewSplit); } else if (NodeTypeEnums.isTerminalNode(sink)) { endNodes.otherEndNodes.add((PathEndNode) sink); - } else if (NodeTypeEnums.RightInputAdapterNode == sink.getType()) { + } else if (NodeTypeEnums.TupleToObjectNode == sink.getType()) { if (sink.isAssociatedWith( processedRule )) { endNodes.subjectEndNodes.add( (PathEndNode) sink ); } @@ -1343,7 +1345,7 @@ static SegmentMemory createChildSegment(ReteEvaluator reteEvaluator, LeftTupleNo Memory memory = reteEvaluator.getNodeMemory((MemoryFactory) node); if (memory.getSegmentMemory() == null) { if (NodeTypeEnums.isEndNode(node)) { - // RTNS and RiaNode's have their own segment, if they are the child of a split. + // RTNS and TupleToObjectNode's have their own segment, if they are the child of a split. createChildSegmentForTerminalNode( node, memory ); } else { createSegmentMemory((LeftTupleSource) node, reteEvaluator); @@ -1361,7 +1363,7 @@ static SegmentMemory createSegmentMemory(ReteEvaluator reteEvaluator, LeftTupleN } private static SegmentMemory createChildSegmentForTerminalNode( LeftTupleNode node, Memory memory ) { - SegmentMemory childSmem = new SegmentMemory( node ); // rtns or riatns don't need a queue + SegmentMemory childSmem = new SegmentMemory( node ); // rtns or TupleToObjectNodes don't need a queue PathMemory pmem = (PathMemory) memory; childSmem.setPos( pmem.getSegmentMemories().length - 1 ); @@ -1429,16 +1431,16 @@ private static SegmentMemory createSegmentMemory(LeftTupleSource segmentRoot, Re if (NodeTypeEnums.isLeftTupleSource(sink)) { tupleSource = (LeftTupleSource) sink; } else { - // rtn or rian - // While not technically in a segment, we want to be able to iterate easily from the last node memory to the ria/rtn memory - // we don't use createNodeMemory, as these may already have been created by, but not added, by the method updateRiaAndTerminalMemory + // rtn or TupleToObjectNode + // While not technically in a segment, we want to be able to iterate easily from the last node memory to the TupleToObjectNode/rtn memory + // we don't use createNodeMemory, as these may already have been created by, but not added, by the method updateTupleToObjectAndTerminalMemory Memory memory = reteEvaluator.getNodeMemory((MemoryFactory) sink); - if (sink.getType() == NodeTypeEnums.RightInputAdapterNode) { - PathMemory riaPmem = (RightInputAdapterNode.RiaPathMemory)memory; - memories.add( riaPmem ); + if (sink.getType() == NodeTypeEnums.TupleToObjectNode) { + PathMemory subnMem = (SubnetworkPathMemory)memory; + memories.add( subnMem ); - RightInputAdapterNode rian = ( RightInputAdapterNode ) sink; - ObjectSink[] nodes = rian.getObjectSinkPropagator().getSinks(); + TupleToObjectNode tton = (TupleToObjectNode) sink; + ObjectSink[] nodes = tton.getObjectSinkPropagator().getSinks(); for ( ObjectSink node : nodes ) { if ( NodeTypeEnums.isLeftTupleSource(node) ) { getOrCreateSegmentMemory( (LeftTupleSource) node, reteEvaluator ); @@ -1486,7 +1488,7 @@ private static SegmentMemory createSegmentMemory(LeftTupleSource segmentRoot, Re smem.setSegmentPosMaskBit(ruleSegmentPosMask); smem.setPos(counter); - updateRiaAndTerminalMemory(tupleSource, tupleSource, smem, reteEvaluator, false, nodeTypesInSegment); + updateSubnetworkAndTerminalMemory(tupleSource, tupleSource, smem, reteEvaluator, false, nodeTypesInSegment); reteEvaluator.getKnowledgeBase().registerSegmentPrototype(segmentRoot, smem.getSegmentPrototype().initFromSegmentMemory(smem)); @@ -1579,13 +1581,13 @@ private static long processBetaNode(BetaNode betaNode, ReteEvaluator reteEvaluat // and bm.getSegmentMemory == null check can be used to avoid recursion. bm.setSegmentMemory(smem); - if (betaNode.isRightInputIsRiaNode()) { - RightInputAdapterNode riaNode = createRiaSegmentMemory( betaNode, reteEvaluator ); + if (betaNode.getRightInput().inputIsTupleToObjectNode()) { + TupleToObjectNode tton = createSubnetworkSegmentMemory(betaNode, reteEvaluator); - PathMemory riaMem = reteEvaluator.getNodeMemory(riaNode); - bm.setRiaRuleMemory((RiaPathMemory) riaMem); - if (updateNodeBit && canBeDisabled(betaNode) && riaMem.getAllLinkedMaskTest() > 0) { - // only ria's with reactive subnetworks can be disabled and thus need checking + PathMemory subnetworkPathMemory = reteEvaluator.getNodeMemory(tton); + bm.setSubnetworkPathMemory((SubnetworkPathMemory) subnetworkPathMemory); + if (updateNodeBit && canBeDisabled(betaNode) && subnetworkPathMemory.getAllLinkedMaskTest() > 0) { + // only TupleToObjectNode's with reactive subnetworks can be disabled and thus need checking allLinkedTestMask = allLinkedTestMask | nodePosMask; } } else if (updateNodeBit && canBeDisabled(betaNode)) { @@ -1601,35 +1603,35 @@ private static long processBetaNode(BetaNode betaNode, ReteEvaluator reteEvaluat } /** - * This adds the segment memory to the terminal node or ria node's list of memories. + * This adds the segment memory to the terminal node or TupleToObjectNode node's list of memories. * In the case of the terminal node this allows it to know that all segments from * the tip to root are linked. * In the case of the ria node its all the segments up to the start of the subnetwork. - * This is because the rianode only cares if all of it's segments are linked, then + * This is because the TupleToObjectNode only cares if all of it's segments are linked, then * it sets the bit of node it is the right input for. */ - private static int updateRiaAndTerminalMemory( LeftTupleSource lt, - LeftTupleSource originalLt, - SegmentMemory smem, - ReteEvaluator reteEvaluator, - boolean fromPrototype, - int nodeTypesInSegment ) { + private static int updateSubnetworkAndTerminalMemory(LeftTupleSource lt, + LeftTupleSource originalLt, + SegmentMemory smem, + ReteEvaluator reteEvaluator, + boolean fromPrototype, + int nodeTypesInSegment) { nodeTypesInSegment = checkSegmentBoundary(lt, reteEvaluator, nodeTypesInSegment); PathMemory pmem = null; for (LeftTupleSink sink : lt.getSinkPropagator().getSinks()) { if (NodeTypeEnums.isLeftTupleSource(sink)) { - nodeTypesInSegment = updateRiaAndTerminalMemory((LeftTupleSource) sink, originalLt, smem, reteEvaluator, fromPrototype, nodeTypesInSegment); - } else if (sink.getType() == NodeTypeEnums.RightInputAdapterNode) { + nodeTypesInSegment = updateSubnetworkAndTerminalMemory((LeftTupleSource) sink, originalLt, smem, reteEvaluator, fromPrototype, nodeTypesInSegment); + } else if (sink.getType() == NodeTypeEnums.TupleToObjectNode) { // Even though we don't add the pmem and smem together, all pmem's for all pathend nodes must be initialized - RightInputAdapterNode.RiaPathMemory riaMem = (RightInputAdapterNode.RiaPathMemory) reteEvaluator.getNodeMemory((MemoryFactory) sink); - // Only add the RIANode, if the LeftTupleSource is part of the RIANode subnetwork - if (inSubNetwork((RightInputAdapterNode) sink, originalLt)) { - pmem = riaMem; + SubnetworkPathMemory subnMem = (SubnetworkPathMemory) reteEvaluator.getNodeMemory((MemoryFactory) sink); + // Only add the TupleToObjectNode, if the LeftTupleSource is part of the TupleToObjectNode subnetwork + if (inSubNetwork((TupleToObjectNode) sink, originalLt)) { + pmem = subnMem; if (fromPrototype) { - ObjectSink[] nodes = ((RightInputAdapterNode) sink).getObjectSinkPropagator().getSinks(); + ObjectSink[] nodes = ((TupleToObjectNode) sink).getObjectSinkPropagator().getSinks(); for ( ObjectSink node : nodes ) { // check if the SegmentMemory has been already created by the BetaNode and if so avoid to build it twice if ( NodeTypeEnums.isLeftTupleSource(node) && reteEvaluator.getNodeMemory((MemoryFactory) node).getSegmentMemory() == null ) { @@ -1638,7 +1640,7 @@ private static int updateRiaAndTerminalMemory( LeftTupleSource lt, } } else if ( ( pmem.getAllLinkedMaskTest() & ( 1L << pmem.getSegmentMemories().length ) ) == 0 ) { // must eagerly initialize child segment memories - ObjectSink[] nodes = ((RightInputAdapterNode) sink).getObjectSinkPropagator().getSinks(); + ObjectSink[] nodes = ((TupleToObjectNode) sink).getObjectSinkPropagator().getSinks(); for ( ObjectSink node : nodes ) { if ( NodeTypeEnums.isLeftTupleSource(node) ) { getOrCreateSegmentMemory( (LeftTupleSource) node, reteEvaluator ); @@ -1667,7 +1669,7 @@ private static int updateRiaAndTerminalMemory( LeftTupleSource lt, private static void restoreSegmentFromPrototype(ReteEvaluator reteEvaluator, LeftTupleSource segmentRoot, int nodeTypesInSegment) { SegmentMemory smem = reteEvaluator.getKnowledgeBase().createSegmentFromPrototype(reteEvaluator, segmentRoot); if ( smem != null ) { - updateRiaAndTerminalMemory(segmentRoot, segmentRoot, smem, reteEvaluator, true, nodeTypesInSegment); + updateSubnetworkAndTerminalMemory(segmentRoot, segmentRoot, smem, reteEvaluator, true, nodeTypesInSegment); } } @@ -1684,11 +1686,11 @@ private static int checkSegmentBoundary(LeftTupleSource lt, ReteEvaluator reteEv /** * Is the LeftTupleSource a node in the sub network for the RightInputAdapterNode * To be in the same network, it must be a node is after the two output of the parent - * and before the rianode. + * and before the TupleToObjectNode. */ - private static boolean inSubNetwork(RightInputAdapterNode riaNode, LeftTupleSource leftTupleSource) { - LeftTupleSource startTupleSource = riaNode.getStartTupleSource().getLeftTupleSource(); - LeftTupleSource current = riaNode.getLeftTupleSource(); + private static boolean inSubNetwork(TupleToObjectNode tton, LeftTupleSource leftTupleSource) { + LeftTupleSource startTupleSource = tton.getStartTupleSource().getLeftTupleSource(); + LeftTupleSource current = tton.getLeftTupleSource(); while (current != startTupleSource) { if (current == leftTupleSource) { diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakAccumulateNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakAccumulateNode.java index e87a4fba138..05b0b4fa80f 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakAccumulateNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakAccumulateNode.java @@ -83,7 +83,7 @@ public void doNode(AccumulateNode accNode, doLeftUpdates(accNode, am, reteEvaluator, srcLeftTuples, tempLeftTuples); } - if (!accNode.isRightInputIsRiaNode()) { + if (!accNode.getRightInput().inputIsTupleToObjectNode()) { // Non subnetworks ore process right then left. This because it's typically faster to ensure all RightTuples // are in place then you can iterate with the left evaluation cached. if (srcRightTuples.getInsertFirst() != null) { @@ -156,7 +156,7 @@ private void doLeftInserts(AccumulateNode accNode, } BaseAccumulation accresult = initAccumulationContext( am, reteEvaluator, accumulate, leftTuple ); - if (accNode.isRightInputIsRiaNode()) { + if (accNode.getRightInput().inputIsTupleToObjectNode()) { // This is a subnetwork, do not process further. As all matches will processed // by the right insert. This is to avoid double iteration (first right side iteration // then left side iteration) or for the join to find matching tuple chains, which it previously @@ -236,12 +236,12 @@ private void doRightInserts(AccumulateNode accNode, TupleImpl next = rightTuple.getStagedNext(); boolean useTupleMemory = tupleMemoryEnabled || RuleNetworkEvaluator.useLeftMemory(accNode, rightTuple); - if (useTupleMemory || !accNode.isRightInputIsRiaNode()) { + if (useTupleMemory || !accNode.getRightInput().inputIsTupleToObjectNode()) { // If tuple memory is off, it will still be when it is not a subnetwork. rtm.add(rightTuple); } - if (accNode.isRightInputIsRiaNode() || (ltm != null && ltm.size() > 0)) { + if (accNode.getRightInput().inputIsTupleToObjectNode() || (ltm != null && ltm.size() > 0)) { constraints.updateFromFactHandle( contextEntry, reteEvaluator, rightTuple.getFactHandleForEvaluation() ); @@ -284,7 +284,7 @@ private void doLeftUpdates(AccumulateNode accNode, TupleImpl next = leftTuple.getStagedNext(); BaseAccumulation accctx = (BaseAccumulation) leftTuple.getContextObject(); - if (accNode.isRightInputIsRiaNode()) { + if (accNode.getRightInput().inputIsTupleToObjectNode()) { // This is a subnetwork, do not process further. As all matches will processed // by the right updates. This is to avoid double iteration (first right side iteration // then left side iteration) or for the join to find matching tuple chains, which it previously @@ -718,7 +718,7 @@ private void addMatch(final AccumulateNode accNode, TupleImpl tuple = leftTuple; InternalFactHandle handle = rightTuple.getFactHandle(); - if (accNode.isRightInputIsRiaNode()) { + if (accNode.getRightInput().inputIsTupleToObjectNode()) { // if there is a subnetwork, handle must be unwrapped tuple = rightTuple; handle = rightTuple.getFactHandleForEvaluation(); @@ -773,7 +773,7 @@ private boolean removeMatch(final AccumulateNode accNode, // if there is a subnetwork, we need to unwrap the object from inside the tuple FactHandle handle = rightTuple.getFactHandle(); TupleImpl tuple = leftParent; - if (accNode.isRightInputIsRiaNode()) { + if (accNode.getRightInput().inputIsTupleToObjectNode()) { tuple = rightTuple; handle = rightTuple.getFactHandleForEvaluation(); } @@ -817,7 +817,7 @@ protected void reaccumulateForLeftTuple(final AccumulateNode accNode, TupleImpl rightTuple = childMatch.getRightParent(); FactHandle childHandle = rightTuple.getFactHandle(); TupleImpl tuple = leftParent; - if (accNode.isRightInputIsRiaNode()) { + if (accNode.getRightInput().inputIsTupleToObjectNode()) { // if there is a subnetwork, handle must be unwrapped tuple = rightTuple; childHandle = rightTuple.getFactHandleForEvaluation(); diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakExistsNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakExistsNode.java index bc66defa8e1..7cf6734b428 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakExistsNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakExistsNode.java @@ -42,7 +42,7 @@ public void doNode(ExistsNode existsNode, TupleSets srcLeftTuples, TupleSets trgLeftTuples, TupleSets stagedLeftTuples) { - if (!existsNode.isRightInputIsRiaNode()) { + if (!existsNode.getRightInput().inputIsTupleToObjectNode()) { doNormalNode(existsNode, sink, bm, reteEvaluator, srcLeftTuples, trgLeftTuples, stagedLeftTuples); } else { PhreakSubnetworkNotExistsNode.doSubNetworkNode(existsNode, sink, bm, diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakGroupByNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakGroupByNode.java index 8a329ac24cf..94db4c87cf3 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakGroupByNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakGroupByNode.java @@ -108,7 +108,7 @@ protected void reaccumulateForLeftTuple(final AccumulateNode accNode, TupleImpl rightTuple = childMatch.getRightParent(); FactHandle childHandle = rightTuple.getFactHandle(); TupleImpl tuple = leftTuple; - if (accNode.isRightInputIsRiaNode()) { + if (accNode.getRightInput().inputIsTupleToObjectNode()) { // if there is a subnetwork, handle must be unwrapped tuple = rightTuple; childHandle = rightTuple.getFactHandleForEvaluation(); diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakNotNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakNotNode.java index 3cb56b6e013..f8eb034df20 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakNotNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakNotNode.java @@ -43,7 +43,7 @@ public void doNode(NotNode notNode, TupleSets trgLeftTuples, TupleSets stagedLeftTuples) { - if (!notNode.isRightInputIsRiaNode()) { + if (!notNode.getRightInput().inputIsTupleToObjectNode()) { doNormalNode(notNode, sink, bm, reteEvaluator, srcLeftTuples, trgLeftTuples, stagedLeftTuples); } else { PhreakSubnetworkNotExistsNode.doSubNetworkNode(notNode, sink, bm, diff --git a/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java b/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java index eef6b8ad1b8..9d17b80cdb6 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java +++ b/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java @@ -30,6 +30,7 @@ import org.drools.core.common.TupleSets; import org.drools.core.common.TupleSetsImpl; import org.drools.core.reteoo.AbstractTerminalNode; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.TupleFactory; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.AccumulateNode; @@ -61,8 +62,8 @@ import org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory; import org.drools.core.reteoo.QueryTerminalNode; import org.drools.core.reteoo.ReactiveFromNode; -import org.drools.core.reteoo.RightInputAdapterNode; -import org.drools.core.reteoo.RightInputAdapterNode.RiaPathMemory; +import org.drools.core.reteoo.TupleToObjectNode; +import org.drools.core.reteoo.TupleToObjectNode.SubnetworkPathMemory; import org.drools.core.reteoo.RightTuple; import org.drools.core.reteoo.SegmentMemory; import org.drools.core.reteoo.SubnetworkTuple; @@ -162,8 +163,8 @@ public static int getOffset(NetworkNode node) { if (NodeTypeEnums.isTerminalNode(node)) { lt = ((TerminalNode) node).getLeftTupleSource(); offset++; - } else if (node.getType() == NodeTypeEnums.RightInputAdapterNode) { - lt = ((RightInputAdapterNode) node).getLeftTupleSource(); + } else if (node.getType() == NodeTypeEnums.TupleToObjectNode) { + lt = ((TupleToObjectNode) node).getLeftTupleSource(); } else { lt = (LeftTupleSource) node; } @@ -184,9 +185,9 @@ public void outerEval(PathMemory pmem, TupleSets trgTuples, ActivationsManager activationsManager, LinkedList stack, - boolean processRian, + boolean processSubnetwork, RuleExecutor executor) { - innerEval(pmem, node, bit, nodeMem, smems, smemIndex, trgTuples, activationsManager, stack, processRian, executor); + innerEval(pmem, node, bit, nodeMem, smems, smemIndex, trgTuples, activationsManager, stack, processSubnetwork, executor); while (true) { // eval if (!stack.isEmpty()) { @@ -214,7 +215,7 @@ public void evalStackEntry(StackEntry entry, LinkedList stack, RuleE SegmentMemory[] smems = entry.getSmems(); int smemIndex = entry.getSmemIndex(); - boolean processRian = entry.isProcessRian(); + boolean processSubnetwork = entry.isProcessSubnetwork(); long bit = entry.getBit(); if (entry.isResumeFromNextNode()) { @@ -248,7 +249,7 @@ public void evalStackEntry(StackEntry entry, LinkedList stack, RuleE int offset = getOffset(node); log.trace("{} Resume {} {}", indent(offset), node.toString(), trgTuples.toStringSizes()); } - innerEval(pmem, node, bit, nodeMem, smems, smemIndex, trgTuples, activationsManager, stack, processRian, executor); + innerEval(pmem, node, bit, nodeMem, smems, smemIndex, trgTuples, activationsManager, stack, processSubnetwork, executor); } public void innerEval(PathMemory pmem, @@ -260,7 +261,7 @@ public void innerEval(PathMemory pmem, TupleSets trgTuples, ActivationsManager activationsManager, LinkedList stack, - boolean processRian, + boolean processSubnetwork, RuleExecutor executor) { TupleSets srcTuples; SegmentMemory smem = smems[smemIndex]; @@ -273,8 +274,8 @@ public void innerEval(PathMemory pmem, } boolean emptySrcTuples = srcTuples.isEmpty(); - if ( !(NodeTypeEnums.isBetaNode(node) && ((BetaNode)node).isRightInputIsRiaNode() ) ) { - // The engine cannot skip a ria node, as the dirty might be several levels deep + if ( !(NodeTypeEnums.isBetaNodeWithSubnetwork(node)) ) { + // The engine cannot skip a TupleToObjectNode node, as the dirty might be several levels deep if ( emptySrcTuples && smem.getDirtyNodeMask() == 0) { // empty sources and segment is not dirty, skip to non empty src tuples or dirty segment. boolean foundDirty = false; @@ -298,7 +299,7 @@ public void innerEval(PathMemory pmem, nodeMem = smem.getNodeMemories()[0]; if ( !emptySrcTuples || smem.getDirtyNodeMask() != 0 || - (NodeTypeEnums.isBetaNode(node) && ((BetaNode)node).isRightInputIsRiaNode() )) { + (NodeTypeEnums.isBetaNode(node) && ((BetaNode)node).getRightInput().inputIsTupleToObjectNode() )) { // break if dirty or if we reach a subnetwork. It must break for subnetworks, so they can be searched. foundDirty = true; smemIndex = i; @@ -318,7 +319,8 @@ public void innerEval(PathMemory pmem, long dirtyMask = smem.getDirtyNodeMask(); if ( emptySrcTuples ) { - while ((dirtyMask & bit) == 0 && node != smem.getTipNode() && !(NodeTypeEnums.isBetaNode(node) && ((BetaNode)node).isRightInputIsRiaNode() ) ) { + while ((dirtyMask & bit) == 0 && node != smem.getTipNode() && !NodeTypeEnums.isBetaNodeWithSubnetwork(node) ) { + //while ((dirtyMask & bit) == 0 && node != smem.getTipNode() && NodeTypeEnums.isBetaNodeWithoutSubnetwork(node) ) { if (log.isTraceEnabled()) { int offset = getOffset(node); log.trace("{} Skip Node {}", indent(offset), node); @@ -337,8 +339,8 @@ public void innerEval(PathMemory pmem, case NodeTypeEnums.QueryTerminalNode: pQtNode.doNode((QueryTerminalNode) node, activationsManager, srcTuples, stack); break; - case NodeTypeEnums.RightInputAdapterNode: - doRiaNode2(activationsManager.getReteEvaluator(), srcTuples, (RightInputAdapterNode) node); + case NodeTypeEnums.TupleToObjectNode: + doSubnetwork2(activationsManager.getReteEvaluator(), srcTuples, (TupleToObjectNode) node); break; default: terminalNode = false; @@ -350,7 +352,7 @@ public void innerEval(PathMemory pmem, stagedLeftTuples = getTargetStagedLeftTuples(node, activationsManager.getReteEvaluator(), smem); LeftTupleSinkNode sink = ((LeftTupleSource) node).getSinkPropagator().getFirstLeftTupleSink(); - trgTuples = evalNode( pmem, node, bit, nodeMem, smems, smemIndex, activationsManager, stack, processRian, executor, srcTuples, smem, stagedLeftTuples, sink ); + trgTuples = evalNode( pmem, node, bit, nodeMem, smems, smemIndex, activationsManager, stack, processSubnetwork, executor, srcTuples, smem, stagedLeftTuples, sink ); if ( trgTuples == null ) { break; // Queries exists and has been placed StackEntry, and there are no current trgTuples to process } @@ -376,7 +378,7 @@ public void innerEval(PathMemory pmem, node = smem.getRootNode(); nodeMem = smem.getNodeMemories()[0]; } - processRian = true; // make sure it's reset, so ria nodes are processed + processSubnetwork = true; // make sure it's reset, so ria nodes are processed } if ( stagedLeftTuples != null && !stagedLeftTuples.isEmpty() ) { @@ -386,11 +388,11 @@ public void innerEval(PathMemory pmem, public TupleSets evalNode(PathMemory pmem, NetworkNode node, long bit, Memory nodeMem, SegmentMemory[] smems, int smemIndex, ActivationsManager activationsManager, LinkedList stack, - boolean processRian, RuleExecutor executor, TupleSets srcTuples, SegmentMemory smem, + boolean processSubnetwork, RuleExecutor executor, TupleSets srcTuples, SegmentMemory smem, TupleSets stagedLeftTuples, LeftTupleSinkNode sink ) { TupleSets trgTuples = new TupleSetsImpl(); if ( NodeTypeEnums.isBetaNode( node )) { - boolean exitInnerEval = evalBetaNode(pmem, node, nodeMem, smems, smemIndex, trgTuples, activationsManager, stack, processRian, executor, srcTuples, stagedLeftTuples, sink); + boolean exitInnerEval = evalBetaNode(pmem, node, nodeMem, smems, smemIndex, trgTuples, activationsManager, stack, processSubnetwork, executor, srcTuples, stagedLeftTuples, sink); if ( exitInnerEval ) { return null; } @@ -543,7 +545,7 @@ private boolean evalQueryNode(PathMemory pmem, private boolean evalBetaNode(PathMemory pmem, NetworkNode node, Memory nodeMem, SegmentMemory[] smems, int smemIndex, TupleSets trgTuples, ActivationsManager activationsManager, - LinkedList stack, boolean processRian, RuleExecutor executor, + LinkedList stack, boolean processSubnetwork, RuleExecutor executor, TupleSets srcTuples, TupleSets stagedLeftTuples, LeftTupleSinkNode sink) { BetaNode betaNode = (BetaNode) node; BetaMemory bm; @@ -555,12 +557,12 @@ private boolean evalBetaNode(PathMemory pmem, NetworkNode node, Memory nodeMem, bm = (BetaMemory) nodeMem; } - if (processRian && betaNode.isRightInputIsRiaNode()) { + if (processSubnetwork && betaNode.getRightInput().inputIsTupleToObjectNode()) { // if the subnetwork is nested in this segment, it will create srcTuples containing // peer LeftTuples, suitable for the node in the main path. - doRiaNode( activationsManager, pmem, srcTuples, - betaNode, sink, smems, smemIndex, nodeMem, bm, stack, executor ); - return true; // return here, doRiaNode queues the evaluation on the stack, which is necessary to handled nested query nodes + doSubnetwork(activationsManager, pmem, srcTuples, + betaNode, sink, smems, smemIndex, nodeMem, bm, stack, executor); + return true; // return here, TupleToObjectNode queues the evaluation on the stack, which is necessary to handled nested query nodes } switchOnDoBetaNode(node, trgTuples, activationsManager.getReteEvaluator(), srcTuples, stagedLeftTuples, sink, bm, am); @@ -603,19 +605,19 @@ private void switchOnDoBetaNode(NetworkNode node, TupleSets trgTuples, ReteEvalu } } - private void doRiaNode(ActivationsManager activationsManager, - PathMemory pmem, - TupleSets srcTuples, - BetaNode betaNode, - LeftTupleSinkNode sink, - SegmentMemory[] smems, - int smemIndex, - Memory nodeMem, - BetaMemory bm, - LinkedList stack, - RuleExecutor executor) { - RiaPathMemory pathMem = bm.getRiaRuleMemory(); - SegmentMemory[] subnetworkSmems = pathMem.getSegmentMemories(); + private void doSubnetwork(ActivationsManager activationsManager, + PathMemory pmem, + TupleSets srcTuples, + BetaNode betaNode, + LeftTupleSinkNode sink, + SegmentMemory[] smems, + int smemIndex, + Memory nodeMem, + BetaMemory bm, + LinkedList stack, + RuleExecutor executor) { + SubnetworkPathMemory pathMem = bm.getSubnetworkPathMemory(); + SegmentMemory[] subnetworkSmems = pathMem.getSegmentMemories(); SegmentMemory subSmem = null; for ( int i = 0; subSmem == null; i++) { // segment positions outside of the subnetwork, in the parent chain, are null @@ -623,13 +625,13 @@ private void doRiaNode(ActivationsManager activationsManager, subSmem = subnetworkSmems[i]; } - // Resume the node after the riaNode segment has been processed and the right input memory populated + // Resume the node after the TupleToObjectNode segment has been processed and the right input memory populated StackEntry stackEntry = new StackEntry(betaNode, bm.getNodePosMaskBit(), sink, pmem, nodeMem, smems, smemIndex, srcTuples, false, false); stack.add(stackEntry); if (log.isTraceEnabled()) { int offset = getOffset(betaNode); - log.trace("{} RiaQueue {} {}", indent(offset), betaNode.toString(), srcTuples.toStringSizes()); + log.trace("{} SubnetworkQueue {} {}", indent(offset), betaNode.toString(), srcTuples.toStringSizes()); } @@ -641,13 +643,13 @@ private void doRiaNode(ActivationsManager activationsManager, subLts, activationsManager, stack, true, executor ); } - private void doRiaNode2(ReteEvaluator reteEvaluator, - TupleSets srcTuples, - RightInputAdapterNode riaNode) { + private void doSubnetwork2(ReteEvaluator reteEvaluator, + TupleSets srcTuples, + TupleToObjectNode tton) { - ObjectSink[] sinks = riaNode.getObjectSinkPropagator().getSinks(); + ObjectSink[] sinks = tton.getObjectSinkPropagator().getSinks(); - BetaNode betaNode = (BetaNode) sinks[0]; + BetaNode betaNode = ((RightInputAdapterNode)sinks[0]).getBetaNode(); BetaMemory bm; Memory nodeMem = reteEvaluator.getNodeMemory(betaNode); if (NodeTypeEnums.AccumulateNode == betaNode.getType()) { @@ -665,7 +667,7 @@ private void doRiaNode2(ReteEvaluator reteEvaluator, bns = new BetaNode[sinks.length - 1]; bms = new BetaMemory[sinks.length - 1]; for (int i = 1; i < length; i++) { - bns[i - 1] = (BetaNode) sinks[i]; + bns[i - 1] = ((RightInputAdapterNode)sinks[i]).getBetaNode(); Memory nodeMem2 = reteEvaluator.getNodeMemory(bns[i - 1]); if (NodeTypeEnums.AccumulateNode == betaNode.getType()) { bms[i - 1] = ((AccumulateMemory) nodeMem2).getBetaMemory(); @@ -691,7 +693,7 @@ private void doRiaNode2(ReteEvaluator reteEvaluator, if ( bms[i].getStagedRightTuples().isEmpty() ) { bms[i].setNodeDirtyWithoutNotify(); } - subnetworkTuple = (SubnetworkTuple) TupleFactory.createPeer(riaNode, + subnetworkTuple = (SubnetworkTuple) TupleFactory.createPeer(tton, subnetworkTuple); bms[i].getStagedRightTuples().addInsert(subnetworkTuple); } @@ -776,8 +778,8 @@ public static void findLeftTupleBlocker(BetaNode betaNode, TupleMemory rtm, if (useLeftMemory) { rightTuple.addBlocked((LeftTuple) leftTuple); break; - } else if (betaNode.isRightInputIsRiaNode()) { - // If we aren't using leftMemory and the right input is a RIAN, then we must iterate and find all subetwork right tuples and remove them + } else if (betaNode.getRightInput().inputIsTupleToObjectNode()) { + // If we aren't using leftMemory and the right input is a TupleToObjectNode, then we must iterate and find all subetwork right tuples and remove them // so we don't break rtm.remove(rightTuple); } else { diff --git a/drools-core/src/main/java/org/drools/core/phreak/RuntimeSegmentUtilities.java b/drools-core/src/main/java/org/drools/core/phreak/RuntimeSegmentUtilities.java index 5fdbc510809..43d7d4bdb37 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/RuntimeSegmentUtilities.java +++ b/drools-core/src/main/java/org/drools/core/phreak/RuntimeSegmentUtilities.java @@ -36,7 +36,7 @@ import org.drools.core.reteoo.PathEndNode; import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.QueryElementNode; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.SegmentMemory; import org.drools.core.reteoo.SegmentMemory.SegmentPrototype; @@ -65,8 +65,8 @@ public static SegmentMemory getOrCreateSegmentMemory(Memory memory, LeftTupleNod smem = restoreSegmentFromPrototype(reteEvaluator, segmentRoot); if ( smem != null ) { - if (NodeTypeEnums.isBetaNode(segmentRoot) && segmentRoot.isRightInputIsRiaNode()) { - createRiaSegmentMemory((BetaNode) segmentRoot, reteEvaluator); + if (NodeTypeEnums.isBetaNode(segmentRoot) && segmentRoot.inputIsTupleToObjectNode()) { + createSubnetworkSegmentMemory((BetaNode) segmentRoot, reteEvaluator); } return smem; } @@ -99,7 +99,7 @@ private static SegmentMemory restoreSegmentFromPrototype(ReteEvaluator reteEvalu SegmentMemory smem = reteEvaluator.getKnowledgeBase().createSegmentFromPrototype(reteEvaluator, proto); - updateRiaAndTerminalMemory(smem, proto, reteEvaluator); + updateSubnetworkAndTerminalMemory(smem, proto, reteEvaluator); return smem; } @@ -115,10 +115,10 @@ public static SegmentMemory getQuerySegmentMemory(ReteEvaluator reteEvaluator, Q return querySmem; } - static RightInputAdapterNode createRiaSegmentMemory( BetaNode betaNode, ReteEvaluator reteEvaluator ) { - RightInputAdapterNode riaNode = (RightInputAdapterNode) betaNode.getRightInput(); + static TupleToObjectNode createSubnetworkSegmentMemory(BetaNode betaNode, ReteEvaluator reteEvaluator) { + TupleToObjectNode tton = (TupleToObjectNode) betaNode.getRightInput().getParent(); - LeftTupleSource subnetworkLts = riaNode.getStartTupleSource(); + LeftTupleSource subnetworkLts = tton.getStartTupleSource(); Memory rootSubNetwokrMem = reteEvaluator.getNodeMemory( (MemoryFactory) subnetworkLts ); SegmentMemory subNetworkSegmentMemory = rootSubNetwokrMem.getSegmentMemory(); @@ -126,7 +126,7 @@ static RightInputAdapterNode createRiaSegmentMemory( BetaNode betaNode, ReteEval // we need to stop recursion here getOrCreateSegmentMemory(rootSubNetwokrMem, subnetworkLts, reteEvaluator); } - return riaNode; + return tton; } public static void createChildSegments(ReteEvaluator reteEvaluator, SegmentMemory smem, LeftTupleSinkPropagator sinkProp) { @@ -150,16 +150,16 @@ public static SegmentMemory createChildSegment(ReteEvaluator reteEvaluator, Left } /** - * This adds the segment memory to the terminal node or ria node's list of memories. + * This adds the segment memory to the terminal node or TupleToObjectNode node's list of memories. * In the case of the terminal node this allows it to know that all segments from * the tip to root are linked. - * In the case of the ria node its all the segments up to the start of the subnetwork. - * This is because the rianode only cares if all of it's segments are linked, then + * In the case of the TupleToObjectNode node its all the segments up to the start of the subnetwork. + * This is because the TupleToObjectNode only cares if all of it's segments are linked, then * it sets the bit of node it is the right input for. */ - private static void updateRiaAndTerminalMemory(SegmentMemory smem, - SegmentPrototype proto, - ReteEvaluator reteEvaluator) { + private static void updateSubnetworkAndTerminalMemory(SegmentMemory smem, + SegmentPrototype proto, + ReteEvaluator reteEvaluator) { for (PathEndNode endNode : proto.getPathEndNodes()) { if (!isInsideSubnetwork(endNode, proto)) { // While SegmentPrototypes are added for entire path, for traversal reasons. diff --git a/drools-core/src/main/java/org/drools/core/phreak/SegmentPropagator.java b/drools-core/src/main/java/org/drools/core/phreak/SegmentPropagator.java index 70779468ac0..d76960eeaeb 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/SegmentPropagator.java +++ b/drools-core/src/main/java/org/drools/core/phreak/SegmentPropagator.java @@ -32,7 +32,7 @@ import static org.drools.base.reteoo.NodeTypeEnums.AccumulateNode; import static org.drools.core.phreak.TupleEvaluationUtil.forceFlushLeftTuple; -import static org.drools.core.phreak.TupleEvaluationUtil.forceFlushWhenRiaNode; +import static org.drools.core.phreak.TupleEvaluationUtil.forceFlushWhenSubnetwork; public class SegmentPropagator { @@ -60,7 +60,7 @@ public static void propagate(SegmentMemory sourceSegment, TupleSets leftTuples, continue; } forceFlushLeftTuple(dataDrivenPmem, smem, reteEvaluator, smem.getStagedLeftTuples()); - forceFlushWhenRiaNode(reteEvaluator, dataDrivenPmem); + forceFlushWhenSubnetwork(reteEvaluator, dataDrivenPmem); } } } diff --git a/drools-core/src/main/java/org/drools/core/phreak/StackEntry.java b/drools-core/src/main/java/org/drools/core/phreak/StackEntry.java index bf1a2c8a5f9..8bfc4a1a680 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/StackEntry.java +++ b/drools-core/src/main/java/org/drools/core/phreak/StackEntry.java @@ -42,8 +42,8 @@ public class StackEntry extends AbstractLinkedListNode { private final SegmentMemory[] smems; private final int smemIndex; private final TupleSets trgTuples; - private final boolean resumeFromNextNode; - private final boolean processRian; + private final boolean resumeFromNextNode; + private final boolean processSubnetwork; public StackEntry(NetworkNode node, @@ -55,17 +55,17 @@ public StackEntry(NetworkNode node, int smemIndex, TupleSets trgTuples, boolean resumeFromNextNode, - boolean processRian) { - this.bit = bit; - this.node = node; - this.sink = sink; - this.pmem = pmem; - this.nodeMem = nodeMem; - this.smems = smems; - this.smemIndex = smemIndex; - this.trgTuples = trgTuples; + boolean processSubnetwork) { + this.bit = bit; + this.node = node; + this.sink = sink; + this.pmem = pmem; + this.nodeMem = nodeMem; + this.smems = smems; + this.smemIndex = smemIndex; + this.trgTuples = trgTuples; this.resumeFromNextNode = resumeFromNextNode; - this.processRian = processRian; + this.processSubnetwork = processSubnetwork; } public long getBit() { @@ -105,7 +105,7 @@ public boolean isResumeFromNextNode() { } - public boolean isProcessRian() { - return processRian; + public boolean isProcessSubnetwork() { + return processSubnetwork; } } diff --git a/drools-core/src/main/java/org/drools/core/phreak/TupleEvaluationUtil.java b/drools-core/src/main/java/org/drools/core/phreak/TupleEvaluationUtil.java index 2fe3820f41f..9bb89fd6fe7 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/TupleEvaluationUtil.java +++ b/drools-core/src/main/java/org/drools/core/phreak/TupleEvaluationUtil.java @@ -34,7 +34,6 @@ import org.drools.core.reteoo.PathEndNode; import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.SegmentMemory; -import org.drools.core.reteoo.TerminalNode; import org.drools.core.reteoo.Tuple; import org.drools.core.util.LinkedList; @@ -51,7 +50,7 @@ public static boolean flushLeftTupleIfNecessary(ReteEvaluator reteEvaluator, Seg } forceFlushLeftTuple( pmem, sm, reteEvaluator, createLeftTupleTupleSets(leftTuple, stagedType) ); - forceFlushWhenRiaNode(reteEvaluator, pmem); + forceFlushWhenSubnetwork(reteEvaluator, pmem); return true; } @@ -78,15 +77,15 @@ public static TupleSets createLeftTupleTupleSets(TupleImpl leftTuple, short stag return leftTupleSets; } - public static void forceFlushWhenRiaNode(ReteEvaluator reteEvaluator, PathMemory pmem) { - for (PathMemory outPmem : findPathsToFlushFromRia(reteEvaluator, pmem)) { + public static void forceFlushWhenSubnetwork(ReteEvaluator reteEvaluator, PathMemory pmem) { + for (PathMemory outPmem : findPathsToFlushFromSubnetwork(reteEvaluator, pmem)) { forceFlushPath(reteEvaluator, outPmem); } } - public static List findPathsToFlushFromRia(ReteEvaluator reteEvaluator, PathMemory pmem) { + public static List findPathsToFlushFromSubnetwork(ReteEvaluator reteEvaluator, PathMemory pmem) { List paths = null; - if (pmem.isDataDriven() && pmem.getNodeType() == NodeTypeEnums.RightInputAdapterNode) { + if (pmem.isDataDriven() && pmem.getNodeType() == NodeTypeEnums.TupleToObjectNode) { for (PathEndNode pnode : pmem.getPathEndNode().getPathEndNodes()) { if ( NodeTypeEnums.isTerminalNode(pnode)) { PathMemory outPmem = reteEvaluator.getNodeMemory(pnode); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AbstractTerminalNode.java b/drools-core/src/main/java/org/drools/core/reteoo/AbstractTerminalNode.java index d510f41fcb5..43c5e2c7544 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AbstractTerminalNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AbstractTerminalNode.java @@ -114,6 +114,11 @@ public PathMemSpec getPathMemSpec() { return getPathMemSpec(null); } + @Override + public BaseNode getParent() { + return tupleSource; + } + @Override public void setPathMemSpec(PathMemSpec pathMemSpec) { this.pathMemSpec = pathMemSpec; @@ -130,7 +135,7 @@ public PathMemSpec getPathMemSpec(TerminalNode removingTN) { @Override public void resetPathMemSpec(TerminalNode removingTN) { // null all PathMemSpecs, for all pathEnds, or the recursion will use a previous value. - // calling calculatePathMemSpec, will eventually getPathMemSpec on all nested rians, so previous values must be nulled + // calling calculatePathMemSpec, will eventually getPathMemSpec on all nested ttons, so previous values must be nulled Arrays.stream(pathEndNodes).forEach( n -> { n.nullPathMemSpec(); n.setSegmentPrototypes(null); @@ -212,7 +217,7 @@ public void setObjectCount(int count) { protected void initDeclaredMask(BuildContext context) { if ( !(NodeTypeEnums.isLeftInputAdapterNode(unwrapTupleSource()))) { // RTN's not after LIANode are not relevant for property specific, so don't block anything. - setDeclaredMask( AllSetBitMask.get() ); + declaredMask = AllSetBitMask.get(); return; } @@ -221,11 +226,11 @@ protected void initDeclaredMask(BuildContext context) { if ( isPropertyReactive(context.getRuleBase(), objectType) ) { List accessibleProperties = pattern.getAccessibleProperties( context.getRuleBase() ); - setDeclaredMask( pattern.getPositiveWatchMask(accessibleProperties) ); - setNegativeMask( pattern.getNegativeWatchMask(accessibleProperties) ); + declaredMask = pattern.getPositiveWatchMask(accessibleProperties); + negativeMask = pattern.getNegativeWatchMask(accessibleProperties); } else { // if property specific is not on, then accept all modification propagations - setDeclaredMask( AllSetBitMask.get() ); + declaredMask = AllSetBitMask.get(); } } @@ -234,14 +239,14 @@ public void initInferredMask() { if ( NodeTypeEnums.isLeftInputAdapterNode(leftTupleSource) && ((LeftInputAdapterNode)leftTupleSource).getParentObjectSource().getType() == NodeTypeEnums.AlphaNode ) { AlphaNode alphaNode = (AlphaNode) ((LeftInputAdapterNode)leftTupleSource).getParentObjectSource(); - setInferredMask( alphaNode.updateMask( getDeclaredMask() ) ); + inferredMask = alphaNode.updateMask( getDeclaredMask() ); } else { - setInferredMask( getDeclaredMask() ); + inferredMask = getDeclaredMask(); } - setInferredMask( getInferredMask().resetAll( getNegativeMask() ) ); + inferredMask = getInferredMask().resetAll( getNegativeMask() ); if ( getNegativeMask().isAllSet() && !getDeclaredMask().isAllSet() ) { - setInferredMask( getInferredMask().setAll( getDeclaredMask() ) ); + inferredMask = getInferredMask().setAll( getDeclaredMask() ); } } @@ -278,27 +283,11 @@ public BitMask getDeclaredMask() { public BitMask getInferredMask() { return inferredMask; } - - public BitMask getLeftInferredMask() { - return inferredMask; - } - - public void setDeclaredMask(BitMask mask) { - declaredMask = mask; - } - - public void setInferredMask(BitMask mask) { - inferredMask = mask; - } public BitMask getNegativeMask() { return negativeMask; } - public void setNegativeMask(BitMask mask) { - negativeMask = mask; - } - public void networkUpdated(UpdateContext updateContext) { getLeftTupleSource().networkUpdated(updateContext); } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AccumulateNode.java b/drools-core/src/main/java/org/drools/core/reteoo/AccumulateNode.java index 2ff681e4f66..28b829aab90 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AccumulateNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AccumulateNode.java @@ -69,7 +69,7 @@ public AccumulateNode() { public AccumulateNode(final int id, final LeftTupleSource leftInput, - final ObjectSource rightInput, + final RightInputAdapterNode rightInput, final AlphaNodeFieldConstraint[] resultConstraints, final BetaConstraints sourceBinder, final BetaConstraints resultBinder, @@ -98,7 +98,7 @@ public AccumulateNode(final int id, } private void addAccFunctionDeclarationsToLeftMask(InternalRuleBase ruleBase, LeftTupleSource leftInput, Accumulate accumulate) { - BitMask leftMask = getLeftInferredMask(); + BitMask leftMask = getInferredMask(); ObjectType leftObjectType = leftInput.getObjectType(); if (leftObjectType instanceof ClassObjectType ) { TypeDeclaration typeDeclaration = ruleBase.getExactTypeDeclaration(((ClassObjectType) leftObjectType).getClassType() ); @@ -111,12 +111,12 @@ private void addAccFunctionDeclarationsToLeftMask(InternalRuleBase ruleBase, Lef } } } - setLeftInferredMask( leftMask ); + setInferredMask(leftMask); } @Override protected ObjectType getObjectTypeForPropertyReactivity( LeftInputAdapterNode leftInput, Pattern pattern ) { - return pattern != null && isRightInputIsRiaNode() ? + return pattern != null && rightInput.inputIsTupleToObjectNode() ? pattern.getObjectType() : leftInput.getParentObjectSource().getObjectTypeNode().getObjectType(); } @@ -173,7 +173,7 @@ public boolean equals( final Object object ) { } AccumulateNode other = (AccumulateNode) object; - return this.leftInput.getId() == other.leftInput.getId() && this.rightInput.getId() == other.rightInput.getId() && + return this.leftInput.getId() == other.leftInput.getId() && this.rightInput.equals(other.rightInput)&& this.constraints.equals( other.constraints ) && this.accumulate.equals( other.accumulate ) && this.resultBinder.equals( other.resultBinder ) && @@ -369,35 +369,4 @@ public void clear() { lastTupleList = null; } } - - /** - * @inheritDoc - * - * If an object is retract, call modify tuple for each - * tuple match. - */ - public void retractRightTuple( final TupleImpl rightTuple, - final PropagationContext pctx, - final ReteEvaluator reteEvaluator ) { - final AccumulateMemory memory = (AccumulateMemory) reteEvaluator.getNodeMemory( this ); - - BetaMemory bm = memory.getBetaMemory(); - rightTuple.setPropagationContext( pctx ); - doDeleteRightTuple( rightTuple, reteEvaluator, bm ); - } - - @Override - public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean doRemove(RuleRemovalContext context, ReteooBuilder builder) { - if ( !isInUse() ) { - getLeftTupleSource().removeTupleSink( this ); - getRightInput().removeObjectSink( this ); - return true; - } - return false; - } } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AccumulateRight.java b/drools-core/src/main/java/org/drools/core/reteoo/AccumulateRight.java new file mode 100644 index 00000000000..ece549033be --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/reteoo/AccumulateRight.java @@ -0,0 +1,42 @@ +package org.drools.core.reteoo; + +import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.reteoo.AccumulateNode.AccumulateMemory; +import org.drools.core.reteoo.builder.BuildContext; + +public class AccumulateRight extends RightInputAdapterNode { + + public AccumulateRight(int id, ObjectSource rightInput, BuildContext context) { + super(id, rightInput, context); + } + + + /** + * @inheritDoc + * + * If an object is retract, call modify tuple for each + * tuple match. + */ + @Override + public void retractRightTuple( final TupleImpl rightTuple, + final PropagationContext pctx, + final ReteEvaluator reteEvaluator) { + final AccumulateMemory memory = (AccumulateMemory) reteEvaluator.getNodeMemory(betaNode); + + BetaMemory bm = memory.getBetaMemory(); + rightTuple.setPropagationContext( pctx ); + doDeleteRightTuple( rightTuple, reteEvaluator, bm ); + } + + @Override + public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + throw new UnsupportedOperationException(); + } + + @Override + public int getType() { + return NodeTypeEnums.AccumulateRightAdapterNode; + } +} diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AlphaNode.java b/drools-core/src/main/java/org/drools/core/reteoo/AlphaNode.java index 9214e71e3bf..adb450556b7 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AlphaNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AlphaNode.java @@ -287,12 +287,12 @@ public boolean isAssociatedWith(Rule rule) { @Override public void addAssociatedTerminal(BaseTerminalNode terminalNode) { - sink.addAssociatedTerminal(terminalNode); + throw new UnsupportedOperationException(); } @Override public void removeAssociatedTerminal(BaseTerminalNode terminalNode) { - sink.removeAssociatedTerminal(terminalNode); + throw new UnsupportedOperationException(); } @Override diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AlphaTerminalNode.java b/drools-core/src/main/java/org/drools/core/reteoo/AlphaTerminalNode.java index 66b53817c0e..99d6107c8c0 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AlphaTerminalNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AlphaTerminalNode.java @@ -64,9 +64,9 @@ public void modifyObject(InternalFactHandle factHandle, ModifyPreviousTuples mod NetworkNode[] sinks = getSinks(); for (int i = 0; i < sinks.length; i++) { - TerminalNode rtn = ( TerminalNode ) sinks[i]; - ObjectTypeNodeId otnId = rtn.getLeftInputOtnId(); - TupleImpl leftTuple = processDeletesFromModify(modifyPreviousTuples, context, reteEvaluator, otnId); + TerminalNode rtn = ( TerminalNode ) sinks[i]; + ObjectTypeNodeId otnId = rtn.getInputOtnId(); + TupleImpl leftTuple = processDeletesFromModify(modifyPreviousTuples, context, reteEvaluator, otnId); RuleAgendaItem agendaItem = getRuleAgendaItem( reteEvaluator, activationsManager, rtn, true ); RuleExecutor executor = agendaItem.getRuleExecutor(); @@ -74,7 +74,7 @@ public void modifyObject(InternalFactHandle factHandle, ModifyPreviousTuples mod if ( leftTuple != null && leftTuple.getInputOtnId().equals(otnId) ) { modifyPreviousTuples.removeLeftTuple(partitionId); leftTuple.reAdd(); - if ( context.getModificationMask().intersects( rtn.getLeftInferredMask() ) ) { + if ( context.getModificationMask().intersects( rtn.getInferredMask()) ) { leftTuple.setPropagationContext( context ); PhreakRuleTerminalNode.doLeftTupleUpdate( rtn, executor, activationsManager, (RuleTerminalNodeLeftTuple) leftTuple ); if (leftTuple.isFullMatch()) { @@ -82,7 +82,7 @@ public void modifyObject(InternalFactHandle factHandle, ModifyPreviousTuples mod } } } else { - if ( context.getModificationMask().intersects( rtn.getLeftInferredMask() ) ) { + if ( context.getModificationMask().intersects( rtn.getInferredMask()) ) { leftTuple = TupleFactory.createLeftTuple( rtn, factHandle, true ); leftTuple.setPropagationContext( context ); PhreakRuleTerminalNode.doLeftTupleInsert( rtn, executor, activationsManager, agendaItem, (RuleTerminalNodeLeftTuple) leftTuple ); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java b/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java index c224da685b5..f2b78bdc5d6 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java @@ -81,7 +81,7 @@ public AsyncReceiveNode( final int id, this.betaConstraints = (binder == null) ? EmptyBetaConstraints.getInstance() : binder; this.betaConstraints.init(context, getType()); - initMasks( context, tupleSource ); + initMasks( context ); hashcode = calculateHashCode(); } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AsyncSendNode.java b/drools-core/src/main/java/org/drools/core/reteoo/AsyncSendNode.java index 1d1665a0a26..cd0e252dda5 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AsyncSendNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AsyncSendNode.java @@ -82,7 +82,7 @@ public AsyncSendNode( final int id, this.send = send; this.messageId = send.getMessageId(); - initMasks(context, tupleSource); + initMasks(context); hashcode = calculateHashCode(); } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/BetaMemory.java b/drools-core/src/main/java/org/drools/core/reteoo/BetaMemory.java index fd83472bca7..cddd87111f6 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/BetaMemory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/BetaMemory.java @@ -22,21 +22,21 @@ import org.drools.core.common.ReteEvaluator; import org.drools.core.common.TupleSets; import org.drools.core.common.TupleSetsImpl; -import org.drools.core.reteoo.RightInputAdapterNode.RiaPathMemory; +import org.drools.core.reteoo.TupleToObjectNode.SubnetworkPathMemory; import org.drools.core.util.AbstractLinkedListNode; public class BetaMemory extends AbstractLinkedListNode implements SegmentNodeMemory { private TupleMemory leftTupleMemory; private TupleMemory rightTupleMemory; - private TupleSets stagedRightTuples; - private C context; + private TupleSets stagedRightTuples; + private C context; // the node type this memory belongs to - private int nodeType; - private SegmentMemory segmentMemory; - private long nodePosMaskBit; - private int counter; - private RiaPathMemory riaRuleMemory; + private int nodeType; + private SegmentMemory segmentMemory; + private long nodePosMaskBit; + private int counter; + private SubnetworkPathMemory subnetworkPathMemory; public BetaMemory() { } @@ -68,12 +68,12 @@ public TupleMemory getLeftTupleMemory() { return this.leftTupleMemory; } - public RiaPathMemory getRiaRuleMemory() { - return riaRuleMemory; + public SubnetworkPathMemory getSubnetworkPathMemory() { + return subnetworkPathMemory; } - public void setRiaRuleMemory(RiaPathMemory riaRuleMemory) { - this.riaRuleMemory = riaRuleMemory; + public void setSubnetworkPathMemory(SubnetworkPathMemory subnetworkPathMemory) { + this.subnetworkPathMemory = subnetworkPathMemory; } /** diff --git a/drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java b/drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java index 357d7203501..f0be4ccae4f 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java @@ -23,13 +23,11 @@ import java.util.List; import java.util.Objects; -import org.drools.base.base.ObjectType; import org.drools.base.common.NetworkNode; import org.drools.base.common.RuleBasePartitionId; import org.drools.base.reteoo.BaseTerminalNode; import org.drools.base.reteoo.NodeTypeEnums; import org.drools.base.rule.IndexableConstraint; -import org.drools.base.rule.Pattern; import org.drools.base.util.index.IndexUtil; import org.drools.core.RuleBaseConfiguration; import org.drools.core.common.BetaConstraints; @@ -47,66 +45,44 @@ import org.drools.core.common.SingleNonIndexSkipBetaConstraints; import org.drools.core.common.TripleBetaConstraints; import org.drools.core.common.TripleNonIndexSkipBetaConstraints; -import org.drools.core.common.TupleSets; import org.drools.core.common.UpdateContext; import org.drools.core.phreak.DetachedTuple; import org.drools.core.reteoo.AccumulateNode.AccumulateMemory; import org.drools.core.reteoo.builder.BuildContext; import org.drools.base.rule.constraint.BetaConstraint; import org.drools.core.util.FastIterator; -import org.drools.util.bitmask.AllSetBitMask; -import org.drools.util.bitmask.BitMask; -import org.drools.util.bitmask.EmptyBitMask; import org.kie.api.definition.rule.Rule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.drools.base.reteoo.PropertySpecificUtil.isPropertyReactive; -import static org.drools.core.phreak.RuleNetworkEvaluator.doUpdatesReorderChildLeftTuple; import static org.drools.core.phreak.TupleEvaluationUtil.flushLeftTupleIfNecessary; public abstract class BetaNode extends LeftTupleSource implements LeftTupleSinkNode, - ObjectSinkNode, - RightTupleSink, MemoryFactory { protected static final Logger log = LoggerFactory.getLogger(BetaNode.class); protected static final boolean isLogTraceEnabled = log.isTraceEnabled(); - protected ObjectSource rightInput; + protected RightInputAdapterNode rightInput; protected BetaConstraints constraints; private LeftTupleSinkNode previousTupleSinkNode; private LeftTupleSinkNode nextTupleSinkNode; - private ObjectSinkNode previousObjectSinkNode; - private ObjectSinkNode nextObjectSinkNode; - - private ObjectTypeNodeId rightInputOtnId = ObjectTypeNodeId.DEFAULT_ID; - protected boolean objectMemory = true; // hard coded to true protected boolean tupleMemoryEnabled; protected boolean indexedUnificationJoin; - private BitMask rightDeclaredMask = EmptyBitMask.get(); - private BitMask rightInferredMask = EmptyBitMask.get(); - private BitMask rightNegativeMask = EmptyBitMask.get(); - private Collection leftListenedProperties; - private Collection rightListenedProperties; - - protected boolean rightInputIsRiaNode; - private transient ObjectTypeNode objectTypeNode; + private boolean indexable; - private boolean rightInputIsPassive; - private boolean indexable; // ------------------------------------------------------------ // Constructors @@ -125,15 +101,14 @@ public BetaNode() { */ protected BetaNode(final int id, final LeftTupleSource leftInput, - final ObjectSource rightInput, + final RightInputAdapterNode rightInput, final BetaConstraints constraints, final BuildContext context) { super(id, context); + rightInput.setBetaNode(this); setLeftTupleSource(leftInput); this.rightInput = rightInput; - rightInputIsRiaNode = NodeTypeEnums.RightInputAdapterNode == rightInput.getType(); - setConstraints(constraints); if (this.constraints == null) { @@ -143,7 +118,7 @@ protected BetaNode(final int id, this.constraints.init(context, getType()); this.constraints.registerEvaluationContext(context); - initMasks(context, leftInput); + initMasks(context); setStreamMode( context.isStreamMode() && getObjectTypeNode(context).getObjectType().isEvent() ); @@ -159,44 +134,18 @@ private ObjectTypeNode getObjectTypeNode(BuildContext context) { } @Override - protected void initDeclaredMask(BuildContext context, - LeftTupleSource leftInput) { - if (context == null || context.getLastBuiltPatterns() == null) { - // only happens during unit tests - rightDeclaredMask = AllSetBitMask.get(); - super.initDeclaredMask(context, leftInput); - return; - } - - Pattern pattern = context.getLastBuiltPatterns()[0]; // right input pattern - rightInputIsPassive = pattern.isPassive(); - - if (!isRightInputIsRiaNode()) { - ObjectType objectType = pattern.getObjectType(); - - if (isPropertyReactive(context.getRuleBase(), objectType)) { - rightListenedProperties = pattern.getListenedProperties(); - List accessibleProperties = pattern.getAccessibleProperties( context.getRuleBase() ); - rightDeclaredMask = pattern.getPositiveWatchMask(accessibleProperties); - rightDeclaredMask = rightDeclaredMask.setAll(constraints.getListenedPropertyMask(pattern, objectType, accessibleProperties)); - rightNegativeMask = pattern.getNegativeWatchMask(accessibleProperties); - } else { - // if property reactive is not on, then accept all modification propagations - rightDeclaredMask = AllSetBitMask.get(); - } - } else { - rightDeclaredMask = AllSetBitMask.get(); - // There would have been no right input pattern, so swap current to first, so leftInput can still work - context.setLastBuiltPattern( context.getLastBuiltPatterns()[0] ); - } + protected void initDeclaredMask(BuildContext context) { + rightInput.initDeclaredMask(context); - super.initDeclaredMask(context, leftInput); + super.initDeclaredMask(context); } @Override public void setPartitionId(BuildContext context, RuleBasePartitionId partitionId ) { - if (rightInput.getPartitionId() != RuleBasePartitionId.MAIN_PARTITION && !rightInput.getPartitionId().equals( partitionId )) { - this.partitionId = rightInput.getPartitionId(); + RuleBasePartitionId parentId = rightInput.getParent().getPartitionId(); + if (parentId != RuleBasePartitionId.MAIN_PARTITION && !parentId.equals(partitionId)) { + this.partitionId = parentId; + rightInput.setPartitionId(context, this.partitionId); context.setPartitionId( this.partitionId ); leftInput.setSourcePartitionId( context, this.partitionId ); } else { @@ -209,26 +158,10 @@ protected void setLeftListenedProperties(Collection leftListenedProperti this.leftListenedProperties = leftListenedProperties; } - public void initInferredMask() { - initInferredMask(leftInput); - } - @Override - protected void initInferredMask(LeftTupleSource leftInput) { - super.initInferredMask( leftInput ); - - ObjectSource unwrappedRight = unwrapRightInput(); - if ( unwrappedRight.getType() == NodeTypeEnums.AlphaNode ) { - AlphaNode alphaNode = (AlphaNode) unwrappedRight; - rightInferredMask = alphaNode.updateMask( rightDeclaredMask ); - } else { - rightInferredMask = rightDeclaredMask; - } - rightInferredMask = rightInferredMask.resetAll(rightNegativeMask); - } - - public ObjectSource unwrapRightInput() { - return rightInput; + protected void initInferredMask() { + super.initInferredMask(); + rightInput.initInferredMask(); } private void setUnificationJoin() { @@ -253,127 +186,12 @@ private void setUnificationJoin() { } } - @Override - public void assertObject( InternalFactHandle factHandle, PropagationContext pctx, ReteEvaluator reteEvaluator ) { - final BetaMemory memory = (BetaMemory) getBetaMemoryFromRightInput(this, reteEvaluator); - - RightTuple rightTuple = createRightTuple(factHandle, this, pctx); - - boolean stagedInsertWasEmpty = memory.getStagedRightTuples().addInsert(rightTuple); - if ( isLogTraceEnabled ) { - log.trace("BetaNode stagedInsertWasEmpty={}", stagedInsertWasEmpty ); - } - - boolean shouldFlush = isStreamMode(); - if ( memory.getAndIncCounter() == 0 ) { - if ( stagedInsertWasEmpty ) { - memory.setNodeDirtyWithoutNotify(); - } - shouldFlush = memory.linkNode( this, reteEvaluator, !rightInputIsPassive ) | shouldFlush; - } else if ( stagedInsertWasEmpty ) { - shouldFlush = memory.setNodeDirty( this, reteEvaluator, !rightInputIsPassive ) | shouldFlush; - } - - if (shouldFlush) { - flushLeftTupleIfNecessary( reteEvaluator, memory.getOrCreateSegmentMemory( this, reteEvaluator ), isStreamMode() ); - } - } - - public void modifyObject(InternalFactHandle factHandle, ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, ReteEvaluator reteEvaluator) { - TupleImpl rightTuple = modifyPreviousTuples.peekRightTuple(partitionId); - - // if the peek is for a different OTN we assume that it is after the current one and then this is an assert - while ( rightTuple != null && rightTuple.getInputOtnId().before(getRightInputOtnId()) ) { - modifyPreviousTuples.removeRightTuple(partitionId); - - // we skipped this node, due to alpha hashing, so retract now - rightTuple.setPropagationContext( context ); - BetaMemory bm = getBetaMemory(rightTuple.getSink(), reteEvaluator); - (( BetaNode ) rightTuple.getSink()).doDeleteRightTuple(rightTuple, reteEvaluator, bm); - rightTuple = modifyPreviousTuples.peekRightTuple(partitionId); - } - - if ( rightTuple != null && rightTuple.getInputOtnId().equals(getRightInputOtnId()) ) { - modifyPreviousTuples.removeRightTuple(partitionId); - rightTuple.reAdd(); - if ( context.getModificationMask().intersects(getRightInferredMask()) ) { - // RightTuple previously existed, so continue as modify - rightTuple.setPropagationContext( context ); // only update, if the mask intersects - - BetaMemory bm = getBetaMemory(this, reteEvaluator); - rightTuple.setPropagationContext( context ); - doUpdateRightTuple(rightTuple, reteEvaluator, bm); - } else if (rightTuple.getMemory() != null) { - reorderRightTuple(reteEvaluator, rightTuple); - } - } else { - if ( context.getModificationMask().intersects(getRightInferredMask()) ) { - // RightTuple does not exist for this node, so create and continue as assert - assertObject( factHandle, context, reteEvaluator ); - } - } - } - - protected void reorderRightTuple(ReteEvaluator reteEvaluator, TupleImpl rightTuple) { - getBetaMemory(this, reteEvaluator).getRightTupleMemory().removeAdd(rightTuple); - doUpdatesReorderChildLeftTuple(rightTuple); - } - - public void doDeleteRightTuple(final TupleImpl rightTuple, - final ReteEvaluator reteEvaluator, - final BetaMemory memory) { - TupleSets stagedRightTuples = memory.getStagedRightTuples(); - - boolean stagedDeleteWasEmpty = stagedRightTuples.addDelete(rightTuple); - - boolean shouldFlush = isStreamMode(); - if ( memory.getAndDecCounter() == 1 ) { - if ( stagedDeleteWasEmpty ) { - memory.setNodeDirtyWithoutNotify(); - } - shouldFlush = memory.unlinkNode(reteEvaluator) | shouldFlush; - } else if ( stagedDeleteWasEmpty ) { - // nothing staged before, notify rule, so it can evaluate network - shouldFlush = memory.setNodeDirty( this, reteEvaluator ) | shouldFlush; - } - - if (shouldFlush) { - flushLeftTupleIfNecessary( reteEvaluator, memory.getOrCreateSegmentMemory( this, reteEvaluator ), isStreamMode() ); - } - } - - public void doUpdateRightTuple(final TupleImpl rightTuple, - final ReteEvaluator reteEvaluator, - final BetaMemory memory) { - TupleSets stagedRightTuples = memory.getStagedRightTuples(); - - boolean stagedUpdateWasEmpty = stagedRightTuples.addUpdate( rightTuple ); - - boolean shouldFlush = isStreamMode(); - if ( stagedUpdateWasEmpty ) { - shouldFlush = memory.setNodeDirty( this, reteEvaluator ) | shouldFlush; - } - - if (shouldFlush) { - flushLeftTupleIfNecessary( reteEvaluator, memory.getOrCreateSegmentMemory( this, reteEvaluator ), isStreamMode() ); - } - } - - public boolean isRightInputIsRiaNode() { - return rightInputIsRiaNode; - } - - public boolean isRightInputPassive() { - return rightInputIsPassive; - } - - public ObjectSource getRightInput() { + public RightInputAdapterNode getRightInput() { return this.rightInput; } - public void setRightInput( ObjectSource rightInput ) { - this.rightInput = rightInput; - rightInputIsRiaNode = NodeTypeEnums.RightInputAdapterNode == rightInput.getType(); + public boolean inputIsTupleToObjectNode() { + return rightInput.inputIsTupleToObjectNode(); } public FastIterator getRightIterator(TupleMemory memory) { @@ -395,7 +213,7 @@ public RightTuple getFirstRightTuple(final TupleImpl leftTuple, } public FastIterator getLeftIterator(TupleMemory memory) { - if (rightInputIsRiaNode) { + if (rightInput.inputIsTupleToObjectNode()) { return FastIterator.NullFastIterator.INSTANCE; } else { if ( this.indexedUnificationJoin ) { @@ -409,7 +227,7 @@ public FastIterator getLeftIterator(TupleMemory memory) { public TupleImpl getFirstLeftTuple(final TupleImpl rightTuple, final TupleMemory memory, final FastIterator it) { - if (rightInputIsRiaNode) { + if (rightInput.inputIsTupleToObjectNode()) { return getStartTuple(rightTuple); } else { if ( this.indexedUnificationJoin ) { @@ -421,7 +239,8 @@ public TupleImpl getFirstLeftTuple(final TupleImpl rightTuple, } public TupleImpl getStartTuple(TupleImpl lt) { - LeftTupleSource startTupleSource = (( RightInputAdapterNode ) getRightInput()).getStartTupleSource(); + + LeftTupleSource startTupleSource = ((TupleToObjectNode) rightInput.getParent()).getStartTupleSource(); // Iterate find start while (lt.getIndex() != startTupleSource.getPathIndex()-1) { // -1 as it needs the split node, not the start of the branch @@ -462,7 +281,7 @@ private void setConstraints(BetaConstraints constraints) { public void networkUpdated(UpdateContext updateContext) { updateContext.startVisitNode( leftInput ); - rightInput.networkUpdated( updateContext ); + rightInput.networkUpdated(updateContext); updateContext.endVisit(); if ( !updateContext.isVisiting( leftInput ) ) { leftInput.networkUpdated( updateContext ); @@ -485,33 +304,17 @@ public List getRules() { @Override public ObjectTypeNode getObjectTypeNode() { - if (objectTypeNode == null) { - ObjectSource source = this.rightInput; - while ( source != null ) { - if ( NodeTypeEnums.ObjectTypeNode == source.getType()) { - objectTypeNode = (ObjectTypeNode) source; - break; - } - source = source.source; - } - } - return objectTypeNode; + return rightInput.getObjectTypeNode(); } public void doAttach(BuildContext context) { super.doAttach(context); setUnificationJoin(); - this.rightInput.addObjectSink(this); + this.rightInput.doAttach(context); this.leftInput.addTupleSink( this, context ); } - public void byPassModifyToBetaNode (final InternalFactHandle factHandle, - final ModifyPreviousTuples modifyPreviousTuples, - final PropagationContext context, - final ReteEvaluator reteEvaluator) { - modifyObject( factHandle, modifyPreviousTuples, context, reteEvaluator ); - } public static BetaMemory getBetaMemory(NetworkNode node, ReteEvaluator reteEvaluator) { @@ -542,14 +345,11 @@ public String toString() { } protected int calculateHashCode() { - int hash = ( 23 * leftInput.hashCode() ) + ( 29 * rightInput.hashCode() ) + ( 31 * constraints.hashCode() ); + int hash = ( 23 * leftInput.hashCode() ) + (29 * rightInput.hashCode() ) + (31 * constraints.hashCode() ); if (leftListenedProperties != null) { hash += 37 * leftListenedProperties.hashCode(); } - if (rightListenedProperties != null) { - hash += 41 * rightListenedProperties.hashCode(); - } - return hash + (rightInputIsPassive ? 43 : 0); + return hash; } @Override @@ -565,11 +365,9 @@ public boolean equals(Object object) { BetaNode other = (BetaNode) object; return this.getClass() == other.getClass() && this.constraints.equals( other.constraints ) && - this.rightInputIsPassive == other.rightInputIsPassive && + this.rightInput.equals(other.rightInput) && Objects.equals(this.leftListenedProperties, other.leftListenedProperties) && - Objects.equals(this.rightListenedProperties, other.rightListenedProperties) && - this.leftInput.getId() == other.leftInput.getId() && - this.rightInput.getId() == other.rightInput.getId(); + this.leftInput.getId() == other.leftInput.getId(); } /** @@ -607,82 +405,47 @@ public LeftTupleSinkNode getPreviousLeftTupleSinkNode() { public void setPreviousLeftTupleSinkNode(final LeftTupleSinkNode previous) { this.previousTupleSinkNode = previous; } - - /** - * Returns the next node - * @return - * The next ObjectSinkNode - */ - public ObjectSinkNode getNextObjectSinkNode() { - return this.nextObjectSinkNode; - } - - /** - * Sets the next node - * @param next - * The next ObjectSinkNode - */ - public void setNextObjectSinkNode(final ObjectSinkNode next) { - this.nextObjectSinkNode = next; + void disablePropertyReactivity() { + rightInput.disablePropertyReactivity(); + if (NodeTypeEnums.isBetaNode(leftInput)) { + ((BetaNode)leftInput).disablePropertyReactivity(); + } } - /** - * Returns the previous node - * @return - * The previous ObjectSinkNode - */ - public ObjectSinkNode getPreviousObjectSinkNode() { - return this.previousObjectSinkNode; + @Override + public boolean doRemove(RuleRemovalContext context, ReteooBuilder builder) { + if ( !isInUse() ) { + getLeftTupleSource().removeTupleSink( this ); + return true; + } + return false; } /** - * Sets the previous node - * @param previous - * The previous ObjectSinkNode + * Associates this node with the give rule */ - public void setPreviousObjectSinkNode(final ObjectSinkNode previous) { - this.previousObjectSinkNode = previous; + public void addAssociation(Rule rule, BuildContext context) { + super.addAssociation(rule, context); + rightInput.addAssociation(rule, context); } - public RightTuple createRightTuple(InternalFactHandle handle, - RightTupleSink sink, - PropagationContext context) { - RightTuple rightTuple = new RightTuple(handle, sink ); - rightTuple.setPropagationContext( context ); - return rightTuple; - } - - public static BetaMemory getBetaMemoryFromRightInput(BetaNode betaNode, ReteEvaluator reteEvaluator) { - return NodeTypeEnums.AccumulateNode == betaNode.getType() ? - ((AccumulateMemory)reteEvaluator.getNodeMemory( betaNode )).getBetaMemory() : - (BetaMemory) reteEvaluator.getNodeMemory( betaNode ); - } - - public BitMask getRightDeclaredMask() { - return rightDeclaredMask; - } - - public BitMask getRightInferredMask() { - return rightInferredMask; - } - - void disablePropertyReactivity() { - rightInferredMask = AllSetBitMask.get(); - if (NodeTypeEnums.isBetaNode(leftInput)) { - ((BetaNode)leftInput).disablePropertyReactivity(); - } - } - - public BitMask getRightNegativeMask() { - return rightNegativeMask; + @Override + public boolean removeAssociation(Rule rule, RuleRemovalContext context) { + boolean result = super.removeAssociation(rule, context); + rightInput.removeAssociation(rule, context); + return result; } - public ObjectTypeNodeId getRightInputOtnId() { - return rightInputOtnId; + @Override + public void addAssociatedTerminal(BaseTerminalNode terminalNode) { + super.addAssociatedTerminal(terminalNode); + rightInput.addAssociatedTerminal(terminalNode); } - public void setRightInputOtnId(ObjectTypeNodeId rightInputOtnId) { - this.rightInputOtnId = rightInputOtnId; + @Override + public void removeAssociatedTerminal(BaseTerminalNode terminalNode) { + super.removeAssociatedTerminal(terminalNode); + rightInput.removeAssociatedTerminal(terminalNode); } /** @@ -710,13 +473,13 @@ public RightTupleSinkAdapter() { public void assertObject(final InternalFactHandle factHandle, final PropagationContext context, final ReteEvaluator reteEvaluator) { - ObjectTypeNodeId otnId = bnNode.getRightInputOtnId(); + ObjectTypeNodeId otnId = bnNode.getRightInput().getInputOtnId(); TupleImpl detached = factHandle.getLinkedTuples().detachRightTupleAfter(getPartitionId(), otnId); if (detached != null) { detachedTuples.add(new DetachedTuple((DefaultFactHandle) factHandle, detached)); } - bnNode.assertObject(factHandle, context, reteEvaluator); + bnNode.getRightInput().assertObject(factHandle, context, reteEvaluator); } public void modifyObject(InternalFactHandle factHandle, diff --git a/drools-core/src/main/java/org/drools/core/reteoo/CompositeObjectSinkAdapter.java b/drools-core/src/main/java/org/drools/core/reteoo/CompositeObjectSinkAdapter.java index 99eb4c941db..f69e3c1e5a3 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/CompositeObjectSinkAdapter.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/CompositeObjectSinkAdapter.java @@ -282,7 +282,13 @@ public ObjectSinkPropagator removeObjectSink(final ObjectSink sink) { } } - this.otherSinks.remove( (ObjectSinkNode) sink ); + // BetaRights must be removed by identity + for (Iterator it = otherSinks.iterator(); it.hasNext();) { + if (sink == it.next()) { + it.remove(); + break; + } + } if ( this.otherSinks.isEmpty() ) { this.otherSinks = null; @@ -859,20 +865,20 @@ public ObjectSink[] getSinks() { return newSinks; } - public void doLinkRiaNode(ReteEvaluator reteEvaluator) { + public void doLinkSubnetwork(ReteEvaluator reteEvaluator) { if ( this.otherSinks != null ) { - // this is only used for ria nodes when exists are shared, we know there is no indexing for those + // this is only used for TupleToObjectNode nodes when exists are shared, we know there is no indexing for those for ( ObjectSinkNode sink : this.otherSinks ) { - SingleObjectSinkAdapter.staticDoLinkRiaNode( sink, reteEvaluator ); + SingleObjectSinkAdapter.staticDoLinkSubnetwork(sink, reteEvaluator); } } } - public void doUnlinkRiaNode(ReteEvaluator reteEvaluator) { + public void doUnlinkSubnetwork(ReteEvaluator reteEvaluator) { if ( this.otherSinks != null ) { - // this is only used for ria nodes when exists are shared, we know there is no indexing for those + // this is only used for TupleToObjectNode nodes when exists are shared, we know there is no indexing for those for ( ObjectSinkNode sink : this.otherSinks ) { - SingleObjectSinkAdapter.staticDoUnlinkRiaNode( sink, reteEvaluator ); + SingleObjectSinkAdapter.staticDoUnlinkSubnetwork(sink, reteEvaluator); } } } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java b/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java index df9fb055ba9..f4d49dd6b08 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java @@ -220,14 +220,14 @@ public void byPassModifyToBetaNode( InternalFactHandle factHandle, ModifyPreviou } @Override - public void doLinkRiaNode( ReteEvaluator reteEvaluator ) { - throw new UnsupportedOperationException("This sink is only used for OTNs, it cannot be the sink for a RIA"); + public void doLinkSubnetwork(ReteEvaluator reteEvaluator) { + throw new UnsupportedOperationException("This sink is only used for OTNs, it cannot be the sink for a TupleToObjectNode"); } @Override - public void doUnlinkRiaNode( ReteEvaluator reteEvaluator ) { - throw new UnsupportedOperationException("This sink is only used for OTNs, it cannot be the sink for a RIA"); + public void doUnlinkSubnetwork(ReteEvaluator reteEvaluator) { + throw new UnsupportedOperationException("This sink is only used for OTNs, it cannot be the sink for a TupleToObjectNode"); } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ConditionalBranchNode.java b/drools-core/src/main/java/org/drools/core/reteoo/ConditionalBranchNode.java index c95e84ca86e..fcff4080429 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ConditionalBranchNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ConditionalBranchNode.java @@ -60,7 +60,7 @@ public ConditionalBranchNode(int id, this.tupleMemoryEnabled = context.isTupleMemoryEnabled(); this.branchEvaluator = branchEvaluator; - initMasks(context, tupleSource); + initMasks(context); hashcode = calculateHashCode(); } @@ -213,14 +213,14 @@ protected boolean doRemove(final RuleRemovalContext context, } @Override - protected void initDeclaredMask(BuildContext context, LeftTupleSource leftInput) { + public void initDeclaredMask(BuildContext context) { // See LeftTupleSource.initDeclaredMask() should result for the ConditionalBranch to result in ALLSET: // at the moment if pattern is null (e.g. for eval node) we cannot calculate the mask, so we leave it to 0 // // In other words, a conditional branch is analogous to an eval() call - mask ALL SET // To achieve the result, we highjack the call: - super.initDeclaredMask(null, null); + super.initDeclaredMask(null); } } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/EmptyObjectSinkAdapter.java b/drools-core/src/main/java/org/drools/core/reteoo/EmptyObjectSinkAdapter.java index 4a0b3be8128..b1f235d52a7 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/EmptyObjectSinkAdapter.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/EmptyObjectSinkAdapter.java @@ -94,12 +94,12 @@ public boolean equals(Object obj) { return obj instanceof EmptyObjectSinkAdapter; } - public void doLinkRiaNode(ReteEvaluator reteEvaluator) { + public void doLinkSubnetwork(ReteEvaluator reteEvaluator) { // TODO Auto-generated method stub } - public void doUnlinkRiaNode(ReteEvaluator reteEvaluator) { + public void doUnlinkSubnetwork(ReteEvaluator reteEvaluator) { // TODO Auto-generated method stub } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/EvalConditionNode.java b/drools-core/src/main/java/org/drools/core/reteoo/EvalConditionNode.java index c9e9275965a..7aa457ee388 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/EvalConditionNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/EvalConditionNode.java @@ -30,10 +30,8 @@ import org.drools.base.rule.EvalCondition; import org.drools.base.rule.RuleComponent; import org.drools.core.RuleBaseConfiguration; -import org.drools.core.common.InternalFactHandle; import org.drools.core.common.Memory; import org.drools.core.common.MemoryFactory; -import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; import org.drools.core.common.UpdateContext; import org.drools.core.reteoo.builder.BuildContext; @@ -74,7 +72,7 @@ public EvalConditionNode(final int id, this.setObjectCount(leftInput.getObjectCount()); // 'eval' nodes do not increase the count this.tupleMemoryEnabled = context.isTupleMemoryEnabled(); - initMasks(context, tupleSource); + initMasks(context); hashcode = calculateHashCode(); } @@ -89,8 +87,8 @@ public void networkUpdated(UpdateContext updateContext) { } @Override - protected void initInferredMask(LeftTupleSource leftInput) { - super.initInferredMask( leftInput ); + protected void initInferredMask() { + super.initInferredMask( ); if (NodeTypeEnums.isBetaNode(leftInput)) { ((BetaNode)leftInput).disablePropertyReactivity(); } @@ -268,8 +266,8 @@ public int hashCode() { } @Override - public void addAssociation( BuildContext context, Rule rule ) { - super.addAssociation(context, rule); + public void addAssociation(Rule rule, BuildContext context) { + super.addAssociation(rule, context); componentsMap.put(new RuleKey(rule, context.getSubRuleIndex()), context.peekRuleComponent()); } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ExistsNode.java b/drools-core/src/main/java/org/drools/core/reteoo/ExistsNode.java index ead9220acd9..25391378c6d 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ExistsNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ExistsNode.java @@ -19,9 +19,8 @@ package org.drools.core.reteoo; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.core.common.BaseNode; import org.drools.core.common.BetaConstraints; -import org.drools.core.common.PropagationContext; -import org.drools.core.common.ReteEvaluator; import org.drools.core.reteoo.builder.BuildContext; /** @@ -44,7 +43,7 @@ public ExistsNode() { } public ExistsNode(final int id, final LeftTupleSource leftInput, - final ObjectSource rightInput, + final RightInputAdapterNode rightInput, final BetaConstraints joinNodeBinder, final BuildContext context) { super( id, @@ -57,9 +56,9 @@ public ExistsNode(final int id, } public String toString() { - ObjectSource source = this.rightInput; + BaseNode source = this.rightInput; while ( source != null && source.getClass() != ObjectTypeNode.class ) { - source = source.source; + source = source.getParent(); } return "[ExistsNode(" + this.getId() + ") - " + ((source != null) ? ((ObjectTypeNode) source).getObjectType() : "") + "]"; } @@ -68,29 +67,6 @@ public int getType() { return NodeTypeEnums.ExistsNode; } - public void retractRightTuple(final TupleImpl rightTuple, - final PropagationContext pctx, - final ReteEvaluator reteEvaluator) { - final BetaMemory memory = (BetaMemory) reteEvaluator.getNodeMemory(this); - rightTuple.setPropagationContext( pctx ); - doDeleteRightTuple( rightTuple, reteEvaluator, memory ); - } - - @Override - public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean doRemove(RuleRemovalContext context, ReteooBuilder builder) { - if ( !isInUse() ) { - getLeftTupleSource().removeTupleSink( this ); - getRightInput().removeObjectSink( this ); - return true; - } - return false; - } - public boolean isLeftUpdateOptimizationAllowed() { return getRawConstraints().isLeftUpdateOptimizationAllowed(); } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ExistsRight.java b/drools-core/src/main/java/org/drools/core/reteoo/ExistsRight.java new file mode 100644 index 00000000000..246a3e7a3c4 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/reteoo/ExistsRight.java @@ -0,0 +1,32 @@ +package org.drools.core.reteoo; + +import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.reteoo.builder.BuildContext; + +public class ExistsRight extends RightInputAdapterNode { + + public ExistsRight(int id, ObjectSource rightInput, BuildContext context) { + super(id, rightInput, context); + } + + @Override + public void retractRightTuple(final TupleImpl rightTuple, + final PropagationContext pctx, + final ReteEvaluator reteEvaluator) { + final BetaMemory memory = (BetaMemory) reteEvaluator.getNodeMemory(betaNode); + rightTuple.setPropagationContext( pctx ); + doDeleteRightTuple( rightTuple, reteEvaluator, memory ); + } + + @Override + public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + throw new UnsupportedOperationException(); + } + + @Override + public int getType() { + return NodeTypeEnums.ExistsRightAdapterNode; + } +} diff --git a/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java b/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java index d0b4cffc483..07911833534 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java @@ -94,7 +94,7 @@ public FromNode(final int id, this.tupleMemoryEnabled = tupleMemoryEnabled; this.from = from; - initMasks(context, tupleSource); + initMasks(context); hashcode = calculateHashCode(); } @@ -145,17 +145,16 @@ public BetaConstraints getBetaConstraints() { } @Override - protected void initDeclaredMask(BuildContext context, - LeftTupleSource leftInput) { - super.initDeclaredMask(context, leftInput); + protected void initDeclaredMask(BuildContext context) { + super.initDeclaredMask(context); - if ( leftDeclaredMask.isAllSet() ) { + if ( declaredMask.isAllSet() ) { return; } if ( context == null || context.getLastBuiltPatterns() == null ) { // only happens during unit tests - leftDeclaredMask = AllSetBitMask.get(); + declaredMask = AllSetBitMask.get(); return; } @@ -170,8 +169,8 @@ protected void initDeclaredMask(BuildContext context, if ( isPropertyReactive( context.getRuleBase(), objectType ) ) { Collection leftListenedProperties = pattern.getListenedProperties(); List accessibleProperties = getAccessibleProperties( context.getRuleBase(), objectType ); - leftDeclaredMask = leftDeclaredMask.setAll( calculatePositiveMask( objectType, leftListenedProperties, accessibleProperties ) ); - leftNegativeMask = leftNegativeMask.setAll( calculateNegativeMask( objectType, leftListenedProperties, accessibleProperties ) ); + declaredMask = declaredMask.setAll(calculatePositiveMask(objectType, leftListenedProperties, accessibleProperties)); + negativeMask = negativeMask.setAll(calculateNegativeMask(objectType, leftListenedProperties, accessibleProperties)); } } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/JoinNode.java b/drools-core/src/main/java/org/drools/core/reteoo/JoinNode.java index 7f464d7c93b..cd47ccc7494 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/JoinNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/JoinNode.java @@ -20,8 +20,6 @@ import org.drools.base.reteoo.NodeTypeEnums; import org.drools.core.common.BetaConstraints; -import org.drools.core.common.PropagationContext; -import org.drools.core.common.ReteEvaluator; import org.drools.core.reteoo.builder.BuildContext; public class JoinNode extends BetaNode { @@ -34,7 +32,7 @@ public JoinNode() { public JoinNode(final int id, final LeftTupleSource leftInput, - final ObjectSource rightInput, + final RightInputAdapterNode rightInput, final BetaConstraints binder, final BuildContext context) { super( id, @@ -54,26 +52,4 @@ public String toString() { return "[JoinNode(" + this.getId() + ") - " + getObjectTypeNode().getObjectType() + "]"; } - public void retractRightTuple( final TupleImpl rightTuple, - final PropagationContext pctx, - final ReteEvaluator reteEvaluator ) { - final BetaMemory memory = (BetaMemory) reteEvaluator.getNodeMemory(this); - rightTuple.setPropagationContext( pctx ); - doDeleteRightTuple( rightTuple, reteEvaluator, memory ); - } - - @Override - public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean doRemove(RuleRemovalContext context, ReteooBuilder builder) { - if ( !isInUse() ) { - getLeftTupleSource().removeTupleSink( this ); - getRightInput().removeObjectSink( this ); - return true; - } - return false; - } } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/JoinRightAdapterNode.java b/drools-core/src/main/java/org/drools/core/reteoo/JoinRightAdapterNode.java new file mode 100644 index 00000000000..983e9d67ffb --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/reteoo/JoinRightAdapterNode.java @@ -0,0 +1,32 @@ +package org.drools.core.reteoo; + +import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.reteoo.builder.BuildContext; + +public class JoinRightAdapterNode extends RightInputAdapterNode { + public JoinRightAdapterNode(int id, ObjectSource rightInput, BuildContext context) { + super(id, rightInput, context); + } + + @Override + public void retractRightTuple( final TupleImpl rightTuple, + final PropagationContext pctx, + final ReteEvaluator reteEvaluator) { + final BetaMemory memory = (BetaMemory) reteEvaluator.getNodeMemory(betaNode); + rightTuple.setPropagationContext( pctx ); + doDeleteRightTuple( rightTuple, reteEvaluator, memory ); + } + + @Override + public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + throw new UnsupportedOperationException(); + } + + @Override + public int getType() { + return NodeTypeEnums.JoinRightAdapterNode; + } + +} diff --git a/drools-core/src/main/java/org/drools/core/reteoo/LeftInputAdapterNode.java b/drools-core/src/main/java/org/drools/core/reteoo/LeftInputAdapterNode.java index 793d0ff3303..99295c32dc6 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/LeftInputAdapterNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/LeftInputAdapterNode.java @@ -31,6 +31,7 @@ import org.drools.base.reteoo.NodeTypeEnums; import org.drools.base.rule.Pattern; import org.drools.core.RuleBaseConfiguration; +import org.drools.core.common.BaseNode; import org.drools.core.common.DefaultFactHandle; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.Memory; @@ -54,7 +55,7 @@ import static org.drools.base.reteoo.PropertySpecificUtil.isPropertyReactive; import static org.drools.core.phreak.TupleEvaluationUtil.createLeftTupleTupleSets; import static org.drools.core.phreak.TupleEvaluationUtil.findPathToFlush; -import static org.drools.core.phreak.TupleEvaluationUtil.findPathsToFlushFromRia; +import static org.drools.core.phreak.TupleEvaluationUtil.findPathsToFlushFromSubnetwork; import static org.drools.core.phreak.TupleEvaluationUtil.flushLeftTupleIfNecessary; import static org.drools.core.phreak.TupleEvaluationUtil.forceFlushLeftTuple; import static org.drools.core.phreak.TupleEvaluationUtil.forceFlushPath; @@ -102,9 +103,9 @@ public LeftInputAdapterNode(final int id, this.setObjectCount(1); // 'lia' start at 1 this.objectSource = source; this.leftTupleMemoryEnabled = context.isTupleMemoryEnabled(); - ObjectSource current = source; + BaseNode current = source; while (current.getType() != NodeTypeEnums.ObjectTypeNode) { - current = current.getParentObjectSource(); + current = current.getParent(); } setStreamMode( context.isStreamMode() && context.getRootObjectTypeNode().getObjectType().isEvent() ); @@ -113,6 +114,10 @@ public LeftInputAdapterNode(final int id, hashcode = calculateHashCode(); } + public ObjectSource getParent() { + return objectSource; + } + private BitMask calculateSinkMask(BuildContext context) { Pattern pattern = context.getLastBuiltPatterns() != null ? context.getLastBuiltPatterns()[0] : null; if (pattern == null) { @@ -244,7 +249,7 @@ public static List doInsertSegmentMemory(ReteEvaluator reteEvaluator if ( linkOrNotify ) { lm.setNodeDirty( reteEvaluator ); } - return findPathsToFlushFromRia(reteEvaluator, pmem); + return findPathsToFlushFromSubnetwork(reteEvaluator, pmem); } // mask check is necessary if insert is a result of a modify @@ -389,13 +394,13 @@ public void modifyObject(InternalFactHandle factHandle, final ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, ReteEvaluator reteEvaluator) { - ObjectTypeNodeId otnId = this.sink.getFirstLeftTupleSink().getLeftInputOtnId(); + ObjectTypeNodeId otnId = this.sink.getFirstLeftTupleSink().getInputOtnId(); TupleImpl leftTuple = processDeletesFromModify(modifyPreviousTuples, context, reteEvaluator, otnId); LiaNodeMemory lm = reteEvaluator.getNodeMemory( this ); LeftTupleSink sink = getSinkPropagator().getFirstLeftTupleSink(); - BitMask mask = sink.getLeftInferredMask(); + BitMask mask = sink.getInferredMask(); if ( leftTuple != null && leftTuple.getInputOtnId().equals(otnId) ) { modifyPreviousTuples.removeLeftTuple(partitionId); @@ -617,7 +622,7 @@ public LeftTupleSinkAdapter() { public void assertObject(final InternalFactHandle factHandle, final PropagationContext context, final ReteEvaluator reteEvaluator) { - ObjectTypeNodeId otnId = liaNode.getSinkPropagator().getFirstLeftTupleSink().getLeftInputOtnId(); + ObjectTypeNodeId otnId = liaNode.getSinkPropagator().getFirstLeftTupleSink().getInputOtnId(); TupleImpl detached = factHandle.getLinkedTuples().detachLeftTupleAfter(getPartitionId(), otnId); if (detached != null) { detachedTuples.add(new DetachedTuple((DefaultFactHandle) factHandle, detached)); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSink.java b/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSink.java index bda78288904..6b2a7847ea3 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSink.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSink.java @@ -19,8 +19,6 @@ package org.drools.core.reteoo; import org.drools.base.common.RuleBasePartitionId; -import org.drools.core.common.InternalFactHandle; -import org.drools.core.common.PropagationContext; import org.drools.util.bitmask.BitMask; /** @@ -33,11 +31,13 @@ public interface LeftTupleSink extends LeftTupleNode, Sink { boolean isLeftTupleMemoryEnabled(); - ObjectTypeNodeId getLeftInputOtnId(); + ObjectTypeNodeId getInputOtnId(); - void setLeftInputOtnId(ObjectTypeNodeId leftInputOtnId); + void setInputOtnId(ObjectTypeNodeId leftInputOtnId); - BitMask getLeftInferredMask(); + BitMask getDeclaredMask(); + + BitMask getInferredMask(); void setPartitionIdWithSinks( RuleBasePartitionId partitionId ); } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSource.java b/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSource.java index 7391eb4117f..ec379058912 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSource.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSource.java @@ -50,16 +50,16 @@ */ public abstract class LeftTupleSource extends BaseNode implements LeftTupleNode { - protected BitMask leftDeclaredMask = EmptyBitMask.get(); - protected BitMask leftInferredMask = EmptyBitMask.get(); - protected BitMask leftNegativeMask = EmptyBitMask.get(); + protected BitMask declaredMask = EmptyBitMask.get(); + protected BitMask inferredMask = EmptyBitMask.get(); + protected BitMask negativeMask = EmptyBitMask.get(); /** The left input TupleSource. */ protected LeftTupleSource leftInput; - private ObjectTypeNodeId leftInputOtnId = ObjectTypeNodeId.DEFAULT_ID; + private ObjectTypeNodeId inputOtnId = ObjectTypeNodeId.DEFAULT_ID; /** The destination for Tuples. */ protected LeftTupleSinkPropagator sink; @@ -81,7 +81,7 @@ public LeftTupleSource() { * @param id */ protected LeftTupleSource(int id, BuildContext context) { - super(id, context != null ? context.getPartitionId() : RuleBasePartitionId.MAIN_PARTITION); + super(id, context.getPartitionId()); this.sink = EmptyLeftTupleSinkAdapter.getInstance(); initMemoryId( context ); } @@ -96,12 +96,12 @@ public int getPathIndex() { public abstract int getType(); - public ObjectTypeNodeId getLeftInputOtnId() { - return leftInputOtnId; + public ObjectTypeNodeId getInputOtnId() { + return inputOtnId; } - public void setLeftInputOtnId(ObjectTypeNodeId leftInputOtnId) { - this.leftInputOtnId = leftInputOtnId; + public void setInputOtnId(ObjectTypeNodeId inputOtnId) { + this.inputOtnId = inputOtnId; } @@ -113,6 +113,14 @@ public LeftTupleSource getLeftTupleSource() { return leftInput; } + public LeftTupleSource getLeftInput() { + return leftInput; + } + + public LeftTupleSinkPropagator getSink() { + return sink; + } + public final void setLeftTupleSource(LeftTupleSource leftInput) { this.leftInput = leftInput; pathIndex = leftInput.getPathIndex() + 1; @@ -126,6 +134,10 @@ public void setObjectCount(int count) { objectCount = count; } + public BaseNode getParent() { + return leftInput; + } + /** * Adds the TupleSink so that it may receive * Tuples propagated from this TupleSource. @@ -224,23 +236,21 @@ public boolean isInUse() { return this.sink.size() > 0; } - protected final void initMasks(BuildContext context, - LeftTupleSource leftInput) { - initDeclaredMask( context, leftInput ); - initInferredMask( leftInput ); + protected final void initMasks(BuildContext context) { + initDeclaredMask( context ); + initInferredMask( ); } - protected void initDeclaredMask(BuildContext context, - LeftTupleSource leftInput) { - if ( context == null || context.getLastBuiltPatterns() == null ) { + protected void initDeclaredMask(BuildContext context) { + if ( context == null || context.getLastBuiltPatterns() == null) { // only happens during unit tests - leftDeclaredMask = AllSetBitMask.get(); + declaredMask = AllSetBitMask.get(); return; } if ( !NodeTypeEnums.isLeftInputAdapterNode(leftInput)) { // BetaNode's not after LIANode are not relevant for left mask property specific, so don't block anything. - leftDeclaredMask = AllSetBitMask.get(); + declaredMask = AllSetBitMask.get(); return; } @@ -250,20 +260,20 @@ protected void initDeclaredMask(BuildContext context, if ( !(objectType instanceof ClassObjectType) ) { // Only ClassObjectType can use property specific - leftDeclaredMask = AllSetBitMask.get(); + declaredMask = AllSetBitMask.get(); return; } if ( pattern != null && isPropertyReactive(context.getRuleBase(), objectType) ) { Collection leftListenedProperties = pattern.getListenedProperties(); List accessibleProperties = getAccessibleProperties( context.getRuleBase(), objectType ); - leftDeclaredMask = calculatePositiveMask( objectType, leftListenedProperties, accessibleProperties ); - leftDeclaredMask = setNodeConstraintsPropertyReactiveMask(leftDeclaredMask, objectType, accessibleProperties); - leftNegativeMask = calculateNegativeMask( objectType, leftListenedProperties, accessibleProperties ); + declaredMask = calculatePositiveMask(objectType, leftListenedProperties, accessibleProperties); + declaredMask = setNodeConstraintsPropertyReactiveMask(declaredMask, objectType, accessibleProperties); + negativeMask = calculateNegativeMask(objectType, leftListenedProperties, accessibleProperties); setLeftListenedProperties(leftListenedProperties); } else { // if property specific is not on, then accept all modification propagations - leftDeclaredMask = AllSetBitMask.get(); + declaredMask = AllSetBitMask.get(); } } @@ -283,38 +293,38 @@ protected ObjectType getObjectTypeForPropertyReactivity( LeftInputAdapterNode le protected void setLeftListenedProperties(Collection leftListenedProperties) { } - protected void initInferredMask(LeftTupleSource leftInput) { - LeftTupleSource unwrappedLeft = unwrapLeftInput(leftInput); + protected void initInferredMask() { + LeftTupleSource unwrappedLeft = unwrapLeftInput(); if ( NodeTypeEnums.isLeftInputAdapterNode(unwrappedLeft) && ((LeftInputAdapterNode)unwrappedLeft).getParentObjectSource().getType() == NodeTypeEnums.AlphaNode ) { ObjectSource objectSource = ((LeftInputAdapterNode)unwrappedLeft).getParentObjectSource(); - leftInferredMask = objectSource.updateMask( leftDeclaredMask ); + inferredMask = objectSource.updateMask(declaredMask); } else { - leftInferredMask = leftDeclaredMask; + inferredMask = declaredMask; } - leftInferredMask = leftInferredMask.resetAll(leftNegativeMask); + inferredMask = inferredMask.resetAll(negativeMask); } - private LeftTupleSource unwrapLeftInput(LeftTupleSource leftInput) { + private LeftTupleSource unwrapLeftInput() { if (leftInput.getType() == NodeTypeEnums.FromNode || leftInput.getType() == NodeTypeEnums.ReactiveFromNode) { return leftInput.getLeftTupleSource(); } return leftInput; } - public BitMask getLeftDeclaredMask() { - return leftDeclaredMask; + public BitMask getDeclaredMask() { + return declaredMask; } - public BitMask getLeftInferredMask() { - return leftInferredMask; + public BitMask getInferredMask() { + return inferredMask; } - protected void setLeftInferredMask(BitMask leftInferredMask) { - this.leftInferredMask = leftInferredMask; + protected void setInferredMask(BitMask inferredMask) { + this.inferredMask = inferredMask; } - public BitMask getLeftNegativeMask() { - return leftNegativeMask; + public BitMask getNegativeMask() { + return negativeMask; } public ObjectType getObjectType() { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/NotNode.java b/drools-core/src/main/java/org/drools/core/reteoo/NotNode.java index 6d1d8d58120..7af29e2e2f9 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/NotNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/NotNode.java @@ -20,13 +20,8 @@ import org.drools.base.reteoo.NodeTypeEnums; import org.drools.core.common.BetaConstraints; -import org.drools.core.common.InternalFactHandle; -import org.drools.core.common.PropagationContext; -import org.drools.core.common.ReteEvaluator; -import org.drools.core.common.TupleSets; import org.drools.core.reteoo.builder.BuildContext; -import static org.drools.core.phreak.RuleNetworkEvaluator.doExistentialUpdatesReorderChildLeftTuple; import static org.drools.core.phreak.TupleEvaluationUtil.flushLeftTupleIfNecessary; public class NotNode extends BetaNode { @@ -43,7 +38,7 @@ public NotNode() { public NotNode(final int id, final LeftTupleSource leftInput, - final ObjectSource rightInput, + final RightInputAdapterNode rightInput, final BetaConstraints joinNodeBinder, final BuildContext context) { super(id, @@ -60,10 +55,6 @@ public NotNode(final int id, emptyBetaConstraints = joinNodeBinder.getConstraints().length == 0 || context.isEmptyForAllBetaConstraints(); } - @Override - protected void reorderRightTuple(ReteEvaluator reteEvaluator, TupleImpl rightTuple) { - doExistentialUpdatesReorderChildLeftTuple(reteEvaluator, this, (RightTuple) rightTuple); - } public boolean isEmptyBetaConstraints() { return emptyBetaConstraints; @@ -82,80 +73,6 @@ public String toString() { return "[NotNode(" + this.getId() + ") - " + ((source != null) ? source.getObjectType() : "") + "]"; } - public void assertObject( final InternalFactHandle factHandle, - final PropagationContext pctx, - final ReteEvaluator reteEvaluator ) { - final BetaMemory memory = (BetaMemory) getBetaMemoryFromRightInput(this, reteEvaluator); - - TupleImpl rightTuple = createRightTuple( factHandle, - this, - pctx); - - rightTuple.setPropagationContext(pctx); - - boolean stagedInsertWasEmpty = memory.getStagedRightTuples().addInsert( rightTuple ); - - if (memory.getAndIncCounter() == 0 && isEmptyBetaConstraints() ) { - // strangely we link here, this is actually just to force a network evaluation - // The assert is then processed and the rule unlinks then. - // This is because we need the first RightTuple to link with it's blocked - if ( stagedInsertWasEmpty ) { - memory.setNodeDirtyWithoutNotify(); - } - - // NotNodes can only be unlinked, if they have no variable constraints - memory.linkNode( this, reteEvaluator ); - } else if ( stagedInsertWasEmpty ) { - // nothing staged before, notify rule, so it can evaluate network - memory.setNodeDirty(this, reteEvaluator); - } - - flushLeftTupleIfNecessary( reteEvaluator, memory.getOrCreateSegmentMemory( this, reteEvaluator ), isStreamMode() ); - } - - public void retractRightTuple(final TupleImpl rightTuple, - final PropagationContext pctx, - final ReteEvaluator reteEvaluator) { - final BetaMemory memory = (BetaMemory) reteEvaluator.getNodeMemory(this); - rightTuple.setPropagationContext( pctx ); - doDeleteRightTuple( rightTuple, reteEvaluator, memory ); - } - - public void doDeleteRightTuple(final TupleImpl rightTuple, - final ReteEvaluator reteEvaluator, - final BetaMemory memory) { - TupleSets stagedRightTuples = memory.getStagedRightTuples(); - boolean stagedDeleteWasEmpty = stagedRightTuples.addDelete( rightTuple ); - - if ( memory.getAndDecCounter() == 1 && isEmptyBetaConstraints() ) { - if ( stagedDeleteWasEmpty ) { - memory.setNodeDirtyWithoutNotify(); - } - // NotNodes can only be unlinked, if they have no variable constraints - memory.linkNode( this, reteEvaluator ); - } else if ( stagedDeleteWasEmpty ) { - // nothing staged before, notify rule, so it can evaluate network - memory.setNodeDirty( this, reteEvaluator ); - } - - flushLeftTupleIfNecessary( reteEvaluator, memory.getOrCreateSegmentMemory( this, reteEvaluator ), isStreamMode() ); - } - - @Override - public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean doRemove(RuleRemovalContext context, ReteooBuilder builder) { - if ( !isInUse() ) { - getLeftTupleSource().removeTupleSink( this ); - getRightInput().removeObjectSink( this ); - return true; - } - return false; - } - public boolean isLeftUpdateOptimizationAllowed() { return getRawConstraints().isLeftUpdateOptimizationAllowed(); } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/NotRight.java b/drools-core/src/main/java/org/drools/core/reteoo/NotRight.java new file mode 100644 index 00000000000..f889997172b --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/reteoo/NotRight.java @@ -0,0 +1,96 @@ +package org.drools.core.reteoo; + +import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.common.TupleSets; +import org.drools.core.reteoo.builder.BuildContext; + +import static org.drools.core.phreak.RuleNetworkEvaluator.doExistentialUpdatesReorderChildLeftTuple; +import static org.drools.core.phreak.TupleEvaluationUtil.flushLeftTupleIfNecessary; + +public class NotRight extends RightInputAdapterNode { + + public NotRight(int id, ObjectSource rightInput, BuildContext context) { + super(id, rightInput, context); + } + + @Override + protected void reorderRightTuple(ReteEvaluator reteEvaluator, TupleImpl rightTuple) { + doExistentialUpdatesReorderChildLeftTuple(reteEvaluator, (NotNode) betaNode, (RightTuple) rightTuple); + } + + @Override + public void assertObject( final InternalFactHandle factHandle, + final PropagationContext pctx, + final ReteEvaluator reteEvaluator ) { + + final BetaMemory memory = getBetaMemoryFromRightInput(betaNode, reteEvaluator); + + TupleImpl rightTuple = createRightTuple( factHandle, + this, + pctx); + + rightTuple.setPropagationContext(pctx); + + boolean stagedInsertWasEmpty = memory.getStagedRightTuples().addInsert( rightTuple ); + + if (memory.getAndIncCounter() == 0 && ((NotNode)betaNode).isEmptyBetaConstraints() ) { + // strangely we link here, this is actually just to force a network evaluation + // The assert is then processed and the rule unlinks then. + // This is because we need the first RightTuple to link with it's blocked + if ( stagedInsertWasEmpty ) { + memory.setNodeDirtyWithoutNotify(); + } + + // NotNodes can only be unlinked, if they have no variable constraints + memory.linkNode( betaNode, reteEvaluator ); + } else if ( stagedInsertWasEmpty ) { + // nothing staged before, notify rule, so it can evaluate network + memory.setNodeDirty(betaNode, reteEvaluator); + } + + flushLeftTupleIfNecessary( reteEvaluator, memory.getOrCreateSegmentMemory( betaNode, reteEvaluator ), isStreamMode() ); + } + + @Override + public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + throw new UnsupportedOperationException(); + } + + @Override + public void retractRightTuple(final TupleImpl rightTuple, + final PropagationContext pctx, + final ReteEvaluator reteEvaluator) { + final BetaMemory memory = (BetaMemory) reteEvaluator.getNodeMemory(betaNode); + rightTuple.setPropagationContext( pctx ); + doDeleteRightTuple( rightTuple, reteEvaluator, memory ); + } + + @Override + public void doDeleteRightTuple(final TupleImpl rightTuple, + final ReteEvaluator reteEvaluator, + final BetaMemory memory) { + TupleSets stagedRightTuples = memory.getStagedRightTuples(); + boolean stagedDeleteWasEmpty = stagedRightTuples.addDelete( rightTuple ); + + if ( memory.getAndDecCounter() == 1 && ((NotNode)betaNode).isEmptyBetaConstraints() ) { + if ( stagedDeleteWasEmpty ) { + memory.setNodeDirtyWithoutNotify(); + } + // NotNodes can only be unlinked, if they have no variable constraints + memory.linkNode( betaNode, reteEvaluator ); + } else if ( stagedDeleteWasEmpty ) { + // nothing staged before, notify rule, so it can evaluate network + memory.setNodeDirty( betaNode, reteEvaluator ); + } + + flushLeftTupleIfNecessary( reteEvaluator, memory.getOrCreateSegmentMemory( betaNode, reteEvaluator ), isStreamMode() ); + } + + @Override + public int getType() { + return NodeTypeEnums.NotRightAdapterNode; + } +} diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ObjectSinkPropagator.java b/drools-core/src/main/java/org/drools/core/reteoo/ObjectSinkPropagator.java index 4b971610bcc..99d6e1d9e06 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ObjectSinkPropagator.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ObjectSinkPropagator.java @@ -56,8 +56,8 @@ void byPassModifyToBetaNode (final InternalFactHandle factHandle, final PropagationContext context, final ReteEvaluator reteEvaluator); - void doLinkRiaNode(ReteEvaluator reteEvaluator); + void doLinkSubnetwork(ReteEvaluator reteEvaluator); - void doUnlinkRiaNode(ReteEvaluator reteEvaluator); + void doUnlinkSubnetwork(ReteEvaluator reteEvaluator); } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ObjectSource.java b/drools-core/src/main/java/org/drools/core/reteoo/ObjectSource.java index faad3ecd97d..8f557b9dfee 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ObjectSource.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ObjectSource.java @@ -78,6 +78,10 @@ protected ObjectSource(int id, RuleBasePartitionId partitionId) { this( id, partitionId, null, 3, 3); } + protected ObjectSource(int id, final ObjectSource objectSource, RuleBasePartitionId partitionId) { + this( id, partitionId, objectSource, 3, 3); + } + /** * Single parameter constructor that specifies the unique id of the node. */ @@ -93,22 +97,14 @@ protected ObjectSource(int id, RuleBasePartitionId partitionId) { this.sink = EmptyObjectSinkAdapter.getInstance(); } - // ------------------------------------------------------------ - // Instance methods - // ------------------------------------------------------------ - - public ObjectSource getParentObjectSource() { - return this.source; - } - - public void setParentObjectSource(ObjectSource source) { - this.source = source; - } - public InternalRuleBase getRuleBase() { return source.getRuleBase(); } + public BaseNode getParent() { + return source; + } + public void initDeclaredMask(BuildContext context) { if ( context == null || context.getLastBuiltPatterns() == null ) { // only happens during unit tests @@ -237,6 +233,10 @@ public ObjectTypeNode getObjectTypeNode() { } public BitMask getDeclaredMask() { - return EmptyBitMask.get(); + return declaredMask; + } + + public BitMask getInferredMask() { + return inferredMask; } } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java b/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java index dcbac740338..39bb5b2e205 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java @@ -355,11 +355,11 @@ public void networkUpdated(UpdateContext updateContext) { protected static void updateTupleSinkId(ObjectTypeNode otn, ObjectSource source) { for (ObjectSink sink : source.sink.getSinks()) { - if (NodeTypeEnums.isBetaNode(sink)) { - ((BetaNode)sink).setRightInputOtnId(otn.nextOtnId()); + if (NodeTypeEnums.isBetaRightNode(sink)) { + ((RightInputAdapterNode)sink).setInputOtnId(otn.nextOtnId()); } else if (NodeTypeEnums.isLeftInputAdapterNode(sink)) { for (LeftTupleSink liaChildSink : ((LeftInputAdapterNode) sink).getSinkPropagator().getSinks()) { - liaChildSink.setLeftInputOtnId(otn.nextOtnId()); + liaChildSink.setInputOtnId(otn.nextOtnId()); } } else if (sink.getType() == NodeTypeEnums.WindowNode) { ((WindowNode)sink).setRightInputOtnId(otn.nextOtnId()); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/PathEndNode.java b/drools-core/src/main/java/org/drools/core/reteoo/PathEndNode.java index a94c10377d8..654f716effe 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/PathEndNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/PathEndNode.java @@ -101,12 +101,12 @@ default PathMemSpec calculatePathMemSpec(LeftTupleSource startTupleSource, Termi NodeTypeEnums.isBetaNode( tupleSource ) && NodeTypeEnums.AccumulateNode != tupleSource.getType()) { // accumulates can never be disabled BetaNode bn = ( BetaNode) tupleSource; - if ( bn.isRightInputIsRiaNode() ) { + if ( bn.getRightInput().inputIsTupleToObjectNode() ) { updateBitInNewSegment = false; - RightInputAdapterNode rian = (RightInputAdapterNode) bn.getRightInput(); + TupleToObjectNode tton = (TupleToObjectNode) bn.getRightInput().getParent(); // only ria's without reactive subnetworks can be disabled and thus need checking // The getNodeMemory will call this method recursive for sub networks it reaches - if ( rian.getPathMemSpec(removingTN).allLinkedTestMask != 0 ) { + if ( tton.getPathMemSpec(removingTN).allLinkedTestMask != 0 ) { allLinkedTestMask = allLinkedTestMask | 1; } } else if ( NodeTypeEnums.NotNode != bn.getType() || ((NotNode)bn).isEmptyBetaConstraints()) { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/PathMemory.java b/drools-core/src/main/java/org/drools/core/reteoo/PathMemory.java index 9551ab4c781..93c41fe9aea 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/PathMemory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/PathMemory.java @@ -102,7 +102,7 @@ public void linkSegment(long mask, ReteEvaluator reteEvaluator) { TerminalNode rtn = (TerminalNode) getPathEndNode(); log.trace(" LinkSegment smask={} rmask={} name={}", mask, linkedSegmentMask, rtn.getRule().getName()); } else { - log.trace(" LinkSegment smask={} rmask={}", mask, "RiaNode"); + log.trace(" LinkSegment smask={} rmask={}", mask, "TupleToObjectNode"); } } if (isRuleLinked()) { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/QueryElementNode.java b/drools-core/src/main/java/org/drools/core/reteoo/QueryElementNode.java index 400e7dd01e3..73039ef50be 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/QueryElementNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/QueryElementNode.java @@ -78,7 +78,7 @@ public QueryElementNode(final int id, this.tupleMemoryEnabled = tupleMemoryEnabled; this.openQuery = openQuery; this.dataDriven = context != null && context.getRule().isDataDriven(); - initMasks( context, tupleSource ); + initMasks( context ); this.argsTemplate = initArgsTemplate( context ); hashcode = calculateHashCode(); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/QueryTerminalNode.java b/drools-core/src/main/java/org/drools/core/reteoo/QueryTerminalNode.java index d239c23067d..e4016cf7195 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/QueryTerminalNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/QueryTerminalNode.java @@ -25,8 +25,6 @@ import org.drools.base.reteoo.NodeTypeEnums; import org.drools.base.rule.Declaration; import org.drools.base.rule.GroupElement; -import org.drools.core.common.InternalFactHandle; -import org.drools.core.common.PropagationContext; import org.drools.core.reteoo.builder.BuildContext; /** @@ -100,11 +98,11 @@ public int getType() { } - public ObjectTypeNodeId getLeftInputOtnId() { + public ObjectTypeNodeId getInputOtnId() { return leftInputOtnId; } - public void setLeftInputOtnId(ObjectTypeNodeId leftInputOtnId) { + public void setInputOtnId(ObjectTypeNodeId leftInputOtnId) { this.leftInputOtnId = leftInputOtnId; } @@ -116,6 +114,6 @@ public Declaration[] getSalienceDeclarations() { public void doAttach( BuildContext context ) { super.doAttach(context); getLeftTupleSource().addTupleSink( this, context ); - addAssociation( context, context.getRule() ); + addAssociation(context.getRule(), context); } } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ReteooBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/ReteooBuilder.java index 2d7ada53d35..471b86a9400 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ReteooBuilder.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ReteooBuilder.java @@ -25,6 +25,7 @@ import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.ArrayDeque; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -46,7 +47,6 @@ import org.drools.core.impl.InternalRuleBase; import org.drools.core.phreak.PhreakBuilder; import org.drools.core.reteoo.builder.ReteooRuleBuilder; -import org.drools.core.util.TupleRBTree.Node; import org.kie.api.definition.rule.Rule; /** @@ -203,7 +203,7 @@ private Collection removeNodes(AbstractTerminalNode terminalNode, Coll Map stillInUse = new HashMap<>(); Collection alphas = new HashSet<>(); - removePath(wms, context, stillInUse, alphas, terminalNode); + removePath(wms, context, stillInUse, alphas, terminalNode, terminalNode.getStartTupleSource()); Set removedNodes = new HashSet<>(); for (ObjectSource alpha : alphas) { @@ -218,7 +218,7 @@ private Collection removeNodes(AbstractTerminalNode terminalNode, Coll * Each time it reaches a subnetwork beta node, the current path evaluation ends, and instead the subnetwork * path continues. */ - private void removePath( Collection wms, RuleRemovalContext context, Map stillInUse, Collection alphas, PathEndNode endNode ) { + private void removePath( Collection wms, RuleRemovalContext context, Map stillInUse, Collection alphas, PathEndNode endNode, NetworkNode startNode) { LeftTupleNode[] nodes = endNode.getPathNodes(); for (int i = endNode.getPathIndex(); i >= 0; i--) { BaseNode node = (BaseNode) nodes[i]; @@ -230,17 +230,25 @@ private void removePath( Collection wms, RuleRemovalConte if ( removed ) { // reteoo requires to call remove on the OTN for tuples cleanup - if (NodeTypeEnums.isBetaNode(node) && !((BetaNode) node).isRightInputIsRiaNode()) { - alphas.add(((BetaNode) node).getRightInput()); + if (NodeTypeEnums.isBetaNodeWithoutSubnetwork(node)) { + alphas.add(((BetaNode) node).getRightInput().getParent()); } else if (NodeTypeEnums.isLeftInputAdapterNode(node)) { alphas.add(((LeftInputAdapterNode) node).getObjectSource()); } - } - if (NodeTypeEnums.isBetaNode(node) && ((BetaNode) node).isRightInputIsRiaNode()) { - endNode = (PathEndNode) ((BetaNode) node).getRightInput(); - removePath(wms, context, stillInUse, alphas, endNode); - return; + if (NodeTypeEnums.isBetaNodeWithoutSubnetwork(node)) { + // this must be removed after alpha nodes are collected + removeLeftTupleNode(wms, context, stillInUse, ((BetaNode) node).getRightInput()); + } else if (NodeTypeEnums.isBetaNodeWithSubnetwork(node)) { + endNode = (PathEndNode) ((BetaNode) node).getRightInput().getParent(); + // this must be removed after we have a reference to the TupleToObjectNode endnode + removeLeftTupleNode(wms, context, stillInUse, ((BetaNode) node).getRightInput()); + removePath(wms, context, stillInUse, alphas, endNode, endNode.getStartTupleSource()); + } + + if (node == startNode) { // don't go past the network start node + return; + } } } } @@ -251,8 +259,10 @@ private boolean removeLeftTupleNode(Collection wms, RuleR if (removed) { stillInUse.remove( node.getId() ); - for (InternalWorkingMemory workingMemory : wms) { - workingMemory.clearNodeMemory((MemoryFactory) node); + if (NodeTypeEnums.isMemoryFactory(node)) { + for (InternalWorkingMemory workingMemory : wms) { + workingMemory.clearNodeMemory((MemoryFactory) node); + } } } else { stillInUse.put( node.getId(), node ); @@ -261,11 +271,11 @@ private boolean removeLeftTupleNode(Collection wms, RuleR return removed; } - private void removeObjectSource(Collection wms, Map stillInUse, Set removedNodes, ObjectSource node, RuleRemovalContext context ) { + private void removeObjectSource(Collection wms, Map stillInUse, Set removedNodes, BaseNode node, RuleRemovalContext context ) { if (removedNodes.contains( node.getId() )) { return; } - ObjectSource parent = node.getParentObjectSource(); + BaseNode parent = node.getParent(); boolean removed = node.remove( context, this ); @@ -275,9 +285,8 @@ private void removeObjectSource(Collection wms, Map remove removeNodeAssociation( ((LeftTupleNode)node).getLeftTupleSource(), rule, removedNodes, context ); } if ( NodeTypeEnums.isBetaNode( node ) ) { - removeNodeAssociation( ((BetaNode) node).getRightInput(), rule, removedNodes, context ); + removeNodeAssociation( ((BetaNode) node).getRightInput().getParent(), rule, removedNodes, context ); } else if ( NodeTypeEnums.isLeftInputAdapterNode(node)) { - removeNodeAssociation( ((LeftInputAdapterNode) node).getObjectSource(), rule, removedNodes, context ); + removeNodeAssociation( node.getParent(), rule, removedNodes, context ); } else if ( node.getType() == NodeTypeEnums.AlphaNode ) { - removeNodeAssociation( ((AlphaNode) node).getParentObjectSource(), rule, removedNodes, context ); + removeNodeAssociation( node.getParent(), rule, removedNodes, context ); } } @@ -313,11 +322,11 @@ private void resetMasks(Collection nodes) { ObjectSource source = (AlphaNode) node; while ( true ) { source.resetInferredMask(); - ObjectSource parent = source.getParentObjectSource(); + BaseNode parent = source.getParent(); if (parent.getType() != NodeTypeEnums.AlphaNode) { break; } - source = parent; + source = (ObjectSource) parent; } updateLeafSet(source, leafSet ); } else if( NodeTypeEnums.isBetaNode( node ) ) { @@ -336,6 +345,8 @@ private void resetMasks(Collection nodes) { for ( BaseNode node : leafSet ) { if ( NodeTypeEnums.isTerminalNode( node ) ) { ((TerminalNode)node).initInferredMask(); + } else if (NodeTypeEnums.isBetaRightNode(node)){ + ((RightInputAdapterNode)node).initInferredMask(); } else { // else node instanceof BetaNode ((BetaNode)node).initInferredMask(); } @@ -357,6 +368,8 @@ private void updateLeafSet(BaseNode baseNode, NodeSet leafSet) { updateLeafSet( ( BaseNode ) sink, leafSet ); } } + } else if ( NodeTypeEnums.isBetaRightNode( baseNode ) && ( baseNode.isInUse() )) { + leafSet.add( baseNode ); } else if ( baseNode.getType() == NodeTypeEnums.EvalConditionNode ) { for ( LeftTupleSink sink : ((EvalConditionNode) baseNode).getSinkPropagator().getSinks() ) { if ( ((BaseNode)sink).isInUse() ) { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/RightInputAdapterNode.java b/drools-core/src/main/java/org/drools/core/reteoo/RightInputAdapterNode.java index 60e1320f88e..914870add92 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/RightInputAdapterNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/RightInputAdapterNode.java @@ -1,438 +1,413 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ package org.drools.core.reteoo; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - import org.drools.base.base.ObjectType; -import org.drools.base.common.NetworkNode; -import org.drools.base.definitions.rule.impl.RuleImpl; +import org.drools.base.common.RuleBasePartitionId; import org.drools.base.reteoo.NodeTypeEnums; import org.drools.base.rule.Pattern; -import org.drools.core.RuleBaseConfiguration; -import org.drools.core.common.ActivationsManager; +import org.drools.core.common.BaseNode; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.InternalWorkingMemory; -import org.drools.core.common.Memory; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; +import org.drools.core.common.TupleSets; import org.drools.core.common.UpdateContext; -import org.drools.core.reteoo.SegmentMemory.SegmentPrototype; +import org.drools.core.reteoo.AccumulateNode.AccumulateMemory; import org.drools.core.reteoo.builder.BuildContext; +import org.drools.util.bitmask.AllSetBitMask; import org.drools.util.bitmask.BitMask; -import org.kie.api.definition.rule.Rule; +import org.drools.util.bitmask.EmptyBitMask; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -/** - * When joining a subnetwork into the main network again, RightInputAdapterNode adapts the - * subnetwork's tuple into a fact in order right join it with the tuple being propagated in - * the main network. - */ -public class RightInputAdapterNode extends ObjectSource - implements - LeftTupleSinkNode, - PathEndNode { +import java.util.Collection; +import java.util.List; +import java.util.Objects; - private static final long serialVersionUID = 510l; +import static org.drools.base.reteoo.PropertySpecificUtil.isPropertyReactive; +import static org.drools.core.phreak.RuleNetworkEvaluator.doUpdatesReorderChildLeftTuple; +import static org.drools.core.phreak.TupleEvaluationUtil.flushLeftTupleIfNecessary; - private LeftTupleSource tupleSource; +public abstract class RightInputAdapterNode extends BaseNode + implements ObjectSinkNode, + RightTupleSink { - /** - * This is first node inside of the subnetwork. The split, with two outs, would be the parent node. - */ - private LeftTupleSource startTupleSource; + protected static final Logger log = LoggerFactory.getLogger(RightInputAdapterNode.class); + protected static final boolean isLogTraceEnabled = log.isTraceEnabled(); - private boolean tupleMemoryEnabled; + protected T betaNode; - private LeftTupleSinkNode previousTupleSinkNode; - private LeftTupleSinkNode nextTupleSinkNode; + private ObjectSinkNode previousObjectSinkNode; + protected BitMask declaredMask = EmptyBitMask.get(); + protected BitMask inferredMask = EmptyBitMask.get(); + private ObjectSinkNode nextObjectSinkNode; + private BitMask negativeMask = EmptyBitMask.get(); + private ObjectTypeNodeId inputOtnId = ObjectTypeNodeId.DEFAULT_ID; - private LeftTupleNode[] pathNodes; + private ObjectSource source; - private PathEndNode[] pathEndNodes; + private Collection listenedProperties; - private PathMemSpec pathMemSpec; + protected boolean inputIsTupleToObjectNode; - private SegmentPrototype[] segmentPrototypes; + private boolean inputIsPassive; - private SegmentPrototype[] eagerSegmentPrototypes; + private transient ObjectTypeNode objectTypeNode; - private int objectCount; + public RightInputAdapterNode(int id, ObjectSource input, BuildContext context) { + super(id, context.getPartitionId()); + inputIsTupleToObjectNode = NodeTypeEnums.TupleToObjectNode == input.getType(); - public RightInputAdapterNode() { - } + source = input; - /** - * Constructor specifying the unique id of the node in the Rete network, the position of the propagating FactHandleImpl in - * ReteTuple and the source that propagates the receive ReteTuples. - * - * @param id - * Unique id - * @param source - * The TupleSource which propagates the received ReteTuple - */ - public RightInputAdapterNode(final int id, - final LeftTupleSource source, - final LeftTupleSource startTupleSource, - final BuildContext context) { - super( id, context.getPartitionId() ); - this.tupleSource = source; - this.tupleMemoryEnabled = context.isTupleMemoryEnabled(); - this.startTupleSource = startTupleSource; + this.hashcode = calculateHashCode(); - hashcode = calculateHashCode(); - initMemoryId( context ); + if (context.isStreamMode() ) { + ObjectTypeNode otn = getObjectTypeNode(); + if (otn != null) { + setStreamMode(otn.getObjectType().isEvent() ); + } + } + } + public ObjectSource getParent() { + return source; } - @Override - public PathMemSpec getPathMemSpec() { - return getPathMemSpec(null); + public T getBetaNode() { + return betaNode; } + public void setBetaNode(T betaNode) { + this.betaNode = betaNode; + } - /** - * used during network build time, potentially during rule removal time. - * @param removingTN - * @return - */ @Override - public PathMemSpec getPathMemSpec(TerminalNode removingTN) { - if (pathMemSpec == null) { - pathMemSpec = calculatePathMemSpec( startTupleSource, removingTN ); + public void assertObject( InternalFactHandle factHandle, PropagationContext pctx, ReteEvaluator reteEvaluator ) { + final BetaMemory memory = getBetaMemoryFromRightInput(betaNode, reteEvaluator); + + RightTuple rightTuple = createRightTuple(factHandle, this, pctx); + + boolean stagedInsertWasEmpty = memory.getStagedRightTuples().addInsert(rightTuple); + if ( isLogTraceEnabled ) { + log.trace("BetaNode stagedInsertWasEmpty={}", stagedInsertWasEmpty ); } - return pathMemSpec; - } + boolean shouldFlush = isStreamMode(); + if ( memory.getAndIncCounter() == 0 ) { + if ( stagedInsertWasEmpty ) { + memory.setNodeDirtyWithoutNotify(); + } + shouldFlush = memory.linkNode( betaNode, reteEvaluator, !inputIsPassive) | shouldFlush; + } else if ( stagedInsertWasEmpty ) { + shouldFlush = memory.setNodeDirty( betaNode, reteEvaluator, !inputIsPassive) | shouldFlush; + } - @Override - public void nullPathMemSpec() { - pathMemSpec = null; + if (shouldFlush) { + flushLeftTupleIfNecessary( reteEvaluator, memory.getOrCreateSegmentMemory( betaNode, reteEvaluator ), isStreamMode() ); + } } - @Override - public void setPathMemSpec(PathMemSpec pathMemSpec) { - this.pathMemSpec = pathMemSpec; - } + public void modifyObject(InternalFactHandle factHandle, ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, ReteEvaluator reteEvaluator) { + TupleImpl rightTuple = modifyPreviousTuples.peekRightTuple(partitionId); - @Override - public void resetPathMemSpec(TerminalNode removingTN) { - nullPathMemSpec(); - pathMemSpec = getPathMemSpec(removingTN); - } + // if the peek is for a different OTN we assume that it is after the current one and then this is an assert + while ( rightTuple != null && rightTuple.getInputOtnId().before(getInputOtnId()) ) { + modifyPreviousTuples.removeRightTuple(partitionId); - @Override - public void setSegmentPrototypes(SegmentPrototype[] smems) { - this.segmentPrototypes = smems; - } + // we skipped this node, due to alpha hashing, so retract now + rightTuple.setPropagationContext( context ); + BetaMemory bm = BetaNode.getBetaMemory(((RightInputAdapterNode)rightTuple.getSink()).getBetaNode(), reteEvaluator); + ((RightInputAdapterNode) rightTuple.getSink()).doDeleteRightTuple(rightTuple, reteEvaluator, bm); + rightTuple = modifyPreviousTuples.peekRightTuple(partitionId); + } - @Override - public SegmentPrototype[] getSegmentPrototypes() { - return segmentPrototypes; + if ( rightTuple != null && rightTuple.getInputOtnId().equals(getInputOtnId()) ) { + modifyPreviousTuples.removeRightTuple(partitionId); + rightTuple.reAdd(); + if ( context.getModificationMask().intersects(inferredMask) ) { + // RightTuple previously existed, so continue as modify + rightTuple.setPropagationContext( context ); // only update, if the mask intersects + + BetaMemory bm = BetaNode.getBetaMemory(betaNode, reteEvaluator); + rightTuple.setPropagationContext( context ); + doUpdateRightTuple(rightTuple, reteEvaluator, bm); + } else if (rightTuple.getMemory() != null) { + reorderRightTuple(reteEvaluator, rightTuple); + } + } else { + if ( context.getModificationMask().intersects(inferredMask) ) { + // RightTuple does not exist for this node, so create and continue as assert + assertObject( factHandle, context, reteEvaluator ); + } + } } - @Override - public SegmentPrototype[] getEagerSegmentPrototypes() { - return eagerSegmentPrototypes; + protected void reorderRightTuple(ReteEvaluator reteEvaluator, TupleImpl rightTuple) { + BetaNode.getBetaMemory(betaNode, reteEvaluator).getRightTupleMemory().removeAdd(rightTuple); + doUpdatesReorderChildLeftTuple(rightTuple); } - @Override - public void setEagerSegmentPrototypes(SegmentPrototype[] eagerSegmentPrototypes) { - this.eagerSegmentPrototypes = eagerSegmentPrototypes; - } + public void doDeleteRightTuple(final TupleImpl rightTuple, + final ReteEvaluator reteEvaluator, + final BetaMemory memory) { + TupleSets stagedRightTuples = memory.getStagedRightTuples(); - @Override - public void setPathEndNodes(PathEndNode[] pathEndNodes) { - this.pathEndNodes = pathEndNodes; - } + boolean stagedDeleteWasEmpty = stagedRightTuples.addDelete(rightTuple); - @Override - public PathEndNode[] getPathEndNodes() { - return pathEndNodes; + boolean shouldFlush = isStreamMode(); + if ( memory.getAndDecCounter() == 1 ) { + if ( stagedDeleteWasEmpty ) { + memory.setNodeDirtyWithoutNotify(); + } + shouldFlush = memory.unlinkNode(reteEvaluator) | shouldFlush; + } else if ( stagedDeleteWasEmpty ) { + // nothing staged before, notify rule, so it can evaluate network + shouldFlush = memory.setNodeDirty( betaNode, reteEvaluator ) | shouldFlush; + } + + if (shouldFlush) { + flushLeftTupleIfNecessary( reteEvaluator, memory.getOrCreateSegmentMemory( betaNode, reteEvaluator ), isStreamMode() ); + } } - public LeftTupleSource getStartTupleSource() { - return startTupleSource; + public void doUpdateRightTuple(final TupleImpl rightTuple, + final ReteEvaluator reteEvaluator, + final BetaMemory memory) { + TupleSets stagedRightTuples = memory.getStagedRightTuples(); + + boolean stagedUpdateWasEmpty = stagedRightTuples.addUpdate( rightTuple ); + + boolean shouldFlush = isStreamMode(); + if ( stagedUpdateWasEmpty ) { + shouldFlush = memory.setNodeDirty( betaNode, reteEvaluator ) | shouldFlush; + } + + if (shouldFlush) { + flushLeftTupleIfNecessary( reteEvaluator, memory.getOrCreateSegmentMemory( betaNode, reteEvaluator ), isStreamMode() ); + } } - public int getPathIndex() { - return tupleSource.getPathIndex() + 1; + public static BetaMemory getBetaMemoryFromRightInput(BetaNode betaNode, ReteEvaluator reteEvaluator) { + return NodeTypeEnums.AccumulateNode == betaNode.getType() ? + ((AccumulateMemory)reteEvaluator.getNodeMemory(betaNode)).getBetaMemory() : + (BetaMemory) reteEvaluator.getNodeMemory( betaNode ); } - public int getObjectCount() { - return objectCount; + + public RightTuple createRightTuple(InternalFactHandle handle, + RightTupleSink sink, + PropagationContext context) { + RightTuple rightTuple = new RightTuple(handle, sink ); + rightTuple.setPropagationContext( context ); + return rightTuple; } - public void setObjectCount(int count) { - objectCount = count; + public void initDeclaredMask(BuildContext context) { + if (context == null || context.getLastBuiltPatterns() == null) { + // only happens during unit tests + declaredMask = AllSetBitMask.get(); + return; + } + + Pattern pattern = context.getLastBuiltPatterns()[0]; // right input pattern + inputIsPassive = pattern.isPassive(); + + if (!inputIsTupleToObjectNode()) { + ObjectType objectType = pattern.getObjectType(); + + if (isPropertyReactive(context.getRuleBase(), objectType)) { + listenedProperties = pattern.getListenedProperties(); + List accessibleProperties = pattern.getAccessibleProperties( context.getRuleBase() ); + declaredMask = pattern.getPositiveWatchMask(accessibleProperties); + declaredMask = declaredMask.setAll(betaNode.getRawConstraints().getListenedPropertyMask(pattern, objectType, accessibleProperties)); + negativeMask = pattern.getNegativeWatchMask(accessibleProperties); + } else { + // if property reactive is not on, then accept all modification propagations + declaredMask = AllSetBitMask.get(); + } + } else { + declaredMask = AllSetBitMask.get(); + // There would have been no right input pattern, so swap current to first, so leftInput can still work + context.setLastBuiltPattern( context.getLastBuiltPatterns()[0] ); + } } - /** - * Creates and return the node memory - */ - public RiaPathMemory createMemory(final RuleBaseConfiguration config, ReteEvaluator reteEvaluator) { - return (RiaPathMemory) AbstractTerminalNode.initPathMemory( this, new RiaPathMemory(this, reteEvaluator) ); + protected void initInferredMask() { + BaseNode unwrappedRight = getParent(); + if ( unwrappedRight.getType() == NodeTypeEnums.AlphaNode ) { + AlphaNode alphaNode = (AlphaNode) unwrappedRight; + inferredMask = alphaNode.updateMask(declaredMask); + } else { + inferredMask = declaredMask; + } + inferredMask = inferredMask.resetAll(negativeMask); } - public void doAttach( BuildContext context ) { - this.tupleSource.addTupleSink( this, context ); + @Override + public boolean inputIsTupleToObjectNode() { + return inputIsTupleToObjectNode; } - public void networkUpdated(UpdateContext updateContext) { - this.tupleSource.networkUpdated(updateContext); + @Override + public void byPassModifyToBetaNode (final InternalFactHandle factHandle, + final ModifyPreviousTuples modifyPreviousTuples, + final PropagationContext context, + final ReteEvaluator reteEvaluator) { + modifyObject( factHandle, modifyPreviousTuples, context, reteEvaluator ); } - protected boolean doRemove(final RuleRemovalContext context, - final ReteooBuilder builder) { - if ( !isInUse() ) { - tupleSource.removeTupleSink(this); - return true; - } - return false; + public BitMask calculateDeclaredMask(ObjectType modifiedType, List settableProperties) { + return null; } - public boolean isLeftTupleMemoryEnabled() { - return tupleMemoryEnabled; + + public void updateSink(ObjectSink sink, PropagationContext context, InternalWorkingMemory workingMemory) { + source.updateSink(this, context, workingMemory ); } + @Override + public abstract void retractRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator); + + + @Override + public abstract void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator); + /** * Returns the next node * @return - * The next TupleSinkNode + * The next ObjectSinkNode */ - public LeftTupleSinkNode getNextLeftTupleSinkNode() { - return this.nextTupleSinkNode; + public ObjectSinkNode getNextObjectSinkNode() { + return this.nextObjectSinkNode; } /** * Sets the next node * @param next - * The next TupleSinkNode + * The next ObjectSinkNode */ - public void setNextLeftTupleSinkNode(final LeftTupleSinkNode next) { - this.nextTupleSinkNode = next; + public void setNextObjectSinkNode(final ObjectSinkNode next) { + this.nextObjectSinkNode = next; } /** * Returns the previous node * @return - * The previous TupleSinkNode + * The previous ObjectSinkNode */ - public LeftTupleSinkNode getPreviousLeftTupleSinkNode() { - return this.previousTupleSinkNode; + public ObjectSinkNode getPreviousObjectSinkNode() { + return this.previousObjectSinkNode; } /** * Sets the previous node * @param previous - * The previous TupleSinkNode + * The previous ObjectSinkNode */ - public void setPreviousLeftTupleSinkNode(final LeftTupleSinkNode previous) { - this.previousTupleSinkNode = previous; - } - - public int getType() { - return NodeTypeEnums.RightInputAdapterNode; - } - - private int calculateHashCode() { - return this.tupleSource.hashCode() * 17 + ((this.tupleMemoryEnabled) ? 1234 : 4321); + public void setPreviousObjectSinkNode(final ObjectSinkNode previous) { + this.previousObjectSinkNode = previous; } - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - - return ((NetworkNode)object).getType() == NodeTypeEnums.RightInputAdapterNode && this.hashCode() == object.hashCode() && - this.tupleSource.getId() == ((RightInputAdapterNode)object).tupleSource.getId() && - this.tupleMemoryEnabled == ( (RightInputAdapterNode) object ).tupleMemoryEnabled; + void disablePropertyReactivity() { + inferredMask = AllSetBitMask.get(); } - @Override - public String toString() { - return "RightInputAdapterNode(" + id + ")[ tupleMemoryEnabled=" + tupleMemoryEnabled + ", tupleSource=" + tupleSource + ", source=" - + source + ", associations=" + associations + ", partitionId=" + partitionId + "]"; + public BitMask getNegativeMask() { + return negativeMask; } - public LeftTupleSource getLeftTupleSource() { - return this.tupleSource; + public ObjectTypeNodeId getInputOtnId() { + return inputOtnId; } - public void setTupleSource( LeftTupleSource tupleSource ) { - this.tupleSource = tupleSource; + public void setInputOtnId(ObjectTypeNodeId inputOtnId) { + this.inputOtnId = inputOtnId; } - public ObjectTypeNodeId getLeftInputOtnId() { - throw new UnsupportedOperationException(); + public boolean isRightInputPassive() { + return inputIsPassive; } - public void setLeftInputOtnId(ObjectTypeNodeId leftInputOtnId) { - throw new UnsupportedOperationException(); - } - @Override - public BitMask calculateDeclaredMask(Pattern pattern, ObjectType modifiedType, List settableProperties) { - throw new UnsupportedOperationException(); - } - - public static class RiaPathMemory extends PathMemory implements Memory { - private List rules; - - public RiaPathMemory(PathEndNode pathEndNode, ReteEvaluator reteEvaluator) { - super(pathEndNode, reteEvaluator); - } - - @Override - protected boolean initDataDriven( ReteEvaluator reteEvaluator ) { - for (PathEndNode pnode : getPathEndNode().getPathEndNodes()) { - if (NodeTypeEnums.isTerminalNode(pnode)) { - RuleImpl rule = ( (TerminalNode) pnode ).getRule(); - if ( isRuleDataDriven( reteEvaluator, rule ) ) { - return true; - } + public ObjectTypeNode getObjectTypeNode() { + if (objectTypeNode == null) { + ObjectSource source = this.source; + while ( source != null ) { + if ( NodeTypeEnums.ObjectTypeNode == source.getType()) { + objectTypeNode = (ObjectTypeNode) source; + break; } + source = source.source; } - return false; - } - - public RightInputAdapterNode getRightInputAdapterNode() { - return (RightInputAdapterNode) getPathEndNode(); - } - - @Override - public void doLinkRule(ReteEvaluator reteEvaluator) { - getRightInputAdapterNode().getObjectSinkPropagator().doLinkRiaNode( reteEvaluator ); - } - - @Override - public void doLinkRule(ActivationsManager activationsManager) { - doLinkRule(activationsManager.getReteEvaluator()); - } - - @Override - public void doUnlinkRule(ReteEvaluator reteEvaluator) { - getRightInputAdapterNode().getObjectSinkPropagator().doUnlinkRiaNode( reteEvaluator ); } + return objectTypeNode; + } - private void updateRuleTerminalNodes() { - rules = new ArrayList<>(); - for ( ObjectSink osink : getRightInputAdapterNode().getObjectSinkPropagator().getSinks() ) { - for ( LeftTupleSink ltsink : ((BetaNode)osink).getSinkPropagator().getSinks() ) { - findAndAddTN(ltsink, rules ); - } - } - } + @Override + public void doAttach(BuildContext context) { + super.doAttach(context); + this.source.addObjectSink(this); + } - private void findAndAddTN( LeftTupleSink ltsink, List terminalNodes) { - if ( NodeTypeEnums.isTerminalNode(ltsink)) { - terminalNodes.add( ((TerminalNode)ltsink).getRule() ); - } else if ( ltsink.getType() == NodeTypeEnums.RightInputAdapterNode) { - for ( NetworkNode childSink : ( ltsink).getSinks() ) { - findAndAddTN((LeftTupleSink)childSink, terminalNodes); - } - } else { - for ( LeftTupleSink childLtSink : (ltsink).getSinkPropagator().getSinks() ) { - findAndAddTN(childLtSink, terminalNodes); - } - } + @Override + public boolean doRemove(RuleRemovalContext context, ReteooBuilder builder) { + if ( !isInUse() ) { + source.removeObjectSink(this); + return true; } + return false; + } - public List getAssociatedRules() { - if ( rules == null ) { - updateRuleTerminalNodes(); - } - return rules; - } + @Override + public boolean isInUse() { + return betaNode.isInUse(); + } - public String getRuleNames() { - Set ruleNames = new HashSet<>(); - for (RuleImpl rule : getAssociatedRules()) { - ruleNames.add(rule.getName()); - } - return ruleNames.toString(); + protected int calculateHashCode() { + int hash = 29 * source.hashCode(); + if (listenedProperties != null) { + hash += 41 * listenedProperties.hashCode(); } + return hash + (inputIsPassive ? 43 : 0); + } - @Override - public int getNodeType() { - return NodeTypeEnums.RightInputAdapterNode; + @Override + public boolean equals(Object object) { + if (this == object) { + return true; } - public String toString() { - return "RiaMem(" + getRightInputAdapterNode().getId() + ") [" +getRuleNames() + "]"; + if ( //!NodeTypeEnums.isBetaNode((NetworkNode)object) || + this.hashCode() != object.hashCode()) { + return false; } - } - public BitMask getLeftInferredMask() { - throw new UnsupportedOperationException(); + RightInputAdapterNode other = (RightInputAdapterNode) object; + return this.getClass() == other.getClass() && + this.inputIsPassive == other.inputIsPassive && + Objects.equals(this.listenedProperties, other.listenedProperties) && + this.source.getId() == other.source.getId(); } @Override - public void updateSink(ObjectSink sink, PropagationContext context, InternalWorkingMemory wm) { - throw new UnsupportedOperationException(); - } - - public LeftTupleNode[] getPathNodes() { - if (pathNodes == null) { - pathNodes = AbstractTerminalNode.getPathNodes( this ); - } - return pathNodes; + public String toString() { + return "RightInputAdapterNode(" + id + ")[ source=" + + source + ", associations=" + associations + ", partitionId=" + partitionId + "]"; } - public boolean hasPathNode(LeftTupleNode node) { - for (LeftTupleNode pathNode : getPathNodes()) { - if (node.getId() == pathNode.getId()) { - return true; - } - } - return false; + public void networkUpdated(UpdateContext updateContext) { + this.source.networkUpdated(updateContext); } - public LeftTupleSinkPropagator getSinkPropagator() { - return EmptyLeftTupleSinkAdapter.getInstance(); + public final void setPartitionIdWithSinks( RuleBasePartitionId partitionId) { + this.partitionId = partitionId; } - @Override - public void addAssociation( BuildContext context, Rule rule ) { - super.addAssociation(context, rule); - context.addPathEndNode( this ); + public BitMask getDeclaredMask() { + return declaredMask; } - @Override - public boolean removeAssociation( Rule rule, RuleRemovalContext context ) { - boolean result = super.associations.remove(rule); - if (getAssociationsSize() == 0) { - // avoid to recalculate the pathEndNodes if this node is going to be removed - return result; - } - - List remainingPathNodes = new ArrayList<>(); - for (PathEndNode pathEndNode : pathEndNodes) { - if (pathEndNode.getAssociatedTerminalsSize() > 0) { - remainingPathNodes.add(pathEndNode); - } - } - pathEndNodes = remainingPathNodes.toArray( new PathEndNode[remainingPathNodes.size()] ); - return result; + public BitMask getInferredMask() { + return inferredMask; } - } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/RightTuple.java b/drools-core/src/main/java/org/drools/core/reteoo/RightTuple.java index 7339010899a..4f43608398c 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/RightTuple.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/RightTuple.java @@ -189,7 +189,7 @@ public void setExpired( ReteEvaluator reteEvaluator, PropagationContext pctx ) { super.setExpired(); // events expired at firing time should have a chance to produce a join (DROOLS-1329) // but shouldn't participate to an accumulate (DROOLS-4393) - if (this.getSink().getType() == NodeTypeEnums.AccumulateNode) { + if (this.getSink().getType() == NodeTypeEnums.AccumulateRightAdapterNode) { retractTuple( pctx, reteEvaluator ); } } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/RightTupleSink.java b/drools-core/src/main/java/org/drools/core/reteoo/RightTupleSink.java index be79eb3fd5f..6f4ad29f117 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/RightTupleSink.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/RightTupleSink.java @@ -31,7 +31,7 @@ void modifyRightTuple(final TupleImpl rightTuple, final PropagationContext context, final ReteEvaluator reteEvaluator); - default ObjectTypeNodeId getRightInputOtnId() { + default ObjectTypeNodeId getInputOtnId() { return null; } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNode.java b/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNode.java index 097cd7aa947..52ddbcbee1a 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNode.java @@ -98,7 +98,7 @@ public String toString() { public void doAttach( BuildContext context ) { super.doAttach(context); getLeftTupleSource().addTupleSink(this, context); - addAssociation( context, context.getRule() ); + addAssociation(context.getRule(), context); } void initDeclarations(Map decls, final BuildContext context) { @@ -160,11 +160,11 @@ public int getType() { return NodeTypeEnums.RuleTerminalNode; } - public ObjectTypeNodeId getLeftInputOtnId() { + public ObjectTypeNodeId getInputOtnId() { return leftInputOtnId; } - public void setLeftInputOtnId(ObjectTypeNodeId leftInputOtnId) { + public void setInputOtnId(ObjectTypeNodeId leftInputOtnId) { this.leftInputOtnId = leftInputOtnId; } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java b/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java index 90968320ee9..34ec420b68c 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java @@ -34,7 +34,7 @@ import org.drools.core.phreak.RuntimeSegmentUtilities; import org.drools.core.reteoo.AsyncReceiveNode.AsyncReceiveMemory; import org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory; -import org.drools.core.reteoo.RightInputAdapterNode.RiaPathMemory; +import org.drools.core.reteoo.TupleToObjectNode.SubnetworkPathMemory; import org.drools.core.reteoo.TimerNode.TimerNodeMemory; import org.drools.core.util.LinkedList; import org.drools.core.util.DoubleLinkedEntry; @@ -291,7 +291,7 @@ public void mergePathMemories(SegmentMemory segmentMemory) { } private boolean isAssociatedWith( PathMemory pmem ) { - if (NodeTypeEnums.RightInputAdapterNode == pmem.getNodeType()) { + if (NodeTypeEnums.TupleToObjectNode == pmem.getNodeType()) { for (PathEndNode endNode : pmem.getPathEndNode().getPathEndNodes() ) { if (NodeTypeEnums.isTerminalNode(endNode)) { if ( proto.getRootNode().hasAssociatedTerminal((AbstractTerminalNode)endNode)) { @@ -611,7 +611,7 @@ public abstract static class MemoryPrototype { public static MemoryPrototype get(Memory memory) { if (memory instanceof BetaMemory) { BetaMemory betaMemory = (BetaMemory)memory; - return new BetaMemoryPrototype(betaMemory.getNodePosMaskBit(), betaMemory.getRiaRuleMemory() != null ? betaMemory.getRiaRuleMemory().getRightInputAdapterNode() : null); + return new BetaMemoryPrototype(betaMemory.getNodePosMaskBit(), betaMemory.getSubnetworkPathMemory() != null ? betaMemory.getSubnetworkPathMemory().getTupleToObjectNode() : null); } if (memory instanceof LeftInputAdapterNode.LiaNodeMemory) { return new LiaMemoryPrototype(((LeftInputAdapterNode.LiaNodeMemory)memory).getNodePosMaskBit()); @@ -625,7 +625,7 @@ public static MemoryPrototype get(Memory memory) { } if (memory instanceof AccumulateNode.AccumulateMemory) { BetaMemory betaMemory = ((AccumulateNode.AccumulateMemory)memory).getBetaMemory(); - return new AccumulateMemoryPrototype(new BetaMemoryPrototype( betaMemory.getNodePosMaskBit(), betaMemory.getRiaRuleMemory() != null ? betaMemory.getRiaRuleMemory().getRightInputAdapterNode() : null) ); + return new AccumulateMemoryPrototype(new BetaMemoryPrototype( betaMemory.getNodePosMaskBit(), betaMemory.getSubnetworkPathMemory() != null ? betaMemory.getSubnetworkPathMemory().getTupleToObjectNode() : null) ); } if (memory instanceof ReactiveFromNode.ReactiveFromMemory) { return new ReactiveFromMemoryPrototype(((ReactiveFromNode.ReactiveFromMemory)memory).getNodePosMaskBit()); @@ -645,23 +645,23 @@ public long getNodePosMaskBit() { } public static class BetaMemoryPrototype extends MemoryPrototype { - private final RightInputAdapterNode riaNode; + private final TupleToObjectNode tton; - public BetaMemoryPrototype(long nodePosMaskBit, RightInputAdapterNode riaNode) { + public BetaMemoryPrototype(long nodePosMaskBit, TupleToObjectNode tton) { this.nodePosMaskBit = nodePosMaskBit; - this.riaNode = riaNode; + this.tton = tton; } @Override public void populateMemory(ReteEvaluator reteEvaluator, Memory memory) { BetaMemory betaMemory = (BetaMemory)memory; betaMemory.setNodePosMaskBit(nodePosMaskBit); - if (riaNode != null) { - RiaPathMemory riaMem = (RiaPathMemory) reteEvaluator.getNodeMemories().peekNodeMemory(riaNode); + if (tton != null) { + SubnetworkPathMemory riaMem = (SubnetworkPathMemory) reteEvaluator.getNodeMemories().peekNodeMemory(tton); if (riaMem == null) { - riaMem = ( RiaPathMemory) RuntimeSegmentUtilities.initializePathMemory(reteEvaluator, riaNode); + riaMem = (SubnetworkPathMemory) RuntimeSegmentUtilities.initializePathMemory(reteEvaluator, tton); } - betaMemory.setRiaRuleMemory(riaMem); + betaMemory.setSubnetworkPathMemory(riaMem); } } } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/SingleObjectSinkAdapter.java b/drools-core/src/main/java/org/drools/core/reteoo/SingleObjectSinkAdapter.java index b6a93ad781b..b2c09470618 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/SingleObjectSinkAdapter.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/SingleObjectSinkAdapter.java @@ -87,47 +87,46 @@ public void byPassModifyToBetaNode (final InternalFactHandle factHandle, sink.byPassModifyToBetaNode( factHandle, modifyPreviousTuples, context, reteEvaluator ); } - public void doLinkRiaNode(ReteEvaluator reteEvaluator) { - staticDoLinkRiaNode( sink, reteEvaluator ); + public void doLinkSubnetwork(ReteEvaluator reteEvaluator) { + staticDoLinkSubnetwork(sink, reteEvaluator); } - public static void staticDoLinkRiaNode(ObjectSink sink, ReteEvaluator reteEvaluator) { + public static void staticDoLinkSubnetwork(ObjectSink sink, ReteEvaluator reteEvaluator) { BetaMemory bm; - if ( sink.getType() == NodeTypeEnums.AccumulateNode ) { - AccumulateNode accnode = ( AccumulateNode ) sink; - AccumulateMemory accMem = ( AccumulateMemory ) reteEvaluator.getNodeMemory( accnode ); + BetaNode betaNode; + if ( sink.getType() == NodeTypeEnums.AccumulateRightAdapterNode ) { + AccumulateRight accnode = ( AccumulateRight ) sink; + betaNode = accnode.getBetaNode(); + AccumulateMemory accMem = ( AccumulateMemory ) reteEvaluator.getNodeMemory( betaNode ); bm = accMem.getBetaMemory(); - } else if ( NodeTypeEnums.isBetaNode( sink ) ) { - BetaNode betaNode = ( BetaNode ) sink; - bm = (BetaMemory) BetaNode.getBetaMemoryFromRightInput(betaNode, reteEvaluator); } else { - throw new RuntimeException( "Should not be possible to have link into a node of type" + sink); + RightInputAdapterNode betaRight = (RightInputAdapterNode) sink; + betaNode = betaRight.getBetaNode(); + bm = RightInputAdapterNode.getBetaMemoryFromRightInput(betaNode, reteEvaluator); } if ( bm.getStagedRightTuples().isEmpty() ) { if ( bm.getRightTupleMemory().size() == 0 ) { - bm.linkNode( ( BetaNode ) sink, reteEvaluator ); + bm.linkNode( betaNode, reteEvaluator ); } else { - bm.setNodeDirty( ( BetaNode ) sink, reteEvaluator ); + bm.setNodeDirty( betaNode, reteEvaluator ); } } } - public void doUnlinkRiaNode( ReteEvaluator reteEvaluator) { - staticDoUnlinkRiaNode( sink, reteEvaluator ); + public void doUnlinkSubnetwork(ReteEvaluator reteEvaluator) { + staticDoUnlinkSubnetwork(sink, reteEvaluator); } - public static void staticDoUnlinkRiaNode(ObjectSink sink, ReteEvaluator reteEvaluator) { + public static void staticDoUnlinkSubnetwork(ObjectSink sink, ReteEvaluator reteEvaluator) { BetaMemory bm; - if ( sink.getType() == NodeTypeEnums.AccumulateNode ) { - AccumulateNode accnode = ( AccumulateNode ) sink; + if ( sink.getType() == NodeTypeEnums.AccumulateRightAdapterNode ) { + AccumulateNode accnode = ((AccumulateRight)sink).getBetaNode(); AccumulateMemory accMem = ( AccumulateMemory ) reteEvaluator.getNodeMemory( accnode ); bm = accMem.getBetaMemory(); - } else if ( NodeTypeEnums.isBetaNode( sink ) ) { - BetaNode betaNode = ( BetaNode ) sink; - bm = (BetaMemory) BetaNode.getBetaMemoryFromRightInput(betaNode, reteEvaluator); - } else { - throw new RuntimeException( "Should not be possible to have link into a node of type" + sink); + } else { + BetaNode betaNode = ((RightInputAdapterNode) sink).getBetaNode(); + bm = RightInputAdapterNode.getBetaMemoryFromRightInput(betaNode, reteEvaluator); } if (sink.getType() == NodeTypeEnums.NotNode) { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java b/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java index 41a63759824..e0bf8207fc4 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java @@ -70,7 +70,7 @@ public TimerNode(final int id, this.startEndDeclarations = startEndDeclarations; this.tupleMemoryEnabled = context.isTupleMemoryEnabled(); - initMasks(context, tupleSource); + initMasks(context); hashcode = calculateHashCode(); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java b/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java index f0f9d7a1c6b..fc4dc2c5f10 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java @@ -45,7 +45,7 @@ public static TupleImpl createPeer(Sink n, TupleImpl original) { case NodeTypeEnums.ReactiveFromNode: peer = new ReactiveFromNodeLeftTuple(); break; - case NodeTypeEnums.RightInputAdapterNode: + case NodeTypeEnums.TupleToObjectNode: peer = new SubnetworkTuple(); break; case NodeTypeEnums.QueryTerminalNode: @@ -82,7 +82,7 @@ public static TupleImpl createLeftTuple(Sink s, return new EvalNodeLeftTuple(factHandle, s, leftTupleMemoryEnabled); case NodeTypeEnums.ReactiveFromNode: return new ReactiveFromNodeLeftTuple(factHandle, s, leftTupleMemoryEnabled); - case NodeTypeEnums.RightInputAdapterNode: + case NodeTypeEnums.TupleToObjectNode: return new SubnetworkTuple(factHandle, s, leftTupleMemoryEnabled); case NodeTypeEnums.QueryTerminalNode: case NodeTypeEnums.RuleTerminalNode: @@ -112,7 +112,7 @@ public static TupleImpl createLeftTuple(final InternalFactHandle factHandle, return new EvalNodeLeftTuple(factHandle, leftTuple, s); case NodeTypeEnums.ReactiveFromNode: return new ReactiveFromNodeLeftTuple(factHandle, leftTuple, s); - case NodeTypeEnums.RightInputAdapterNode: + case NodeTypeEnums.TupleToObjectNode: return new SubnetworkTuple(factHandle, leftTuple, s); case NodeTypeEnums.QueryTerminalNode: case NodeTypeEnums.RuleTerminalNode: @@ -143,7 +143,7 @@ public static TupleImpl createLeftTuple(TupleImpl leftTuple, return new EvalNodeLeftTuple(leftTuple, s, pctx, leftTupleMemoryEnabled); case NodeTypeEnums.ReactiveFromNode: throw new IllegalStateException("ReactFromNode does not implement this constructor."); - case NodeTypeEnums.RightInputAdapterNode: + case NodeTypeEnums.TupleToObjectNode: return new SubnetworkTuple(leftTuple, s, pctx, leftTupleMemoryEnabled); case NodeTypeEnums.QueryTerminalNode: case NodeTypeEnums.RuleTerminalNode: @@ -173,7 +173,7 @@ public static TupleImpl createLeftTuple(TupleImpl leftTuple, return new EvalNodeLeftTuple(leftTuple, rightTuple, s); case NodeTypeEnums.ReactiveFromNode: throw new IllegalStateException("ReactFromNode does not implement this constructor."); - case NodeTypeEnums.RightInputAdapterNode: + case NodeTypeEnums.TupleToObjectNode: return new SubnetworkTuple(leftTuple, rightTuple, s); case NodeTypeEnums.QueryTerminalNode: case NodeTypeEnums.RuleTerminalNode: @@ -206,7 +206,7 @@ public static TupleImpl createLeftTuple(TupleImpl leftTuple, return new EvalNodeLeftTuple(leftTuple, rightTuple, currentLeftChild, currentRightChild, s, leftTupleMemoryEnabled); case NodeTypeEnums.ReactiveFromNode: return new ReactiveFromNodeLeftTuple(leftTuple, rightTuple, currentLeftChild, currentRightChild, s, leftTupleMemoryEnabled); - case NodeTypeEnums.RightInputAdapterNode: + case NodeTypeEnums.TupleToObjectNode: return new SubnetworkTuple(leftTuple, rightTuple, currentLeftChild, currentRightChild, s, leftTupleMemoryEnabled); case NodeTypeEnums.QueryTerminalNode: case NodeTypeEnums.RuleTerminalNode: diff --git a/drools-core/src/main/java/org/drools/core/reteoo/TupleToObjectNode.java b/drools-core/src/main/java/org/drools/core/reteoo/TupleToObjectNode.java new file mode 100644 index 00000000000..6712dc63bd0 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/reteoo/TupleToObjectNode.java @@ -0,0 +1,437 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.core.reteoo; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.drools.base.base.ObjectType; +import org.drools.base.common.NetworkNode; +import org.drools.base.definitions.rule.impl.RuleImpl; +import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.rule.Pattern; +import org.drools.core.RuleBaseConfiguration; +import org.drools.core.common.ActivationsManager; +import org.drools.core.common.InternalWorkingMemory; +import org.drools.core.common.Memory; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.common.UpdateContext; +import org.drools.core.reteoo.SegmentMemory.SegmentPrototype; +import org.drools.core.reteoo.builder.BuildContext; +import org.drools.util.bitmask.BitMask; +import org.kie.api.definition.rule.Rule; + +/** + * When joining a subnetwork into the main network again, TupleToObjectNode adapts the + * subnetwork's tuple into a fact in order right join it with the tuple being propagated in + * the main network. + */ +public class TupleToObjectNode extends ObjectSource + implements + LeftTupleSinkNode, + PathEndNode { + + private static final long serialVersionUID = 510l; + + private LeftTupleSource tupleSource; + + /** + * This is first node inside of the subnetwork. The split, with two outs, would be the parent node. + */ + private LeftTupleSource startTupleSource; + + private boolean tupleMemoryEnabled; + + private LeftTupleSinkNode previousTupleSinkNode; + private LeftTupleSinkNode nextTupleSinkNode; + + private LeftTupleNode[] pathNodes; + + private PathEndNode[] pathEndNodes; + + private PathMemSpec pathMemSpec; + + private SegmentPrototype[] segmentPrototypes; + + private SegmentPrototype[] eagerSegmentPrototypes; + + private int objectCount; + + public TupleToObjectNode() { + } + + /** + * Constructor specifying the unique id of the node in the Rete network, the position of the propagating FactHandleImpl in + * ReteTuple and the source that propagates the receive ReteTuples. + * + * @param id + * Unique id + * @param source + * The TupleSource which propagates the received ReteTuple + */ + public TupleToObjectNode(final int id, + final LeftTupleSource source, + final LeftTupleSource startTupleSource, + final BuildContext context) { + super( id, context.getPartitionId() ); + this.tupleSource = source; + this.tupleMemoryEnabled = context.isTupleMemoryEnabled(); + this.startTupleSource = startTupleSource; + + hashcode = calculateHashCode(); + initMemoryId( context ); + } + + @Override + public PathMemSpec getPathMemSpec() { + return getPathMemSpec(null); + } + + + /** + * used during network build time, potentially during rule removal time. + * @param removingTN + * @return + */ + @Override + public PathMemSpec getPathMemSpec(TerminalNode removingTN) { + if (pathMemSpec == null) { + pathMemSpec = calculatePathMemSpec( startTupleSource, removingTN ); + } + return pathMemSpec; + } + + + @Override + public void nullPathMemSpec() { + pathMemSpec = null; + } + + @Override + public void setPathMemSpec(PathMemSpec pathMemSpec) { + this.pathMemSpec = pathMemSpec; + } + + @Override + public void resetPathMemSpec(TerminalNode removingTN) { + nullPathMemSpec(); + pathMemSpec = getPathMemSpec(removingTN); + } + + @Override + public void setSegmentPrototypes(SegmentPrototype[] smems) { + this.segmentPrototypes = smems; + } + + @Override + public SegmentPrototype[] getSegmentPrototypes() { + return segmentPrototypes; + } + + @Override + public SegmentPrototype[] getEagerSegmentPrototypes() { + return eagerSegmentPrototypes; + } + + @Override + public void setEagerSegmentPrototypes(SegmentPrototype[] eagerSegmentPrototypes) { + this.eagerSegmentPrototypes = eagerSegmentPrototypes; + } + + @Override + public void setPathEndNodes(PathEndNode[] pathEndNodes) { + this.pathEndNodes = pathEndNodes; + } + + @Override + public PathEndNode[] getPathEndNodes() { + return pathEndNodes; + } + + public LeftTupleSource getStartTupleSource() { + return startTupleSource; + } + + public int getPathIndex() { + return tupleSource.getPathIndex() + 1; + } + + public int getObjectCount() { + return objectCount; + } + + public void setObjectCount(int count) { + objectCount = count; + } + + /** + * Creates and return the node memory + */ + public SubnetworkPathMemory createMemory(final RuleBaseConfiguration config, ReteEvaluator reteEvaluator) { + return (SubnetworkPathMemory) AbstractTerminalNode.initPathMemory(this, new SubnetworkPathMemory(this, reteEvaluator)); + } + + public void doAttach( BuildContext context ) { + this.tupleSource.addTupleSink( this, context ); + } + + public void networkUpdated(UpdateContext updateContext) { + this.tupleSource.networkUpdated(updateContext); + } + + + protected boolean doRemove(final RuleRemovalContext context, + final ReteooBuilder builder) { + if ( !isInUse() ) { + tupleSource.removeTupleSink(this); + return true; + } + return false; + } + + public boolean isLeftTupleMemoryEnabled() { + return tupleMemoryEnabled; + } + + /** + * Returns the next node + * @return + * The next TupleSinkNode + */ + public LeftTupleSinkNode getNextLeftTupleSinkNode() { + return this.nextTupleSinkNode; + } + + /** + * Sets the next node + * @param next + * The next TupleSinkNode + */ + public void setNextLeftTupleSinkNode(final LeftTupleSinkNode next) { + this.nextTupleSinkNode = next; + } + + /** + * Returns the previous node + * @return + * The previous TupleSinkNode + */ + public LeftTupleSinkNode getPreviousLeftTupleSinkNode() { + return this.previousTupleSinkNode; + } + + /** + * Sets the previous node + * @param previous + * The previous TupleSinkNode + */ + public void setPreviousLeftTupleSinkNode(final LeftTupleSinkNode previous) { + this.previousTupleSinkNode = previous; + } + + public int getType() { + return NodeTypeEnums.TupleToObjectNode; + } + + private int calculateHashCode() { + return this.tupleSource.hashCode() * 17 + ((this.tupleMemoryEnabled) ? 1234 : 4321); + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + + return ((NetworkNode)object).getType() == NodeTypeEnums.TupleToObjectNode && this.hashCode() == object.hashCode() && + this.tupleSource.getId() == ((TupleToObjectNode)object).tupleSource.getId() && + this.tupleMemoryEnabled == ( (TupleToObjectNode) object ).tupleMemoryEnabled; + } + + @Override + public String toString() { + return "RightInputAdapterNode(" + id + ")[ tupleMemoryEnabled=" + tupleMemoryEnabled + ", tupleSource=" + tupleSource + ", source=" + + source + ", associations=" + associations + ", partitionId=" + partitionId + "]"; + } + + public LeftTupleSource getLeftTupleSource() { + return this.tupleSource; + } + + public void setTupleSource( LeftTupleSource tupleSource ) { + this.tupleSource = tupleSource; + } + + public ObjectTypeNodeId getInputOtnId() { + throw new UnsupportedOperationException(); + } + + public void setInputOtnId(ObjectTypeNodeId leftInputOtnId) { + throw new UnsupportedOperationException(); + } + + @Override + public BitMask calculateDeclaredMask(Pattern pattern, ObjectType modifiedType, List settableProperties) { + throw new UnsupportedOperationException(); + } + + public static class SubnetworkPathMemory extends PathMemory implements Memory { + private List rules; + + public SubnetworkPathMemory(PathEndNode pathEndNode, ReteEvaluator reteEvaluator) { + super(pathEndNode, reteEvaluator); + } + + @Override + protected boolean initDataDriven( ReteEvaluator reteEvaluator ) { + for (PathEndNode pnode : getPathEndNode().getPathEndNodes()) { + if (NodeTypeEnums.isTerminalNode(pnode)) { + RuleImpl rule = ( (TerminalNode) pnode ).getRule(); + if ( isRuleDataDriven( reteEvaluator, rule ) ) { + return true; + } + } + } + return false; + } + + public TupleToObjectNode getTupleToObjectNode() { + return (TupleToObjectNode) getPathEndNode(); + } + + @Override + public void doLinkRule(ReteEvaluator reteEvaluator) { + getTupleToObjectNode().getObjectSinkPropagator().doLinkSubnetwork(reteEvaluator); + } + + @Override + public void doLinkRule(ActivationsManager activationsManager) { + doLinkRule(activationsManager.getReteEvaluator()); + } + + @Override + public void doUnlinkRule(ReteEvaluator reteEvaluator) { + getTupleToObjectNode().getObjectSinkPropagator().doUnlinkSubnetwork(reteEvaluator); + } + + private void updateRuleTerminalNodes() { + rules = new ArrayList<>(); + for ( ObjectSink osink : getTupleToObjectNode().getObjectSinkPropagator().getSinks() ) { + for ( LeftTupleSink ltsink : ((BetaNode)osink).getSinkPropagator().getSinks() ) { + findAndAddTN(ltsink, rules ); + } + } + } + + private void findAndAddTN( LeftTupleSink ltsink, List terminalNodes) { + if ( NodeTypeEnums.isTerminalNode(ltsink)) { + terminalNodes.add( ((TerminalNode)ltsink).getRule() ); + } else if ( ltsink.getType() == NodeTypeEnums.TupleToObjectNode) { + for ( NetworkNode childSink : ( ltsink).getSinks() ) { + findAndAddTN((LeftTupleSink)childSink, terminalNodes); + } + } else { + for ( LeftTupleSink childLtSink : (ltsink).getSinkPropagator().getSinks() ) { + findAndAddTN(childLtSink, terminalNodes); + } + } + } + + public List getAssociatedRules() { + if ( rules == null ) { + updateRuleTerminalNodes(); + } + return rules; + } + + public String getRuleNames() { + Set ruleNames = new HashSet<>(); + for (RuleImpl rule : getAssociatedRules()) { + ruleNames.add(rule.getName()); + } + return ruleNames.toString(); + } + + @Override + public int getNodeType() { + return NodeTypeEnums.TupleToObjectNode; + } + + public String toString() { + return "TupleToObjectNodeMem(" + getTupleToObjectNode().getId() + ") [" + getRuleNames() + "]"; + } + } + + public BitMask getInferredMask() { + throw new UnsupportedOperationException(); + } + + @Override + public void updateSink(ObjectSink sink, PropagationContext context, InternalWorkingMemory wm) { + throw new UnsupportedOperationException(); + } + + public LeftTupleNode[] getPathNodes() { + if (pathNodes == null) { + pathNodes = AbstractTerminalNode.getPathNodes( this ); + } + return pathNodes; + } + + public boolean hasPathNode(LeftTupleNode node) { + for (LeftTupleNode pathNode : getPathNodes()) { + if (node.getId() == pathNode.getId()) { + return true; + } + } + return false; + } + + public LeftTupleSinkPropagator getSinkPropagator() { + return EmptyLeftTupleSinkAdapter.getInstance(); + } + + @Override + public void addAssociation(Rule rule, BuildContext context) { + super.addAssociation(rule, context); + context.addPathEndNode( this ); + } + + @Override + public boolean removeAssociation( Rule rule, RuleRemovalContext context ) { + boolean result = super.associations.remove(rule); + if (getAssociationsSize() == 0) { + // avoid to recalculate the pathEndNodes if this node is going to be removed + return result; + } + + List remainingPathNodes = new ArrayList<>(); + for (PathEndNode pathEndNode : pathEndNodes) { + if (pathEndNode.getAssociatedTerminalsSize() > 0) { + remainingPathNodes.add(pathEndNode); + } + } + pathEndNodes = remainingPathNodes.toArray( new PathEndNode[remainingPathNodes.size()] ); + return result; + } + +} diff --git a/drools-core/src/main/java/org/drools/core/reteoo/WindowNode.java b/drools-core/src/main/java/org/drools/core/reteoo/WindowNode.java index d4edd37b8fa..d3f54b76df5 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/WindowNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/WindowNode.java @@ -197,7 +197,7 @@ public void modifyObject(InternalFactHandle factHandle, TupleImpl rightTuple = modifyPreviousTuples.peekRightTuple(partitionId); // if the peek is for a different OTN we assume that it is after the current one and then this is an assert - while ( rightTuple != null && rightTuple.getInputOtnId().before(getRightInputOtnId()) ) { + while ( rightTuple != null && rightTuple.getInputOtnId().before(getInputOtnId()) ) { modifyPreviousTuples.removeRightTuple(partitionId); // we skipped this node, due to alpha hashing, so retract now @@ -206,7 +206,7 @@ public void modifyObject(InternalFactHandle factHandle, rightTuple = modifyPreviousTuples.peekRightTuple(partitionId); } - if ( rightTuple != null && rightTuple.getInputOtnId().equals(getRightInputOtnId()) ) { + if ( rightTuple != null && rightTuple.getInputOtnId().equals(getInputOtnId()) ) { modifyPreviousTuples.removeRightTuple(partitionId); rightTuple.reAdd(); modifyRightTuple( rightTuple, context, reteEvaluator ); @@ -354,7 +354,7 @@ public Collection getFactHandles() { } } - public ObjectTypeNodeId getRightInputOtnId() { + public ObjectTypeNodeId getInputOtnId() { return rightInputOtnId; } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/AccumulateBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/AccumulateBuilder.java index f5c9b2ac48d..5ebbfce3660 100755 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/AccumulateBuilder.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/AccumulateBuilder.java @@ -29,7 +29,7 @@ import org.drools.core.reteoo.AccumulateNode; import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.reteoo.LeftTupleSource; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.base.rule.constraint.BetaConstraint; public class AccumulateBuilder @@ -70,13 +70,13 @@ public void build(final BuildContext context, // if object source is null, then we need to adapt tuple source into a subnetwork if ( context.getObjectSource() == null ) { // attach right input adapter node to convert tuple source into an object source - RightInputAdapterNode riaNode = CoreComponentFactory.get().getNodeFactoryService().buildRightInputNode( context.getNextNodeId(), - context.getTupleSource(), - tupleSource, - context ); + TupleToObjectNode tton = CoreComponentFactory.get().getNodeFactoryService().buildRightInputNode(context.getNextNodeId(), + context.getTupleSource(), + tupleSource, + context); // attach right input adapter node to convert tuple source into an object source - context.setObjectSource( utils.attachNode( context, riaNode ) ); + context.setObjectSource( utils.attachNode( context, tton ) ); // restore tuple source from before the start of the sub network context.setTupleSource( tupleSource ); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/BuildUtils.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/BuildUtils.java index aedd6b4e120..6a5b8be78eb 100755 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/BuildUtils.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/BuildUtils.java @@ -135,7 +135,7 @@ public T attachNode(BuildContext context, T candidate) { } partition = context.getPartitionId(); } - // set node whit the actual partition label + // set node with the actual partition label node.setPartitionId( context, partition ); node.attach(context); } else { @@ -151,7 +151,7 @@ public T attachNode(BuildContext context, T candidate) { } // adds the node to the context list to track all added nodes context.getNodes().add( node ); - node.addAssociation( context, context.getRule() ); + node.addAssociation(context.getRule(), context); return (T)node; } @@ -184,7 +184,7 @@ private boolean isSharingEnabledForNode(BuildContext context, BaseNode node) { } private boolean areNodesCompatibleForSharing(BuildContext context, BaseNode node) { - if ( node.getType() == NodeTypeEnums.RightInputAdapterNode) { + if ( node.getType() == NodeTypeEnums.TupleToObjectNode) { // avoid subnetworks sharing when they belong to 2 different agenda-groups String agendaGroup = context.getRule().getAgendaGroup(); for (Rule associatedRule : node.getAssociatedRules()) { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/CollectBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/CollectBuilder.java index da62bed442f..6ce56a83d2d 100755 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/CollectBuilder.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/CollectBuilder.java @@ -33,7 +33,7 @@ import org.drools.core.reteoo.AccumulateNode; import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.reteoo.LeftTupleSource; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.base.rule.constraint.BetaConstraint; public class CollectBuilder @@ -69,13 +69,13 @@ public void build(final BuildContext context, // if object source is null, then we need to adapt tuple source into a subnetwork if ( context.getObjectSource() == null ) { - RightInputAdapterNode riaNode = CoreComponentFactory.get().getNodeFactoryService().buildRightInputNode( context.getNextNodeId(), - context.getTupleSource(), - tupleSource, - context ); + TupleToObjectNode tton = CoreComponentFactory.get().getNodeFactoryService().buildRightInputNode(context.getNextNodeId(), + context.getTupleSource(), + tupleSource, + context); // attach right input adapter node to convert tuple source into an object source - context.setObjectSource( utils.attachNode( context, riaNode ) ); + context.setObjectSource( utils.attachNode( context, tton ) ); // restore tuple source from before the start of the sub network context.setTupleSource( tupleSource ); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/GroupElementBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/GroupElementBuilder.java index 9b2eca4ded0..61f8474a432 100755 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/GroupElementBuilder.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/GroupElementBuilder.java @@ -30,6 +30,7 @@ import org.drools.base.rule.Pattern; import org.drools.base.rule.RuleConditionElement; import org.drools.core.RuleBaseConfiguration; +import org.drools.core.common.BaseNode; import org.drools.core.common.BetaConstraints; import org.drools.core.common.TupleStartEqualsConstraint; import org.drools.core.reteoo.CoreComponentFactory; @@ -37,9 +38,8 @@ import org.drools.core.reteoo.JoinNode; import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.NotNode; -import org.drools.core.reteoo.ObjectSource; import org.drools.core.reteoo.ObjectTypeNode; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.base.rule.constraint.BetaConstraint; import org.kie.api.definition.rule.Propagation; @@ -140,9 +140,9 @@ public static void buildTupleSource(BuildContext context, BuildUtils utils, bool // if a previous object source was bound, but no tuple source if (context.getObjectSource() != null && context.getTupleSource() == null) { // we know this is the root OTN, so record it - ObjectSource source = context.getObjectSource(); + BaseNode source = context.getObjectSource(); while ( !(source.getType() == NodeTypeEnums.ObjectTypeNode ) ) { - source = source.getParentObjectSource(); + source = source.getParent(); } context.setRootObjectTypeNode( (ObjectTypeNode) source ); @@ -247,13 +247,13 @@ public void build(final BuildContext context, // if it is a subnetwork if ( context.getObjectSource() == null && context.getTupleSource() != null ) { - RightInputAdapterNode riaNode = CoreComponentFactory.get().getNodeFactoryService().buildRightInputNode(context.getNextNodeId(), - context.getTupleSource(), - tupleSource, - context); + TupleToObjectNode tton = CoreComponentFactory.get().getNodeFactoryService().buildRightInputNode(context.getNextNodeId(), + context.getTupleSource(), + tupleSource, + context); // attach right input adapter node to convert tuple source into an object source - context.setObjectSource( utils.attachNode( context, riaNode ) ); + context.setObjectSource( utils.attachNode( context, tton ) ); // restore tuple source from before the start of the sub network context.setTupleSource( tupleSource ); @@ -326,13 +326,13 @@ public void build(final BuildContext context, // if it is a subnetwork if ( context.getObjectSource() == null && context.getTupleSource() != null ) { - RightInputAdapterNode riaNode = CoreComponentFactory.get().getNodeFactoryService().buildRightInputNode( context.getNextNodeId(), - context.getTupleSource(), - tupleSource, - context ); + TupleToObjectNode tton = CoreComponentFactory.get().getNodeFactoryService().buildRightInputNode(context.getNextNodeId(), + context.getTupleSource(), + tupleSource, + context); // attach right input adapter node to convert tuple source into an object source - context.setObjectSource( utils.attachNode( context, riaNode ) ); + context.setObjectSource( utils.attachNode( context, tton ) ); // restore tuple source from before the start of the sub network context.setTupleSource( tupleSource ); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java index c02d6a8fa65..a5510919f6f 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java @@ -55,7 +55,7 @@ import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.QueryElementNode; import org.drools.core.reteoo.ReactiveFromNode; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.TerminalNode; import org.drools.core.reteoo.TimerNode; import org.drools.core.reteoo.WindowNode; @@ -96,10 +96,10 @@ EvalConditionNode buildEvalNode( int id, BuildContext context); - RightInputAdapterNode buildRightInputNode( int id, - LeftTupleSource leftInput, - LeftTupleSource startTupleSource, - BuildContext context ); + TupleToObjectNode buildRightInputNode(int id, + LeftTupleSource leftInput, + LeftTupleSource startTupleSource, + BuildContext context); JoinNode buildJoinNode( int id, LeftTupleSource leftInput, diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java index 9a912664d98..f266f51b359 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java @@ -39,6 +39,7 @@ import org.drools.base.time.impl.Timer; import org.drools.core.common.BetaConstraints; import org.drools.core.reteoo.AccumulateNode; +import org.drools.core.reteoo.AccumulateRight; import org.drools.core.reteoo.AlphaNode; import org.drools.core.reteoo.AlphaTerminalNode; import org.drools.core.reteoo.AsyncReceiveNode; @@ -48,17 +49,20 @@ import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.EvalConditionNode; import org.drools.core.reteoo.ExistsNode; +import org.drools.core.reteoo.ExistsRight; import org.drools.core.reteoo.FromNode; import org.drools.core.reteoo.JoinNode; +import org.drools.core.reteoo.JoinRightAdapterNode; import org.drools.core.reteoo.LeftInputAdapterNode; import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.NotNode; +import org.drools.core.reteoo.NotRight; import org.drools.core.reteoo.ObjectSource; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.QueryElementNode; import org.drools.core.reteoo.QueryTerminalNode; import org.drools.core.reteoo.ReactiveFromNode; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.RuleTerminalNode; import org.drools.core.reteoo.TerminalNode; import org.drools.core.reteoo.TimerNode; @@ -101,31 +105,35 @@ public EvalConditionNode buildEvalNode(final int id, return new EvalConditionNode( id, tupleSource, eval, context ); } - public RightInputAdapterNode buildRightInputNode( int id, LeftTupleSource leftInput, LeftTupleSource splitStart, BuildContext context ) { + public TupleToObjectNode buildRightInputNode(int id, LeftTupleSource leftInput, LeftTupleSource splitStart, BuildContext context) { LeftTupleSource startTupleSource = leftInput; while (startTupleSource.getLeftTupleSource() != splitStart) { startTupleSource = startTupleSource.getLeftTupleSource(); } - return new RightInputAdapterNode( id, leftInput, startTupleSource, context ); + return new TupleToObjectNode(id, leftInput, startTupleSource, context ); } public JoinNode buildJoinNode( int id, LeftTupleSource leftInput, ObjectSource rightInput, BetaConstraints binder, BuildContext context ) { - return new JoinNode( id, leftInput, rightInput, binder, context ); + JoinRightAdapterNode joinRight = new JoinRightAdapterNode(id, rightInput, context); + return new JoinNode(context.getNextNodeId(), leftInput, joinRight, binder, context ); } public NotNode buildNotNode( int id, LeftTupleSource leftInput, ObjectSource rightInput, BetaConstraints binder, BuildContext context ) { - return new NotNode( id, leftInput, rightInput, binder, context ); + NotRight notRight = new NotRight(id, rightInput, context); + return new NotNode(context.getNextNodeId(), leftInput, notRight, binder, context ); } public ExistsNode buildExistsNode( int id, LeftTupleSource leftInput, ObjectSource rightInput, BetaConstraints binder, BuildContext context ) { - return new ExistsNode( id, leftInput, rightInput, binder, context ); + ExistsRight existsRight = new ExistsRight(id, rightInput, context); + return new ExistsNode(context.getNextNodeId(), leftInput, existsRight, binder, context ); } public AccumulateNode buildAccumulateNode(int id, LeftTupleSource leftInput, ObjectSource rightInput, AlphaNodeFieldConstraint[] resultConstraints, BetaConstraints sourceBinder, BetaConstraints resultBinder, Accumulate accumulate, BuildContext context) { - return new AccumulateNode(id, leftInput, rightInput, resultConstraints, sourceBinder, resultBinder, accumulate, context ); + AccumulateRight accRight = new AccumulateRight(id, rightInput, context); + return new AccumulateNode(context.getNextNodeId(), leftInput, accRight, resultConstraints, sourceBinder, resultBinder, accumulate, context ); } public LeftInputAdapterNode buildLeftInputAdapterNode( int id, ObjectSource objectSource, BuildContext context, boolean terminal ) { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java index ebb53112a7d..bb3209edd41 100755 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java @@ -51,7 +51,6 @@ import org.drools.core.impl.InternalRuleBase; import org.drools.core.phreak.PhreakBuilder; import org.drools.core.reteoo.PathEndNode; -import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.RuleBuilder; import org.drools.core.reteoo.TerminalNode; import org.drools.core.reteoo.WindowNode; @@ -230,11 +229,11 @@ private static void setPathEndNodes(BuildContext context, TerminalNode terminalN for ( int i = 0; i < pathEndNodes.length; i++ ) { PathEndNode node = context.getPathEndNodes().get(pathEndNodes.length-1-i); pathEndNodes[i] = node; - if (node.getType() == NodeTypeEnums.RightInputAdapterNode && node.getPathEndNodes() != null) { - PathEndNode[] riaPathEndNodes = new PathEndNode[node.getPathEndNodes().length + i]; - System.arraycopy( pathEndNodes, 0, riaPathEndNodes, 0, i ); - System.arraycopy( node.getPathEndNodes(), 0, riaPathEndNodes, i, node.getPathEndNodes().length ); - node.setPathEndNodes( riaPathEndNodes ); + if (node.getType() == NodeTypeEnums.TupleToObjectNode && node.getPathEndNodes() != null) { + PathEndNode[] SubnetworkNodes = new PathEndNode[node.getPathEndNodes().length + i]; + System.arraycopy( pathEndNodes, 0, SubnetworkNodes, 0, i ); + System.arraycopy( node.getPathEndNodes(), 0, SubnetworkNodes, i, node.getPathEndNodes().length ); + node.setPathEndNodes( SubnetworkNodes ); } else { node.setPathEndNodes( pathEndNodes ); } diff --git a/drools-core/src/test/java/org/drools/core/reteoo/BaseNodeTest.java b/drools-core/src/test/java/org/drools/core/reteoo/BaseNodeTest.java index dabc5b72d8b..551b5142d9f 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/BaseNodeTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/BaseNodeTest.java @@ -24,6 +24,7 @@ import org.drools.core.common.PropagationContext; import org.drools.core.common.UpdateContext; import org.drools.core.reteoo.builder.BuildContext; +import org.drools.util.bitmask.BitMask; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -65,6 +66,11 @@ protected boolean doRemove(final RuleRemovalContext context, return true; } + @Override + public BaseNode getParent() { + return null; + } + public boolean isInUse() { return true; } @@ -81,5 +87,15 @@ public void networkUpdated(UpdateContext updateContext) { public int getType() { return 0; } + + @Override + public BitMask getDeclaredMask() { + return null; + } + + @Override + public BitMask getInferredMask() { + return null; + } } } diff --git a/drools-core/src/test/java/org/drools/core/reteoo/BetaNodeTest.java b/drools-core/src/test/java/org/drools/core/reteoo/BetaNodeTest.java index f416955594e..a683ac9665b 100755 --- a/drools-core/src/test/java/org/drools/core/reteoo/BetaNodeTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/BetaNodeTest.java @@ -37,26 +37,27 @@ public void testEqualsObject() { BuildContext buildContext = new BuildContext( kBase, Collections.emptyList() ); final LeftTupleSource ts = new MockTupleSource( 1, buildContext ); - final ObjectSource os = new MockObjectSource( 2, buildContext ); + final ObjectSource os = new MockObjectSource( 2, buildContext ); + RightInputAdapterNode right = new JoinRightAdapterNode(5, os, buildContext); final BetaNode j1 = new JoinNode( 1, ts, - os, + right, EmptyBetaConstraints.getInstance(), buildContext ); final BetaNode j2 = new JoinNode( 2, ts, - os, + right, EmptyBetaConstraints.getInstance(), buildContext ); final BetaNode n1 = new NotNode( 3, ts, - os, + right, EmptyBetaConstraints.getInstance(), buildContext ); final BetaNode n2 = new NotNode( 4, ts, - os, + right, EmptyBetaConstraints.getInstance(), buildContext ); diff --git a/drools-core/src/test/java/org/drools/core/reteoo/MockLeftTupleSink.java b/drools-core/src/test/java/org/drools/core/reteoo/MockLeftTupleSink.java index c086a27578e..bd7ee9185fe 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/MockLeftTupleSink.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/MockLeftTupleSink.java @@ -46,6 +46,10 @@ public MockLeftTupleSink(BuildContext buildContext) { super( 0, buildContext ); } + public MockLeftTupleSink(final int id, BuildContext buildContext) { + super( id, buildContext ); + } + public MockLeftTupleSink(final int id) { super(id, null); } @@ -133,6 +137,19 @@ public int getType() { }; } + public LeftTupleSource getParent() { + if ( super.getLeftTupleSource() != null) { + return super.getLeftTupleSource(); + } + + return new MockLeftTupleSink(null) { + @Override + public int getType() { + return NodeTypeEnums.LeftInputAdapterNode; + } + }; + } + @Override public ObjectTypeNode getObjectTypeNode() { return null; diff --git a/drools-core/src/test/java/org/drools/core/reteoo/NodeTypeEnumTest.java b/drools-core/src/test/java/org/drools/core/reteoo/NodeTypeEnumTest.java index 719e49f436c..2bee35417aa 100644 --- a/drools-core/src/test/java/org/drools/core/reteoo/NodeTypeEnumTest.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/NodeTypeEnumTest.java @@ -34,7 +34,7 @@ public class NodeTypeEnumTest { AlphaNode alphaNode = new AlphaNode(); WindowNode winNode = new WindowNode(); - RightInputAdapterNode riaNode = new RightInputAdapterNode(); + TupleToObjectNode ttoNode = new TupleToObjectNode(); RuleTerminalNode rtNode = new RuleTerminalNode(); QueryTerminalNode qtNode = new QueryTerminalNode(); @@ -58,7 +58,7 @@ public void tesObjectSource() { assertThat(isObjectSource(otNode)).isTrue(); assertThat(isObjectSource(alphaNode)).isTrue(); - assertThat(isObjectSource(riaNode)).isTrue(); + assertThat(isObjectSource(ttoNode)).isTrue(); assertThat(isObjectSource(rtNode)).isFalse(); assertThat(isObjectSource(qtNode)).isFalse(); @@ -83,7 +83,7 @@ public void tesObjectSink() { assertThat(isObjectSink(otNode)).isTrue(); assertThat(isObjectSink(alphaNode)).isTrue(); - assertThat(isObjectSink(riaNode)).isFalse(); + assertThat(isObjectSink(ttoNode)).isFalse(); assertThat(isObjectSink(rtNode)).isFalse(); assertThat(isObjectSink(qtNode)).isFalse(); @@ -107,7 +107,7 @@ public void tesLeftTupleSource() { assertThat(isLeftTupleSource(reteNod)).isFalse(); assertThat(isLeftTupleSource(otNode)).isFalse(); assertThat(isLeftTupleSource(alphaNode)).isFalse(); - assertThat(isLeftTupleSource(riaNode)).isFalse(); + assertThat(isLeftTupleSource(ttoNode)).isFalse(); assertThat(isLeftTupleSource(rtNode)).isFalse(); assertThat(isLeftTupleSource(qtNode)).isFalse(); @@ -132,7 +132,7 @@ public void tesLeftTupleSink() { assertThat(isLeftTupleSink(otNode)).isFalse(); assertThat(isLeftTupleSink(alphaNode)).isFalse(); - assertThat(isLeftTupleSink(riaNode)).isTrue(); + assertThat(isLeftTupleSink(ttoNode)).isTrue(); assertThat(isLeftTupleSink(rtNode)).isTrue(); assertThat(isLeftTupleSink(qtNode)).isTrue(); @@ -157,7 +157,7 @@ public void testBetaNode() { assertThat(isBetaNode(otNode)).isFalse(); assertThat(isBetaNode(alphaNode)).isFalse(); - assertThat(isBetaNode(riaNode)).isFalse(); + assertThat(isBetaNode(ttoNode)).isFalse(); assertThat(isBetaNode(rtNode)).isFalse(); assertThat(isBetaNode(qtNode)).isFalse(); diff --git a/drools-core/src/test/java/org/drools/core/util/RightTupleListTest.java b/drools-core/src/test/java/org/drools/core/util/RightTupleListTest.java index b992a9b7e7f..238e06b2874 100644 --- a/drools-core/src/test/java/org/drools/core/util/RightTupleListTest.java +++ b/drools-core/src/test/java/org/drools/core/util/RightTupleListTest.java @@ -20,13 +20,17 @@ import org.drools.core.common.DefaultFactHandle; import org.drools.core.common.InternalFactHandle; +import org.drools.core.impl.KnowledgeBaseImpl; import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.MockLeftTupleSink; import org.drools.core.reteoo.MockObjectSink; +import org.drools.core.reteoo.builder.BuildContext; import org.drools.core.test.model.Cheese; import org.drools.core.util.index.TupleList; import org.junit.Test; +import java.util.Collections; + import static org.assertj.core.api.Assertions.assertThat; public class RightTupleListTest { @@ -38,6 +42,7 @@ public void testEmptyIterator() { final InternalFactHandle h1 = new DefaultFactHandle( 1, stilton1 ); - assertThat(map.getFirst(new LeftTuple(h1, new MockLeftTupleSink(0), true ))).isNull(); + BuildContext bctx = new BuildContext(new KnowledgeBaseImpl("1"), Collections.emptyList()); + assertThat(map.getFirst(new LeftTuple(h1, new MockLeftTupleSink(0, bctx), true ))).isNull(); } } diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/debug/BetaRightAdapterNodeVisitor.java b/drools-kiesession/src/main/java/org/drools/kiesession/debug/BetaRightAdapterNodeVisitor.java new file mode 100755 index 00000000000..fe50749c2cc --- /dev/null +++ b/drools-kiesession/src/main/java/org/drools/kiesession/debug/BetaRightAdapterNodeVisitor.java @@ -0,0 +1,60 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.kiesession.debug; + +import org.drools.base.common.NetworkNode; +import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.core.common.Memory; +import org.drools.core.reteoo.AccumulateNode.AccumulateMemory; +import org.drools.core.reteoo.BetaMemory; +import org.drools.core.reteoo.BetaNode; +import org.drools.core.reteoo.RightInputAdapterNode; + +import java.util.Collection; + +public class BetaRightAdapterNodeVisitor extends AbstractNetworkNodeVisitor { + + public static final BetaRightAdapterNodeVisitor INSTANCE = new BetaRightAdapterNodeVisitor(); + + protected BetaRightAdapterNodeVisitor() { + } + + @Override + protected void doVisit(NetworkNode node, + Collection nodeStack, + StatefulKnowledgeSessionInfo info) { + RightInputAdapterNode an = (RightInputAdapterNode) node; + DefaultNodeInfo ni = info.getNodeInfo( node ); + + BetaNode betaNode = an.getBetaNode(); + + Memory childMemory = info.getSession().getNodeMemory( betaNode ); + + BetaMemory bm; + if ( betaNode.getType() == NodeTypeEnums.AccumulateNode ) { + bm = ((AccumulateMemory) childMemory).getBetaMemory(); + } else { + bm = (BetaMemory) childMemory; + } + + ni.setTupleMemorySize( bm.getRightTupleMemory().size() ); + ni.setCreatedFactHandles( bm.getRightTupleMemory().size() ); + } + +} diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/debug/RightInputAdapterNodeVisitor.java b/drools-kiesession/src/main/java/org/drools/kiesession/debug/RightInputAdapterNodeVisitor.java index 7bcd7ac9027..cd5189267d3 100755 --- a/drools-kiesession/src/main/java/org/drools/kiesession/debug/RightInputAdapterNodeVisitor.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/debug/RightInputAdapterNodeVisitor.java @@ -25,6 +25,7 @@ import org.drools.core.reteoo.BetaMemory; import org.drools.core.reteoo.BetaNode; import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import java.util.Collection; @@ -39,10 +40,10 @@ protected RightInputAdapterNodeVisitor() { protected void doVisit(NetworkNode node, Collection nodeStack, StatefulKnowledgeSessionInfo info) { - RightInputAdapterNode an = (RightInputAdapterNode) node; - DefaultNodeInfo ni = info.getNodeInfo( node ); + TupleToObjectNode an = (TupleToObjectNode) node; + DefaultNodeInfo ni = info.getNodeInfo( node ); - BetaNode betaNode = (BetaNode) an.getObjectSinkPropagator().getSinks()[0]; + BetaNode betaNode = ((RightInputAdapterNode)an.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); Memory childMemory = info.getSession().getNodeMemory( betaNode ); diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/debug/SessionInspector.java b/drools-kiesession/src/main/java/org/drools/kiesession/debug/SessionInspector.java index 3998deb3d33..2396abf4be9 100755 --- a/drools-kiesession/src/main/java/org/drools/kiesession/debug/SessionInspector.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/debug/SessionInspector.java @@ -36,6 +36,7 @@ import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.QueryTerminalNode; import org.drools.core.reteoo.Rete; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.RuleTerminalNode; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.kie.api.runtime.KieSession; @@ -66,9 +67,19 @@ public class SessionInspector { ObjectTypeNodeVisitor.INSTANCE ); this.visitors.put( NodeTypeEnums.AlphaNode, AlphaNodeVisitor.INSTANCE ); - this.visitors.put( NodeTypeEnums.RightInputAdapterNode, + this.visitors.put( NodeTypeEnums.TupleToObjectNode, RightInputAdapterNodeVisitor.INSTANCE ); + + this.visitors.put( NodeTypeEnums.JoinRightAdapterNode, + BetaRightAdapterNodeVisitor.INSTANCE ); + this.visitors.put( NodeTypeEnums.ExistsRightAdapterNode, + BetaRightAdapterNodeVisitor.INSTANCE ); + this.visitors.put( NodeTypeEnums.NotRightAdapterNode, + BetaRightAdapterNodeVisitor.INSTANCE ); + this.visitors.put( NodeTypeEnums.AccumulateRightAdapterNode, + BetaRightAdapterNodeVisitor.INSTANCE ); + // left tuple source nodes this.visitors.put( NodeTypeEnums.JoinNode, BetaNodeVisitor.INSTANCE ); @@ -171,7 +182,9 @@ protected void visitChildren(NetworkNode parent, nodeStack, info ); } - } else if ( parent instanceof RuleTerminalNode || parent instanceof QueryTerminalNode ) { + } else if (parent instanceof RightInputAdapterNode ) { + // no children to visit + } else if ( parent instanceof RuleTerminalNode || parent instanceof QueryTerminalNode ) { // no children to visit } else { // did we forget any node type? diff --git a/drools-kiesession/src/test/java/org/drools/kiesession/NodeSegmentUnlinkingTest.java b/drools-kiesession/src/test/java/org/drools/kiesession/NodeSegmentUnlinkingTest.java index 9693d65b11c..0113e7349a9 100644 --- a/drools-kiesession/src/test/java/org/drools/kiesession/NodeSegmentUnlinkingTest.java +++ b/drools-kiesession/src/test/java/org/drools/kiesession/NodeSegmentUnlinkingTest.java @@ -31,6 +31,10 @@ import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.core.phreak.BuildtimeSegmentUtilities; import org.drools.core.reteoo.BetaMemory; +import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.ExistsRight; +import org.drools.core.reteoo.JoinRightAdapterNode; +import org.drools.core.reteoo.NotRight; import org.drools.core.reteoo.PathEndNode; import org.drools.core.reteoo.SegmentMemory.SegmentPrototype; import org.drools.core.reteoo.TerminalNode; @@ -88,15 +92,18 @@ private BetaNode createBetaNode(int id, BetaNode betaNode = null; switch ( type ) { case JOIN_NODE : { - betaNode = new JoinNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); + RightInputAdapterNode right = new JoinRightAdapterNode(9, mockObjectSource, buildContext); + betaNode = new JoinNode( id, leftTupleSource, right, new EmptyBetaConstraints(), buildContext ); break; } case EXISTS_NODE : { - betaNode = new ExistsNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); + RightInputAdapterNode right = new ExistsRight(9, mockObjectSource, buildContext); + betaNode = new ExistsNode( id, leftTupleSource, right, new EmptyBetaConstraints(), buildContext ); break; } case NOT_NODE : { - betaNode = new NotNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); + RightInputAdapterNode right = new NotRight(9, mockObjectSource, buildContext); + betaNode = new NotNode( id, leftTupleSource, right, new EmptyBetaConstraints(), buildContext ); break; } } @@ -167,25 +174,25 @@ public void setUp(int... type) { // \ // n7 -> n8 -> r3 - n1.addAssociation( rule1 ); - n1.addAssociation( rule2 ); - n1.addAssociation( rule3 ); - n2.addAssociation( rule1 ); - n2.addAssociation( rule2 ); - n2.addAssociation( rule3 ); - - n3.addAssociation( rule2 ); - n3.addAssociation( rule3 ); - - n4.addAssociation( rule2 ); - n4.addAssociation( rule3 ); - n5.addAssociation( rule2 ); - n5.addAssociation( rule3 ); - n6.addAssociation( rule2 ); - n6.addAssociation( rule3 ); - - n7.addAssociation( rule3 ); - n8.addAssociation( rule3 ); + n1.addAssociation(rule1, null); + n1.addAssociation(rule2, null); + n1.addAssociation(rule3, null); + n2.addAssociation(rule1, null); + n2.addAssociation(rule2, null); + n2.addAssociation(rule3, null); + + n3.addAssociation(rule2, null); + n3.addAssociation(rule3, null); + + n4.addAssociation(rule2, null); + n4.addAssociation(rule3, null); + n5.addAssociation(rule2, null); + n5.addAssociation(rule3, null); + n6.addAssociation(rule2, null); + n6.addAssociation(rule3, null); + + n7.addAssociation(rule3, null); + n8.addAssociation(rule3, null); // assumes no subnetworks for (TerminalNode tn : new TerminalNode[] {rtn1, rtn2, rtn3}) { @@ -208,29 +215,35 @@ public void testSingleNodeinSegment() { MockObjectSource mockObjectSource = new MockObjectSource( 8 ); MockTupleSource mockTupleSource = new MockTupleSource(9, buildContext); + RightInputAdapterNode right1 = new JoinRightAdapterNode(10, mockObjectSource, buildContext); + RightInputAdapterNode right2 = new JoinRightAdapterNode(11, mockObjectSource, buildContext); + RightInputAdapterNode right3 = new JoinRightAdapterNode(12, mockObjectSource, buildContext); + RightInputAdapterNode right4 = new JoinRightAdapterNode(12, mockObjectSource, buildContext); + RightInputAdapterNode right5 = new JoinRightAdapterNode(12, mockObjectSource, buildContext); + // n2 is only node in it's segment ObjectTypeNode otn = new ObjectTypeNode( 2, null, new ClassObjectType( String.class ), buildContext ); - BetaNode n1 = new JoinNode( 10, new LeftInputAdapterNode(3, otn, buildContext ), mockObjectSource, + BetaNode n1 = new JoinNode( 10, new LeftInputAdapterNode(3, otn, buildContext ), right1, new EmptyBetaConstraints(), buildContext ); - BetaNode n2 = new JoinNode( 11, n1, mockObjectSource, + BetaNode n2 = new JoinNode( 11, n1, right2, new EmptyBetaConstraints(), buildContext ); - BetaNode n3 = new JoinNode( 12, n1, mockObjectSource, + BetaNode n3 = new JoinNode( 12, n1, right3, new EmptyBetaConstraints(), buildContext ); - BetaNode n4 = new JoinNode( 13, n2, mockObjectSource, + BetaNode n4 = new JoinNode( 13, n2, right4, new EmptyBetaConstraints(), buildContext ); - BetaNode n5 = new JoinNode( 14, n2, mockObjectSource, + BetaNode n5 = new JoinNode( 14, n2, right5, new EmptyBetaConstraints(), buildContext ); - n1.addAssociation( rule1 ); - n1.addAssociation( rule2 ); - n1.addAssociation( rule3 ); + n1.addAssociation(rule1, null); + n1.addAssociation(rule2, null); + n1.addAssociation(rule3, null); - n2.addAssociation( rule2 ); - n2.addAssociation( rule3 ); + n2.addAssociation(rule2, null); + n2.addAssociation(rule3, null); - n3.addAssociation( rule1 ); - n4.addAssociation( rule2 ); - n5.addAssociation( rule3 ); + n3.addAssociation(rule1, null); + n4.addAssociation(rule2, null); + n5.addAssociation(rule3, null); mockObjectSource.attach(buildContext); mockTupleSource.attach(buildContext); @@ -287,7 +300,7 @@ public void testLiaNodeInitialisation() { // Initialise from n1 ksession = (StatefulKnowledgeSessionImpl)kBase.newKieSession(); - n1.assertObject( (InternalFactHandle) ksession.insert( "str" ), context, ksession ); + n1.getRightInput().assertObject( (InternalFactHandle) ksession.insert( "str" ), context, ksession ); liaMem = ksession.getNodeMemory(liaNode); @@ -308,7 +321,7 @@ public void testLiaNodeLinking() { RuntimeSegmentUtilities.getOrCreateSegmentMemory(liaNode, ksession); InternalFactHandle fh1 = (InternalFactHandle) ksession.insert( "str1" ); - n1.assertObject( fh1, context, ksession ); + n1.getRightInput().assertObject( fh1, context, ksession ); LiaNodeMemory liaMem = ksession.getNodeMemory(liaNode); assertThat(liaMem.getNodePosMaskBit()).isEqualTo(1); @@ -454,18 +467,18 @@ public void testAllLinkedInWithJoinNodesOnly() { StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newKieSession(); DefaultFactHandle f1 = (DefaultFactHandle) ksession.insert( "test1" ); - n3.assertObject( f1, context, ksession ); + n3.getRightInput().assertObject( f1, context, ksession ); BetaMemory bm = (BetaMemory) ksession.getNodeMemory(n3); assertThat(bm.getSegmentMemory().isSegmentLinked()).isFalse(); - n4.assertObject( f1, context, ksession ); + n4.getRightInput().assertObject( f1, context, ksession ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isFalse(); - n5.assertObject( f1, context, ksession ); + n5.getRightInput().assertObject( f1, context, ksession ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isFalse(); - n6.assertObject( f1, context, ksession ); + n6.getRightInput().assertObject( f1, context, ksession ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isTrue(); // only after all 4 nodes are populated, is the segment linked in } @@ -478,18 +491,18 @@ public void testAllLinkedInWithExistsNodesOnly() { StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newKieSession(); DefaultFactHandle f1 = (DefaultFactHandle) ksession.insert( "test1" ); - n3.assertObject( f1, context, ksession ); + n3.getRightInput().assertObject( f1, context, ksession ); BetaMemory bm = (BetaMemory) ksession.getNodeMemory(n3); assertThat(bm.getSegmentMemory().isSegmentLinked()).isFalse(); - n4.assertObject( f1, context, ksession ); + n4.getRightInput().assertObject( f1, context, ksession ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isFalse(); - n5.assertObject( f1, context, ksession ); + n5.getRightInput().assertObject( f1, context, ksession ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isFalse(); - n6.assertObject( f1, context, ksession ); + n6.getRightInput().assertObject( f1, context, ksession ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isTrue(); // only after all 4 nodes are populated, is the segment linked in } @@ -516,13 +529,13 @@ public void testAllLinkedInWithNotNodesOnly() { assertThat(bm.getSegmentMemory().isSegmentLinked()).isTrue(); // not nodes start off linked DefaultFactHandle f1 = (DefaultFactHandle) ksession.insert( "test1" ); // unlinked after first assertion - n3.assertObject( f1, context, ksession ); + n3.getRightInput().assertObject( f1, context, ksession ); // this doesn't unlink on the assertObject, as the node's memory must be processed. So use the helper method the main network evaluator uses. PhreakNotNode.unlinkNotNodeOnRightInsert( (NotNode) n3, bm, ksession ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isFalse(); - n3.retractRightTuple( f1.getFirstRightTuple(), context, ksession ); + n3.getRightInput().retractRightTuple( f1.getFirstRightTuple(), context, ksession ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isTrue(); //assertFalse( bm.getSegmentMemory().isSigmentLinked() ); // check retraction unlinks again } diff --git a/drools-kiesession/src/test/java/org/drools/kiesession/RuleUnlinkingTest.java b/drools-kiesession/src/test/java/org/drools/kiesession/RuleUnlinkingTest.java index 9fbafbdcdff..81908b156d4 100644 --- a/drools-kiesession/src/test/java/org/drools/kiesession/RuleUnlinkingTest.java +++ b/drools-kiesession/src/test/java/org/drools/kiesession/RuleUnlinkingTest.java @@ -31,6 +31,10 @@ import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.core.phreak.BuildtimeSegmentUtilities; import org.drools.core.reteoo.BetaMemory; +import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.ExistsRight; +import org.drools.core.reteoo.JoinRightAdapterNode; +import org.drools.core.reteoo.NotRight; import org.drools.core.reteoo.PathEndNode; import org.drools.core.reteoo.TerminalNode; import org.drools.kiesession.rulebase.InternalKnowledgeBase; @@ -91,20 +95,23 @@ private NetworkNode createNetworkNode(int id, int type, LeftTupleSource leftTupleSource, RuleImpl rule) { - MockObjectSource mockObjectSource = new MockObjectSource( 8 ); + MockObjectSource mockObjectSource = new MockObjectSource( 8 ); LeftTupleSink networkNode = null; switch ( type ) { case JOIN_NODE : { - networkNode = new JoinNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); + RightInputAdapterNode right = new JoinRightAdapterNode(9, mockObjectSource, buildContext); + networkNode = new JoinNode( id, leftTupleSource, right, new EmptyBetaConstraints(), buildContext ); break; } case EXISTS_NODE : { - networkNode = new ExistsNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); + RightInputAdapterNode right = new ExistsRight(9, mockObjectSource, buildContext); + networkNode = new ExistsNode( id, leftTupleSource, right, new EmptyBetaConstraints(), buildContext ); break; } case NOT_NODE : { - networkNode = new NotNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); + RightInputAdapterNode right = new NotRight(9, mockObjectSource, buildContext); + networkNode = new NotNode( id, leftTupleSource, right, new EmptyBetaConstraints(), buildContext ); break; } case RULE_TERMINAL_NODE : { @@ -159,29 +166,29 @@ public void setUp(int type) { // \ // n6 -> n7 -> n8 -> r3 - liaNode.addAssociation( rule1 ); - liaNode.addAssociation( rule2 ); - liaNode.addAssociation( rule3 ); - - n1.addAssociation( rule1 ); - n1.addAssociation( rule2 ); - n1.addAssociation( rule3 ); - n2.addAssociation( rule1 ); - n2.addAssociation( rule2 ); - n2.addAssociation( rule3 ); - - n3.addAssociation( rule1 ); - n3.addAssociation( rule2 ); - n3.addAssociation( rule3 ); - - n4.addAssociation( rule2 ); - n4.addAssociation( rule3 ); - n5.addAssociation( rule2 ); - n5.addAssociation( rule3 ); - - n6.addAssociation( rule3 ); - n7.addAssociation( rule3 ); - n8.addAssociation( rule3 ); + liaNode.addAssociation(rule1, null); + liaNode.addAssociation(rule2, null); + liaNode.addAssociation(rule3, null); + + n1.addAssociation(rule1, null); + n1.addAssociation(rule2, null); + n1.addAssociation(rule3, null); + n2.addAssociation(rule1, null); + n2.addAssociation(rule2, null); + n2.addAssociation(rule3, null); + + n3.addAssociation(rule1, null); + n3.addAssociation(rule2, null); + n3.addAssociation(rule3, null); + + n4.addAssociation(rule2, null); + n4.addAssociation(rule3, null); + n5.addAssociation(rule2, null); + n5.addAssociation(rule3, null); + + n6.addAssociation(rule3, null); + n7.addAssociation(rule3, null); + n8.addAssociation(rule3, null); // assumes no subnetworks for (TerminalNode tn : new TerminalNode[] {rtn1, rtn2, rtn3}) { @@ -323,10 +330,10 @@ public void testRuleSegmentLinking() { RuntimeSegmentUtilities.getOrCreateSegmentMemory(liaNode, wm); liaNode.assertObject( f1, context, wm ); - n1.assertObject( f1, context, wm ); - n3.assertObject( f1, context, wm ); - n4.assertObject( f1, context, wm ); - n8.assertObject( f1, context, wm ); + n1.getRightInput().assertObject( f1, context, wm ); + n3.getRightInput().assertObject( f1, context, wm ); + n4.getRightInput().assertObject( f1, context, wm ); + n8.getRightInput().assertObject( f1, context, wm ); assertThat(rtn1Rs.isRuleLinked()).isFalse(); assertThat(rtn2Rs.isRuleLinked()).isFalse(); @@ -337,7 +344,7 @@ public void testRuleSegmentLinking() { assertThat(bm.getSegmentMemory().isSegmentLinked()).isFalse(); DefaultFactHandle f2 = (DefaultFactHandle) wm.insert( "test2" ); - n2.assertObject( f2, context, wm ); + n2.getRightInput().assertObject( f2, context, wm ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isTrue(); assertThat(rtn1Rs.isRuleLinked()).isTrue(); @@ -348,7 +355,7 @@ public void testRuleSegmentLinking() { bm = (BetaMemory) wm.getNodeMemory(n5); assertThat(bm.getSegmentMemory().isSegmentLinked()).isFalse(); - n5.assertObject( f1, context, wm ); + n5.getRightInput().assertObject( f1, context, wm ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isTrue(); assertThat(rtn1Rs.isRuleLinked()).isTrue(); @@ -356,8 +363,8 @@ public void testRuleSegmentLinking() { assertThat(rtn3Rs.isRuleLinked()).isFalse(); // Link in Rule3 - n6.assertObject( f1, context, wm ); - n7.assertObject( f1, context, wm ); + n6.getRightInput().assertObject( f1, context, wm ); + n7.getRightInput().assertObject( f1, context, wm ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isTrue(); assertThat(rtn1Rs.isRuleLinked()).isTrue(); @@ -365,7 +372,7 @@ public void testRuleSegmentLinking() { assertThat(rtn3Rs.isRuleLinked()).isTrue(); // retract n2, should unlink all rules - n2.retractRightTuple( f2.getFirstRightTuple(), context, wm ); + n2.getRightInput().retractRightTuple( f2.getFirstRightTuple(), context, wm ); assertThat(rtn1Rs.isRuleLinked()).isFalse(); assertThat(rtn2Rs.isRuleLinked()).isFalse(); assertThat(rtn3Rs.isRuleLinked()).isFalse(); diff --git a/drools-kiesession/src/test/java/org/drools/kiesession/RuleUnlinkingWithSegmentMemoryTest.java b/drools-kiesession/src/test/java/org/drools/kiesession/RuleUnlinkingWithSegmentMemoryTest.java index fcd51e7d00c..07678fe96be 100644 --- a/drools-kiesession/src/test/java/org/drools/kiesession/RuleUnlinkingWithSegmentMemoryTest.java +++ b/drools-kiesession/src/test/java/org/drools/kiesession/RuleUnlinkingWithSegmentMemoryTest.java @@ -33,14 +33,18 @@ import org.drools.core.phreak.BuildtimeSegmentUtilities; import org.drools.core.reteoo.BetaMemory; import org.drools.core.reteoo.BetaNode; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.ExistsNode; +import org.drools.core.reteoo.ExistsRight; import org.drools.core.reteoo.JoinNode; +import org.drools.core.reteoo.JoinRightAdapterNode; import org.drools.core.reteoo.LeftInputAdapterNode; import org.drools.core.reteoo.LeftTupleSink; import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.MockObjectSource; import org.drools.base.reteoo.NodeTypeEnums; import org.drools.core.reteoo.NotNode; +import org.drools.core.reteoo.NotRight; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.PathEndNode; import org.drools.core.reteoo.PathMemory; @@ -97,15 +101,18 @@ private NetworkNode createNetworkNode(int id, LeftTupleSink networkNode = null; switch ( type ) { case JOIN_NODE : { - networkNode = new JoinNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); + RightInputAdapterNode right = new JoinRightAdapterNode(9, mockObjectSource, buildContext); + networkNode = new JoinNode( id, leftTupleSource, right, new EmptyBetaConstraints(), buildContext ); break; } case EXISTS_NODE : { - networkNode = new ExistsNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); + RightInputAdapterNode right = new ExistsRight(9, mockObjectSource, buildContext); + networkNode = new ExistsNode( id, leftTupleSource, right, new EmptyBetaConstraints(), buildContext ); break; } case NOT_NODE : { - networkNode = new NotNode( id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext ); + RightInputAdapterNode right = new NotRight(9, mockObjectSource, buildContext); + networkNode = new NotNode( id, leftTupleSource, right, new EmptyBetaConstraints(), buildContext ); break; } case RULE_TERMINAL_NODE : { @@ -158,27 +165,27 @@ public void setUp(int type) { rule3.setActivationListener( "agenda" ); rtn3 = ( RuleTerminalNode ) createNetworkNode( 20, RULE_TERMINAL_NODE, n8, rule3 ); - lian.addAssociation( rule1 ); - lian.addAssociation( rule2 ); - lian.addAssociation( rule3 ); - n1.addAssociation( rule1 ); - n1.addAssociation( rule2 ); - n1.addAssociation( rule3 ); - n2.addAssociation( rule1 ); - n2.addAssociation( rule2 ); - n2.addAssociation( rule3 ); - n3.addAssociation( rule1 ); - n3.addAssociation( rule2 ); - n3.addAssociation( rule3 ); + lian.addAssociation(rule1, null); + lian.addAssociation(rule2, null); + lian.addAssociation(rule3, null); + n1.addAssociation(rule1, null); + n1.addAssociation(rule2, null); + n1.addAssociation(rule3, null); + n2.addAssociation(rule1, null); + n2.addAssociation(rule2, null); + n2.addAssociation(rule3, null); + n3.addAssociation(rule1, null); + n3.addAssociation(rule2, null); + n3.addAssociation(rule3, null); - n4.addAssociation( rule2 ); - n4.addAssociation( rule3 ); - n5.addAssociation( rule2 ); - n5.addAssociation( rule3 ); + n4.addAssociation(rule2, null); + n4.addAssociation(rule3, null); + n5.addAssociation(rule2, null); + n5.addAssociation(rule3, null); - n6.addAssociation( rule3 ); - n7.addAssociation( rule3 ); - n8.addAssociation( rule3 ); + n6.addAssociation(rule3, null); + n7.addAssociation(rule3, null); + n8.addAssociation(rule3, null); // assumes no subnetworks for (TerminalNode tn : new TerminalNode[] {rtn1, rtn2, rtn3}) { @@ -327,10 +334,10 @@ public void testRuleSegmentLinking() { DefaultFactHandle f1 = (DefaultFactHandle) wm.insert( "test1" ); lian.assertObject( f1, context, wm ); - n1.assertObject( f1, context, wm ); - n3.assertObject( f1, context, wm ); - n4.assertObject( f1, context, wm ); - n8.assertObject( f1, context, wm ); + n1.getRightInput().assertObject( f1, context, wm ); + n3.getRightInput().assertObject( f1, context, wm ); + n4.getRightInput().assertObject( f1, context, wm ); + n8.getRightInput().assertObject( f1, context, wm ); assertThat(rtn1Rs.isRuleLinked()).isFalse(); assertThat(rtn2Rs.isRuleLinked()).isFalse(); @@ -342,7 +349,7 @@ public void testRuleSegmentLinking() { assertThat(bm.getSegmentMemory().isSegmentLinked()).isFalse(); DefaultFactHandle f2 = (DefaultFactHandle) wm.insert( "test2" ); - n2.assertObject( f2, context, wm ); + n2.getRightInput().assertObject( f2, context, wm ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isTrue(); assertThat(rtn1Rs.isRuleLinked()).isTrue(); @@ -353,7 +360,7 @@ public void testRuleSegmentLinking() { bm = (BetaMemory) wm.getNodeMemory(n5); assertThat(bm.getSegmentMemory().isSegmentLinked()).isFalse(); - n5.assertObject( f1, context, wm ); + n5.getRightInput().assertObject( f1, context, wm ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isTrue(); assertThat(rtn1Rs.isRuleLinked()).isTrue(); @@ -361,8 +368,8 @@ public void testRuleSegmentLinking() { assertThat(rtn3Rs.isRuleLinked()).isFalse(); // Link in Rule3 - n6.assertObject( f1, context, wm ); - n7.assertObject( f1, context, wm ); + n6.getRightInput().assertObject( f1, context, wm ); + n7.getRightInput().assertObject( f1, context, wm ); assertThat(bm.getSegmentMemory().isSegmentLinked()).isTrue(); assertThat(rtn1Rs.isRuleLinked()).isTrue(); @@ -370,7 +377,7 @@ public void testRuleSegmentLinking() { assertThat(rtn3Rs.isRuleLinked()).isTrue(); // retract n2, should unlink all rules - n2.retractRightTuple( f2.getFirstRightTuple(), context, wm ); + n2.getRightInput().retractRightTuple( f2.getFirstRightTuple(), context, wm ); assertThat(rtn1Rs.isRuleLinked()).isFalse(); assertThat(rtn2Rs.isRuleLinked()).isFalse(); assertThat(rtn3Rs.isRuleLinked()).isFalse(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IndexTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IndexTest.java index 67b8177bd58..1c2f0f29b63 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IndexTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IndexTest.java @@ -23,6 +23,7 @@ import org.drools.base.base.ClassObjectType; import org.drools.core.reteoo.AlphaNode; import org.drools.core.reteoo.BetaNode; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.CompositeObjectSinkAdapter; import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.ObjectSink; @@ -58,7 +59,7 @@ public void testBetaIndexOnDeclaration() { KieSession ksession = getKieSession( str ); ObjectTypeNode otn = getObjectTypeNodeForClass( ksession, Person.class ); - BetaNode beta = (BetaNode) otn.getObjectSinkPropagator().getSinks()[0]; + BetaNode beta = ((RightInputAdapterNode)otn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); IndexableConstraint betaConstraint = (IndexableConstraint) beta.getConstraints()[0]; assertThat(betaConstraint.getLeftIndexExtractor()).isNotNull(); @@ -222,7 +223,7 @@ public void testBetaIndexOn2ValuesOnLeftTuple() { KieSession ksession = getKieSession( str ); ObjectTypeNode otn = getObjectTypeNodeForClass( ksession, Person.class ); - BetaNode beta = (BetaNode) otn.getObjectSinkPropagator().getSinks()[0]; + BetaNode beta = ((RightInputAdapterNode)otn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); // this beta index is only supported by executable model assertThat(beta.getRawConstraints().isIndexed()).isEqualTo(this.testRunType.isExecutableModel()); @@ -327,7 +328,7 @@ public void testBetaIndexOn3ValuesOnLeftTuple() { KieSession ksession = getKieSession( str ); ObjectTypeNode otn = getObjectTypeNodeForClass( ksession, Person.class ); - BetaNode beta = (BetaNode) otn.getObjectSinkPropagator().getSinks()[0]; + BetaNode beta = ((RightInputAdapterNode)otn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); // this beta index is only supported by executable model assertThat(beta.getRawConstraints().isIndexed()).isEqualTo(this.testRunType.isExecutableModel()); @@ -356,7 +357,7 @@ public void testBetaIndexOn4ValuesOnLeftTuple() { KieSession ksession = getKieSession( str ); ObjectTypeNode otn = getObjectTypeNodeForClass( ksession, Person.class ); - BetaNode beta = (BetaNode) otn.getObjectSinkPropagator().getSinks()[0]; + BetaNode beta = ((RightInputAdapterNode)otn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); // this beta index is only supported by executable model assertThat(beta.getRawConstraints().isIndexed()).isEqualTo(this.testRunType.isExecutableModel()); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityTest.java index 66b9b8549c4..6de087c7858 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityTest.java @@ -322,7 +322,7 @@ public void testImmutableField() { } - @Test(timeout = 5000L) + @Test //(timeout = 5000L) public void testPRAfterAccumulate() { // DROOLS-2427 final String str = diff --git a/drools-mvel/src/test/java/org/drools/mvel/compiler/rule/builder/dialect/mvel/MVELConsequenceBuilderTest.java b/drools-mvel/src/test/java/org/drools/mvel/compiler/rule/builder/dialect/mvel/MVELConsequenceBuilderTest.java index 6e63fa9aac5..c0c8abf5822 100644 --- a/drools-mvel/src/test/java/org/drools/mvel/compiler/rule/builder/dialect/mvel/MVELConsequenceBuilderTest.java +++ b/drools-mvel/src/test/java/org/drools/mvel/compiler/rule/builder/dialect/mvel/MVELConsequenceBuilderTest.java @@ -26,42 +26,29 @@ import java.util.Map.Entry; import java.util.Properties; -import org.drools.base.base.ValueResolver; import org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl; import org.drools.compiler.builder.impl.KnowledgeBuilderImpl; import org.drools.compiler.compiler.Dialect; import org.drools.compiler.compiler.DialectCompiletimeRegistry; +import org.drools.core.impl.KnowledgeBaseImpl; import org.drools.core.reteoo.MockLeftTupleSink; import org.drools.core.reteoo.RuleTerminalNodeLeftTuple; import org.drools.core.reteoo.TupleFactory; -import org.drools.core.reteoo.TupleImpl; import org.drools.drl.parser.DrlParser; import org.drools.drl.parser.DroolsParserException; import org.drools.compiler.compiler.PackageRegistry; import org.drools.compiler.rule.builder.RuleBuildContext; import org.drools.compiler.rule.builder.RuleBuilder; -import org.drools.core.RuleBaseConfiguration; import org.drools.base.base.ClassObjectType; -import org.drools.core.common.EmptyBetaConstraints; import org.drools.core.common.InternalFactHandle; -import org.drools.core.common.Memory; import org.drools.core.common.PropagationContextFactory; -import org.drools.core.common.ReteEvaluator; import org.drools.base.definitions.InternalKnowledgePackage; import org.drools.base.definitions.rule.impl.RuleImpl; -import org.drools.core.reteoo.BetaNode; import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.reteoo.LeftTuple; -import org.drools.core.reteoo.LeftTuple; -import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.MockTupleSource; -import org.drools.core.reteoo.ModifyPreviousTuples; -import org.drools.core.reteoo.ObjectSource; -import org.drools.core.reteoo.ReteooBuilder; -import org.drools.core.reteoo.RuleRemovalContext; import org.drools.core.reteoo.RuleTerminalNode; import org.drools.core.reteoo.RuntimeComponentFactory; -import org.drools.core.reteoo.Sink; import org.drools.core.reteoo.builder.BuildContext; import org.drools.base.rule.Declaration; import org.drools.base.rule.GroupElement; @@ -214,8 +201,9 @@ public void testImperativeCodeError() throws Exception { final Cheese cheddar = new Cheese( "cheddar", 10 ); final InternalFactHandle f0 = (InternalFactHandle) ksession.insert( cheddar ); + BuildContext bctx = new BuildContext(new KnowledgeBaseImpl("id0"), Collections.emptyList()); final LeftTuple tuple = new LeftTuple( f0, - new MockLeftTupleSink(0), + new MockLeftTupleSink(0, bctx), true ); RuleTerminalNode rtn = new RuleTerminalNode(); @@ -452,65 +440,4 @@ public void testDefaultConsequenceWithMultipleNamedConsequenceCompilation() { assertThat(context.getRule().getNamedConsequence("name2")).isNotSameAs(context.getRule().getConsequence()); assertThat(context.getRule().getNamedConsequence("name2")).isNotSameAs(context.getRule().getNamedConsequence( "name1")); } - - public static class MockBetaNode extends BetaNode { - - public MockBetaNode() { - - } - - @Override - protected boolean doRemove( RuleRemovalContext context, ReteooBuilder builder) { - return true; - } - - MockBetaNode(final int id, - final LeftTupleSource leftInput, - final ObjectSource rightInput, - BuildContext buildContext) { - super( id, - leftInput, - rightInput, - EmptyBetaConstraints.getInstance(), - buildContext ); - } - - MockBetaNode(final int id, - final LeftTupleSource leftInput, - final ObjectSource rightInput) { - super( id, - leftInput, - rightInput, - EmptyBetaConstraints.getInstance(), - null ); - } - - public void assertObject(final InternalFactHandle factHandle, - final PropagationContext pctx, - final ValueResolver valueResolver) { - } - - @Override - public void modifyObject( InternalFactHandle factHandle, ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, ReteEvaluator reteEvaluator) { - } - - public void retractRightTuple(final TupleImpl rightTuple, - final PropagationContext context, - final ReteEvaluator reteEvaluator) { - } - - public int getType() { - return 0; - } - - public void modifyRightTuple(TupleImpl rightTuple, - PropagationContext context, - ReteEvaluator reteEvaluator) { - } - - public Memory createMemory(RuleBaseConfiguration config, ReteEvaluator reteEvaluator) { - return super.createMemory( config, reteEvaluator); - } - - } } diff --git a/drools-retediagram/src/main/java/org/drools/retediagram/ReteDiagram.java b/drools-retediagram/src/main/java/org/drools/retediagram/ReteDiagram.java index 105723ce0ce..6b69f3a248e 100644 --- a/drools-retediagram/src/main/java/org/drools/retediagram/ReteDiagram.java +++ b/drools-retediagram/src/main/java/org/drools/retediagram/ReteDiagram.java @@ -53,7 +53,7 @@ import org.drools.core.reteoo.ObjectSource; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.Rete; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.RuleTerminalNode; import org.drools.core.reteoo.Sink; import org.drools.base.rule.constraint.BetaConstraint; @@ -245,7 +245,7 @@ private static void printNodeMap(HashMap, ListLeftInputAdapterNode.class.isAssignableFrom( kv.getKey() )) .flatMap(kv->kv.getValue().stream()).collect(toList()); printNodeMapNodes(l3, out); - printNodeMapNodes(nodeMap.getOrDefault(RightInputAdapterNode.class, Collections.emptyList()), out); + printNodeMapNodes(nodeMap.getOrDefault(TupleToObjectNode.class, Collections.emptyList()), out); // Level 4: BN List l4 = nodeMap.entrySet().stream() .filter(kv->BetaNode.class.isAssignableFrom( kv.getKey() )) @@ -304,7 +304,7 @@ private void printLevelMap(HashMap, Set> lev // RIA Set lria = levelMap.entrySet().stream() - .filter(kv->RightInputAdapterNode.class.isAssignableFrom( kv.getKey() )) + .filter(kv-> TupleToObjectNode.class.isAssignableFrom(kv.getKey())) .flatMap(kv->kv.getValue().stream()).collect(toSet()); printLevelMapLevel("lria", lria, out); @@ -425,7 +425,7 @@ private static String printNodeId(BaseNode node) { return "AN"+node.getId(); } else if (node instanceof LeftInputAdapterNode ) { return "LIA"+node.getId(); - } else if (node instanceof RightInputAdapterNode ) { + } else if (node instanceof TupleToObjectNode) { return "RIA"+node.getId(); } else if (node instanceof BetaNode ) { return "BN"+node.getId(); @@ -450,7 +450,7 @@ private static String printNodeAttributes(BaseNode node) { escapeDot(n.getConstraint().toString())); } else if (node instanceof LeftInputAdapterNode ) { return "[shape=house orientation=-90]"; - } else if (node instanceof RightInputAdapterNode ) { + } else if (node instanceof TupleToObjectNode) { return "[shape=house orientation=90]"; } else if (node instanceof JoinNode ) { BetaNode n = (BetaNode) node; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/LeftTupleIterator.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/LeftTupleIterator.java index e94d74455e7..e865089074c 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/LeftTupleIterator.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/LeftTupleIterator.java @@ -18,6 +18,7 @@ */ package org.drools.serialization.protobuf.iterators; +import org.drools.core.common.BaseNode; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.InternalWorkingMemory; import org.drools.core.common.MemoryFactory; @@ -149,9 +150,9 @@ public TupleImpl getFirstLeftTuple(LeftTupleSource source, } case NodeTypeEnums.LeftInputAdapterNode: case NodeTypeEnums.AlphaTerminalNode: { - ObjectSource os = ((LeftInputAdapterNode) source).getParentObjectSource(); + BaseNode os = ((LeftInputAdapterNode) source).getParentObjectSource(); while ( !(os instanceof ObjectTypeNode) ) { - os = os.getParentObjectSource(); + os = os.getParent(); } ObjectTypeNode otn = (ObjectTypeNode) os; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/PhreakActivationIterator.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/PhreakActivationIterator.java index 8af734daaa9..198207dabd6 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/PhreakActivationIterator.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/PhreakActivationIterator.java @@ -22,6 +22,10 @@ import java.util.List; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.core.common.BaseNode; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.common.InternalWorkingMemory; +import org.drools.core.common.Memory; import org.drools.core.common.ReteEvaluator; import org.drools.core.impl.InternalRuleBase; import org.drools.core.phreak.RuleExecutor; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/marshalling/RuleBaseNodes.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/marshalling/RuleBaseNodes.java index bd72d40cc49..7a95425b102 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/marshalling/RuleBaseNodes.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/marshalling/RuleBaseNodes.java @@ -23,6 +23,7 @@ import org.drools.core.common.BaseNode; import org.drools.core.impl.InternalRuleBase; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.LeftTupleSink; import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.ObjectSink; @@ -61,6 +62,10 @@ private static void addObjectSink(InternalRuleBase kBase, leftTupleSink, nodes); } + } else if ( sink instanceof RightInputAdapterNode) { + RightInputAdapterNode node = (RightInputAdapterNode) sink; + nodes.put( sink.getId(), ((BaseNode)sink) ); + addLeftTupleSink(kBase, node.getBetaNode(), nodes); } else if ( sink instanceof WindowNode ) { WindowNode node = (WindowNode) sink; nodes.put( sink.getId(), ((BaseNode)sink) ); diff --git a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallingTest.java b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallingTest.java index 3258b90b1f8..04f5f61d405 100644 --- a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallingTest.java +++ b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallingTest.java @@ -54,6 +54,8 @@ import org.drools.core.impl.RuleBaseFactory; import org.drools.core.marshalling.ClassObjectMarshallingStrategyAcceptor; import org.drools.core.reteoo.CoreComponentFactory; +import org.drools.core.reteoo.JoinNode; +import org.drools.core.reteoo.JoinRightAdapterNode; import org.drools.core.reteoo.MockTupleSource; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.RuleTerminalNode; @@ -1057,11 +1059,12 @@ public void testSingleRuleSingleJoinNodePattern() throws Exception { // Make sure the rete node map is created correctly Map nodes = RuleBaseNodes.getNodeMap( (InternalKnowledgeBase) kBase); - assertThat(nodes.size()).isEqualTo(5); + assertThat(nodes.size()).isEqualTo(6); assertThat(((ClassObjectType) ((ObjectTypeNode) nodes.get(3)).getObjectType()).getClassType().getSimpleName()).isEqualTo("Cheese"); assertThat(((ClassObjectType) ((ObjectTypeNode) nodes.get(5)).getObjectType()).getClassType().getSimpleName()).isEqualTo("Person"); - assertThat(nodes.get(6).getClass().getSimpleName().endsWith("JoinNode")).as("Should end with JoinNode").isTrue(); - assertThat(((RuleTerminalNode) nodes.get(7)).getRule().getName()).isEqualTo("Rule 1"); + assertThat(nodes.get(6).getClass() == JoinRightAdapterNode.class).as("Should end with JoinNode").isTrue(); + assertThat(nodes.get(7).getClass() == JoinNode.class).as("Should end with JoinNode").isTrue(); + assertThat(((RuleTerminalNode) nodes.get(8)).getRule().getName()).isEqualTo("Rule 1"); KieSession session = kBase.newKieSession(); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/AccumulateMvelDialectTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/AccumulateMvelDialectTest.java index 654e28c72c0..8ba6cceb00e 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/AccumulateMvelDialectTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/AccumulateMvelDialectTest.java @@ -25,11 +25,11 @@ import java.util.List; import java.util.Map; -import org.drools.core.reteoo.JoinNode; +import org.drools.core.reteoo.JoinRightAdapterNode; import org.drools.core.reteoo.LeftTupleSink; import org.drools.core.reteoo.ObjectSink; import org.drools.core.reteoo.ObjectTypeNode; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.testcoverage.common.model.Cheese; import org.drools.testcoverage.common.model.Person; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; @@ -310,11 +310,11 @@ public void testAccumulateWithSameSubnetwork() { final ObjectSink[] oSinks = cheeseOtn.getObjectSinkPropagator().getSinks(); assertThat(oSinks.length).isEqualTo(1); - final JoinNode cheeseJoin = (JoinNode) oSinks[0]; - final LeftTupleSink[] ltSinks = cheeseJoin.getSinkPropagator().getSinks(); + final JoinRightAdapterNode cheeseJoin = (JoinRightAdapterNode ) oSinks[0]; + final LeftTupleSink[] ltSinks = cheeseJoin.getBetaNode().getSinkPropagator().getSinks(); assertThat(ltSinks.length).isEqualTo(1); - final RightInputAdapterNode rian = (RightInputAdapterNode) ltSinks[0]; + final TupleToObjectNode rian = (TupleToObjectNode) ltSinks[0]; assertThat(rian.getObjectSinkPropagator().size()).isEqualTo(2); // RiaNode is shared, if this has two outputs wm.insert(new Cheese("stilton", 10)); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/AlphaNetworkModifyTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/AlphaNetworkModifyTest.java index 95779125b12..9842319802e 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/AlphaNetworkModifyTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/AlphaNetworkModifyTest.java @@ -169,8 +169,8 @@ public void testModifyWithLiaToFrom() { final LeftTupleSink[] sinks = liaNode.getSinkPropagator().getSinks(); assertThat(sinks.length).isEqualTo(2); - assertThat(sinks[0].getLeftInputOtnId().getId()).isEqualTo(0); - assertThat(sinks[1].getLeftInputOtnId().getId()).isEqualTo(1); + assertThat(sinks[0].getInputOtnId().getId()).isEqualTo(0); + assertThat(sinks[1].getInputOtnId().getId()).isEqualTo(1); } finally { wm.dispose(); } @@ -224,9 +224,9 @@ public void testModifyWithLiaToAcc() { final LeftTupleSink[] sinks = liaNode.getSinkPropagator().getSinks(); - assertThat(sinks[0].getLeftInputOtnId().getId()).isEqualTo(0); - assertThat(sinks[1].getLeftInputOtnId().getId()).isEqualTo(1); - assertThat(sinks[2].getLeftInputOtnId().getId()).isEqualTo(2); + assertThat(sinks[0].getInputOtnId().getId()).isEqualTo(0); + assertThat(sinks[1].getInputOtnId().getId()).isEqualTo(1); + assertThat(sinks[2].getInputOtnId().getId()).isEqualTo(2); final ObjectTypeNode otnPerson = getObjectTypeNode(kbase, "Person" ); final ObjectTypeNode otnCheese = getObjectTypeNode(kbase, "Cheese" ); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/BackwardChainingTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/BackwardChainingTest.java index a0fd4c1212f..6fb0ac8ad92 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/BackwardChainingTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/BackwardChainingTest.java @@ -37,14 +37,18 @@ import org.drools.core.common.InternalWorkingMemory; import org.drools.core.impl.InternalRuleBase; import org.drools.core.reteoo.AccumulateNode; +import org.drools.core.reteoo.AccumulateRight; import org.drools.core.reteoo.BetaMemory; import org.drools.core.reteoo.BetaNode; import org.drools.core.reteoo.ExistsNode; +import org.drools.core.reteoo.ExistsRight; import org.drools.core.reteoo.FromNode; +import org.drools.core.reteoo.JoinRightAdapterNode; import org.drools.core.reteoo.NotNode; +import org.drools.core.reteoo.NotRight; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.QueryElementNode; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.drools.testcoverage.common.model.Address; @@ -2232,19 +2236,19 @@ public void testSubNetworksAndQueries() { } assertThat(node).isNotNull(); - final BetaNode stringBetaNode = (BetaNode) node.getObjectSinkPropagator().getSinks()[0]; - final QueryElementNode queryElementNode1 = (QueryElementNode) stringBetaNode.getSinkPropagator().getSinks()[0]; - final RightInputAdapterNode riaNode1 = (RightInputAdapterNode) queryElementNode1.getSinkPropagator().getSinks()[0]; - final AccumulateNode accNode = (AccumulateNode) riaNode1.getObjectSinkPropagator().getSinks()[0]; + final BetaNode stringBetaNode = ((JoinRightAdapterNode) node.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + final QueryElementNode queryElementNode1 = (QueryElementNode) stringBetaNode.getSinkPropagator().getSinks()[0]; + final TupleToObjectNode riaNode1 = (TupleToObjectNode) queryElementNode1.getSinkPropagator().getSinks()[0]; + final AccumulateNode accNode =((AccumulateRight) riaNode1.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); - final QueryElementNode queryElementNode2 = (QueryElementNode) accNode.getSinkPropagator().getSinks()[0]; - final RightInputAdapterNode riaNode2 = (RightInputAdapterNode) queryElementNode2.getSinkPropagator().getSinks()[0]; - final ExistsNode existsNode = (ExistsNode) riaNode2.getObjectSinkPropagator().getSinks()[0]; + final QueryElementNode queryElementNode2 = (QueryElementNode) accNode.getSinkPropagator().getSinks()[0]; + final TupleToObjectNode riaNode2 = (TupleToObjectNode) queryElementNode2.getSinkPropagator().getSinks()[0]; + final ExistsNode existsNode = ((ExistsRight)riaNode2.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); final QueryElementNode queryElementNode3 = (QueryElementNode) existsNode.getSinkPropagator().getSinks()[0]; - final FromNode fromNode = (FromNode) queryElementNode3.getSinkPropagator().getSinks()[0]; - final RightInputAdapterNode riaNode3 = (RightInputAdapterNode) fromNode.getSinkPropagator().getSinks()[0]; - final NotNode notNode = (NotNode) riaNode3.getObjectSinkPropagator().getSinks()[0]; + final FromNode fromNode = (FromNode) queryElementNode3.getSinkPropagator().getSinks()[0]; + final TupleToObjectNode riaNode3 = (TupleToObjectNode) fromNode.getSinkPropagator().getSinks()[0]; + final NotNode notNode = ((NotRight)riaNode3.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); final KieSession ksession = kbase.newKieSession(); try { diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CepEspTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CepEspTest.java index 9e5795baf7c..f96856f19da 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CepEspTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/CepEspTest.java @@ -5728,13 +5728,14 @@ public void testCollectExpiredEvent() { SessionPseudoClock clock = ksession.getSessionClock(); - ksession.insert(1); + FactHandle fh1 = ksession.insert(1); clock.advanceTime(2, TimeUnit.HOURS); - ksession.insert(2L); + FactHandle fh2 = ksession.insert(2L); assertThat(ksession.fireAllRules()).isEqualTo(0); clock.advanceTime(2, TimeUnit.HOURS); // Should expire first event - ksession.insert(1L); + + FactHandle fh3 = ksession.insert(1L); assertThat(ksession.fireAllRules()).isEqualTo(0); } finally { diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/JoinNodeRangeIndexingTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/JoinNodeRangeIndexingTest.java index d1616208a80..fba7c68d7a1 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/JoinNodeRangeIndexingTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/JoinNodeRangeIndexingTest.java @@ -30,6 +30,7 @@ import org.drools.ancompiler.CompiledNetwork; import org.drools.core.common.BetaConstraints; import org.drools.core.reteoo.JoinNode; +import org.drools.core.reteoo.JoinRightAdapterNode; import org.drools.core.reteoo.ObjectSink; import org.drools.core.reteoo.ObjectSinkPropagator; import org.drools.core.reteoo.ObjectTypeNode; @@ -118,8 +119,8 @@ private void assertIndexed(KieBase kbase, Class factClass, boolean isIndexed) boolean isPassedForJoinNode = false; ObjectSink[] sinks = objectSinkPropagator.getSinks(); for (ObjectSink sink : sinks) { - if (sink instanceof JoinNode) { - JoinNode join = (JoinNode) sink; + if (sink instanceof JoinRightAdapterNode) { + JoinNode join = ((JoinRightAdapterNode) sink).getBetaNode(); BetaConstraints betaConstraints = join.getRawConstraints(); assertThat(betaConstraints.isIndexed()).isEqualTo(isIndexed); isPassedForJoinNode = true; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/NegativePatternsTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/NegativePatternsTest.java index 6aa38d2258a..f0eb0928d24 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/NegativePatternsTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/NegativePatternsTest.java @@ -51,7 +51,7 @@ @RunWith(Parameterized.class) public class NegativePatternsTest { - private static final int LOOPS = 300; + private static final int LOOPS = 2; private static final int SHORT_SLEEP_TIME = 20; private static final int LONG_SLEEP_TIME = 30; @@ -217,12 +217,15 @@ public void testMultipleEvents() { final FactHandle handle = entryPoint.insert(new TestEvent(-1, "EventB")); advanceTime(SHORT_SLEEP_TIME); ksession.fireAllRules(); + assertThat(firedRulesListener.ruleFiredCount("MultipleEvents")).isEqualTo(count); entryPoint.delete(handle); ksession.fireAllRules(); + assertThat(firedRulesListener.ruleFiredCount("MultipleEvents")).isEqualTo(count); // it shouldn't fire because of the duration advanceTime(SHORT_SLEEP_TIME); ksession.fireAllRules(); + assertThat(firedRulesListener.ruleFiredCount("MultipleEvents")).isEqualTo(count); // it shouldn't fire because event A is gone out of window while (count < LOOPS) { diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/operators/NotTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/operators/NotTest.java index 6416b6e48c8..1a49e8738d5 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/operators/NotTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/operators/NotTest.java @@ -29,6 +29,7 @@ import org.drools.core.impl.InternalRuleBase; import org.drools.core.reteoo.BetaMemory; import org.drools.core.reteoo.BetaNode; +import org.drools.core.reteoo.NotRight; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.RightTuple; import org.drools.core.reteoo.TupleImpl; @@ -207,7 +208,7 @@ public void testMissingRootBlockerEquality() { private InternalFactHandle getBlockerFactHandle(KieSession ksession) { ObjectTypeNode otn = getObjectTypeNode(ksession.getKieBase(), Person.class); - BetaNode notNode = (BetaNode) otn.getSinks()[0].getSinks()[0]; + BetaNode notNode = ((NotRight)otn.getSinks()[0].getSinks()[0]).getBetaNode(); StatefulKnowledgeSessionImpl ksessionImpl = (StatefulKnowledgeSessionImpl) ksession; NodeMemories nodeMemories = ksessionImpl.getNodeMemories(); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/CompositeObjectSinkAdapterTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/CompositeObjectSinkAdapterTest.java index afd7692759a..11955fa27f3 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/CompositeObjectSinkAdapterTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/CompositeObjectSinkAdapterTest.java @@ -27,9 +27,11 @@ import org.drools.core.base.ClassFieldAccessorCache; import org.drools.core.common.InternalFactHandle; import org.drools.core.reteoo.AlphaNode; -import org.drools.core.reteoo.BetaNode; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.CompositeObjectSinkAdapter; import org.drools.core.reteoo.CompositeObjectSinkAdapter.HashKey; +import org.drools.core.reteoo.JoinRightAdapterNode; +import org.drools.core.reteoo.MockObjectSink; import org.drools.core.reteoo.ObjectSink; import org.drools.core.reteoo.ReteooFactHandleFactory; import org.drools.core.reteoo.builder.BuildContext; @@ -94,8 +96,8 @@ public void setUp() throws Exception { @Test public void testAddBeta() { - final MockBetaNode beta = createBetaNode(); - + RightInputAdapterNode beta = new JoinRightAdapterNode(0, new MockObjectSink(), buildContext); + ad.addObjectSink( beta ); sinksAre(beta); @@ -107,7 +109,7 @@ public void testAddBeta() { @Test public void testAddBetaRemoveBeta() { - final MockBetaNode beta = createBetaNode(); + RightInputAdapterNode beta = new JoinRightAdapterNode(0, new MockObjectSink(), buildContext); ad.addObjectSink( beta ); ad.removeObjectSink( beta ); @@ -183,7 +185,7 @@ public void testAddTwoAlphasAddOneBeta() { ad.addObjectSink( al ); final AlphaNode al2 = createAlphaNode(cheeseTypeEqualsTo("cheddar")); ad.addObjectSink( al2 ); - final BetaNode beta = createBetaNode(); + RightInputAdapterNode beta = new JoinRightAdapterNode(0, new MockObjectSink(), buildContext); ad.addObjectSink( beta ); @@ -198,7 +200,8 @@ public void testAddTwoAlphasAddOneBetaRemoveOneBeta() { ad.addObjectSink( al ); final AlphaNode al2 = createAlphaNode(cheeseTypeEqualsTo("cheddar")); ad.addObjectSink( al2 ); - final BetaNode beta = createBetaNode(); + RightInputAdapterNode beta = new JoinRightAdapterNode(0, new MockObjectSink(), buildContext); + ad.addObjectSink( beta ); ad.removeObjectSink( beta ); @@ -475,7 +478,7 @@ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundExcept private MockBetaNode createBetaNode() { return new MockBetaNode( buildContext.getNextNodeId(), new MockBetaNode( ), - new MockObjectSource(), + new JoinRightAdapterNode(0, new MockObjectSink(), buildContext), buildContext ); } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/LeftTupleIndexHashTableIteratorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/LeftTupleIndexHashTableIteratorTest.java index cb4d2bbdc9f..73ed977990e 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/LeftTupleIndexHashTableIteratorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/LeftTupleIndexHashTableIteratorTest.java @@ -19,12 +19,14 @@ package org.drools.mvel; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.drools.core.RuleBaseConfiguration; import org.drools.core.common.BetaConstraints; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.SingleBetaConstraints; +import org.drools.core.impl.KnowledgeBaseImpl; import org.drools.core.impl.RuleBaseFactory; import org.drools.core.reteoo.BetaMemory; import org.drools.core.reteoo.LeftTuple; @@ -32,6 +34,7 @@ import org.drools.base.rule.constraint.BetaConstraint; import org.drools.core.reteoo.MockLeftTupleSink; import org.drools.core.reteoo.TupleImpl; +import org.drools.core.reteoo.builder.BuildContext; import org.drools.core.util.FastIterator; import org.drools.core.util.index.TupleIndexHashTable; import org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator; @@ -81,25 +84,28 @@ public void test1() { InternalFactHandle fh12 = (InternalFactHandle) ss.insert(new Foo("snicker", 0)); InternalFactHandle fh13 = (InternalFactHandle) ss.insert(new Foo("snicker", 0)); - betaMemory.getLeftTupleMemory().add(new LeftTuple(fh1, new MockLeftTupleSink(0), true)); - betaMemory.getLeftTupleMemory().add(new LeftTuple(fh2, new MockLeftTupleSink(0), true)); - betaMemory.getLeftTupleMemory().add(new LeftTuple(fh3, new MockLeftTupleSink(0), true)); - betaMemory.getLeftTupleMemory().add(new LeftTuple(fh4, new MockLeftTupleSink(0), true)); - betaMemory.getLeftTupleMemory().add(new LeftTuple(fh5, new MockLeftTupleSink(0), true)); - betaMemory.getLeftTupleMemory().add(new LeftTuple(fh6, new MockLeftTupleSink(0), true)); - betaMemory.getLeftTupleMemory().add(new LeftTuple(fh7, new MockLeftTupleSink(0), true)); - betaMemory.getLeftTupleMemory().add(new LeftTuple(fh8, new MockLeftTupleSink(0), true)); - betaMemory.getLeftTupleMemory().add(new LeftTuple(fh9, new MockLeftTupleSink(0), true)); + BuildContext bctx = new BuildContext(new KnowledgeBaseImpl("01"), Collections.emptyList()); + MockLeftTupleSink sink = new MockLeftTupleSink(0, bctx); + + betaMemory.getLeftTupleMemory().add(new LeftTuple(fh1, sink, true)); + betaMemory.getLeftTupleMemory().add(new LeftTuple(fh2, sink, true)); + betaMemory.getLeftTupleMemory().add(new LeftTuple(fh3, sink, true)); + betaMemory.getLeftTupleMemory().add(new LeftTuple(fh4, sink, true)); + betaMemory.getLeftTupleMemory().add(new LeftTuple(fh5, sink, true)); + betaMemory.getLeftTupleMemory().add(new LeftTuple(fh6, sink, true)); + betaMemory.getLeftTupleMemory().add(new LeftTuple(fh7, sink, true)); + betaMemory.getLeftTupleMemory().add(new LeftTuple(fh8, sink, true)); + betaMemory.getLeftTupleMemory().add(new LeftTuple(fh9, sink, true)); TupleIndexHashTable hashTable = (TupleIndexHashTable) betaMemory.getLeftTupleMemory(); // can't create a 0 hashCode, so forcing TupleList leftTupleList = new TupleList(); - leftTupleList.add(new LeftTuple(fh10, new MockLeftTupleSink(0), true)); + leftTupleList.add(new LeftTuple(fh10, sink, true)); hashTable.getTable()[0] = leftTupleList; leftTupleList = new TupleList(); - leftTupleList.add(new LeftTuple(fh11, new MockLeftTupleSink(0), true)); - leftTupleList.add(new LeftTuple(fh12, new MockLeftTupleSink(0), true)); - leftTupleList.add(new LeftTuple(fh13, new MockLeftTupleSink(0), true)); + leftTupleList.add(new LeftTuple(fh11, sink, true)); + leftTupleList.add(new LeftTuple(fh12, sink, true)); + leftTupleList.add(new LeftTuple(fh13, sink, true)); hashTable.getTable()[0].setNext(leftTupleList); List tableIndexList = createTableIndexListForAssertion(hashTable); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/MockBetaNode.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/MockBetaNode.java index 5bdf8ac4f74..b2e04fee79d 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/MockBetaNode.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/MockBetaNode.java @@ -24,15 +24,8 @@ import org.drools.core.common.Memory; import org.drools.core.common.ReteEvaluator; import org.drools.core.reteoo.BetaNode; -import org.drools.core.reteoo.LeftTuple; -import org.drools.core.reteoo.LeftTuple; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.LeftTupleSource; -import org.drools.core.reteoo.ModifyPreviousTuples; -import org.drools.core.reteoo.ObjectSource; -import org.drools.core.reteoo.ReteooBuilder; -import org.drools.core.reteoo.RuleRemovalContext; -import org.drools.core.reteoo.Sink; -import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.builder.BuildContext; import org.drools.core.common.PropagationContext; @@ -42,14 +35,9 @@ public MockBetaNode() { } - @Override - protected boolean doRemove( RuleRemovalContext context, ReteooBuilder builder) { - return true; - } - MockBetaNode(final int id, final LeftTupleSource leftInput, - final ObjectSource rightInput, + final RightInputAdapterNode rightInput, BuildContext buildContext) { super( id, leftInput, @@ -60,7 +48,7 @@ protected boolean doRemove( RuleRemovalContext context, ReteooBuilder builder) { MockBetaNode(final int id, final LeftTupleSource leftInput, - final ObjectSource rightInput) { + final RightInputAdapterNode rightInput) { super( id, leftInput, rightInput, @@ -73,24 +61,11 @@ public void assertObject(final InternalFactHandle factHandle, final ReteEvaluator reteEvaluator) { } - @Override - public void modifyObject( InternalFactHandle factHandle, ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, ReteEvaluator reteEvaluator) { - } - - public void retractRightTuple(final TupleImpl rightTuple, - final PropagationContext context, - final ReteEvaluator reteEvaluator) { - } public int getType() { return 0; } - public void modifyRightTuple(TupleImpl rightTuple, - PropagationContext context, - ReteEvaluator reteEvaluator) { - } - public Memory createMemory(RuleBaseConfiguration config, ReteEvaluator reteEvaluator) { return super.createMemory( config, reteEvaluator); } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/MemoryLeakTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/MemoryLeakTest.java index ecee4e74f76..22766f07f65 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/MemoryLeakTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/MemoryLeakTest.java @@ -37,6 +37,7 @@ import org.drools.core.reteoo.AlphaNode; import org.drools.core.reteoo.BetaMemory; import org.drools.core.reteoo.JoinNode; +import org.drools.core.reteoo.JoinRightAdapterNode; import org.drools.core.reteoo.LeftInputAdapterNode; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.Rete; @@ -112,7 +113,7 @@ public void testStagedTupleLeak() throws Exception { JoinNode joinNode = null; for ( ObjectTypeNode otn : rete.getObjectTypeNodes() ) { if ( String.class == otn.getObjectType().getValueType().getClassType() ) { - joinNode = (JoinNode) otn.getObjectSinkPropagator().getSinks()[0]; + joinNode = ((JoinRightAdapterNode)otn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); break; } } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/util/debug/SessionInspectorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/util/debug/SessionInspectorTest.java index c76b87225f9..569ce9042c4 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/util/debug/SessionInspectorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/util/debug/SessionInspectorTest.java @@ -103,15 +103,15 @@ public void testGetSessionInfo() { ksession.insert( new Cheese( "Stilton", 10 ) ); ksession.insert( new Cheese( "Stilton", 10 ) ); ksession.insert( new Cheese( "Stilton", 10 ) ); - ksession.insert( new Double( 10 ) ); - ksession.insert( new Double( 11 ) ); - ksession.insert( new Double( 12 ) ); - ksession.insert( new Double( 13 ) ); - ksession.insert( new Double( 14 ) ); - ksession.insert( new Integer( 15 ) ); - ksession.insert( new Integer( 16 ) ); - ksession.insert( new Integer( 17 ) ); - ksession.insert( new Integer( 18 ) ); + ksession.insert( Double.valueOf( 10 ) ); + ksession.insert( Double.valueOf(( 11 ) ) ); + ksession.insert( Double.valueOf(( 12 ) ) ); + ksession.insert( Double.valueOf(( 13 ) ) ); + ksession.insert( Double.valueOf(( 14 ) ) ); + ksession.insert( Integer.valueOf(( 15 ) ) ); + ksession.insert( Integer.valueOf(( 16 ) ) ); + ksession.insert( Integer.valueOf(( 17 ) ) ); + ksession.insert( Integer.valueOf(( 18 ) ) ); FactHandle handle = ksession.insert( new Worker( ) ); ksession.retract( handle ); @@ -177,15 +177,15 @@ public void testGetSessionInfoWithCustomTemplate() { ksession.insert( new Cheese( "Stilton", 10 ) ); ksession.insert( new Cheese( "Stilton", 10 ) ); ksession.insert( new Cheese( "Stilton", 10 ) ); - ksession.insert( new Double( 10 ) ); - ksession.insert( new Double( 11 ) ); - ksession.insert( new Double( 12 ) ); - ksession.insert( new Double( 13 ) ); - ksession.insert( new Double( 14 ) ); - ksession.insert( new Integer( 15 ) ); - ksession.insert( new Integer( 16 ) ); - ksession.insert( new Integer( 17 ) ); - ksession.insert( new Integer( 18 ) ); + ksession.insert( Double.valueOf(( 10 ) ) ); + ksession.insert( Double.valueOf(( 11 ) ) ); + ksession.insert( Double.valueOf(( 12 ) ) ); + ksession.insert( Double.valueOf(( 13 ) ) ); + ksession.insert( Double.valueOf(( 14 ) ) ); + ksession.insert( Integer.valueOf(( 15 ) ) ); + ksession.insert( Integer.valueOf(( 16 ) ) ); + ksession.insert( Integer.valueOf(( 17 ) ) ); + ksession.insert( Integer.valueOf(( 18 ) ) ); FactHandle handle = ksession.insert( new Worker( ) ); ksession.retract( handle ); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/LinkingTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/LinkingTest.java index 8630aaffed3..10a5598bd76 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/LinkingTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/LinkingTest.java @@ -29,7 +29,8 @@ import org.drools.core.common.MemoryFactory; import org.drools.core.impl.InternalRuleBase; import org.drools.core.reteoo.BetaMemory; -import org.drools.core.reteoo.RightInputAdapterNode.RiaPathMemory; +import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode.SubnetworkPathMemory; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.drools.core.phreak.RuleAgendaItem; import org.drools.core.phreak.RuleExecutor; @@ -42,7 +43,7 @@ import org.drools.core.reteoo.NotNode; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.PathMemory; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.RuleTerminalNode; import org.drools.core.reteoo.SegmentMemory; import org.drools.core.reteoo.Tuple; @@ -261,20 +262,20 @@ public void testSubNetworkSharing() throws Exception { ExistsNode existsNode3 = ( ExistsNode) liaNode.getSinkPropagator().getSinks()[2]; JoinNode joinNodeB = ( JoinNode) liaNode.getSinkPropagator().getSinks()[0]; - assertThat(getObjectTypeNode(kbase, B.class)).isSameAs(joinNodeB.getRightInput()); + assertThat(getObjectTypeNode(kbase, B.class)).isSameAs(joinNodeB.getRightInput().getParent()); JoinNode joinNodeC = ( JoinNode) joinNodeB.getSinkPropagator().getSinks()[0]; - assertThat(getObjectTypeNode(kbase, C.class)).isSameAs(joinNodeC.getRightInput()); + assertThat(getObjectTypeNode(kbase, C.class)).isSameAs(joinNodeC.getRightInput().getParent()); assertThat(joinNodeC.getSinkPropagator().size()).isEqualTo(2); JoinNode joinNodeD = ( JoinNode) joinNodeC.getSinkPropagator().getSinks()[0]; - assertThat(getObjectTypeNode(kbase, X.class)).isSameAs(joinNodeD.getRightInput()); + assertThat(getObjectTypeNode(kbase, X.class)).isSameAs(joinNodeD.getRightInput().getParent()); assertThat(joinNodeD.getSinkPropagator().size()).isEqualTo(2); - assertThat(((RightInputAdapterNode) joinNodeC.getSinkPropagator().getSinks()[1]).getObjectSinkPropagator().getSinks()[0]).isSameAs(existsNode2); + assertThat(((RightInputAdapterNode)((TupleToObjectNode) joinNodeC.getSinkPropagator().getSinks()[1]).getObjectSinkPropagator().getSinks()[0]).getBetaNode()).isSameAs(existsNode2); - assertThat(((RightInputAdapterNode) joinNodeD.getSinkPropagator().getSinks()[1]).getObjectSinkPropagator().getSinks()[0]).isSameAs(existsNode3); + assertThat(((RightInputAdapterNode)((TupleToObjectNode) joinNodeD.getSinkPropagator().getSinks()[1]).getObjectSinkPropagator().getSinks()[0]).getBetaNode()).isSameAs(existsNode3); } @Test @@ -423,7 +424,7 @@ public void testSubNetworkRiaLinking() throws Exception { JoinNode dNode = ( JoinNode) cNode.getSinkPropagator().getSinks()[0]; assertThat(dNode.getSinkPropagator().size()).isEqualTo(1); - RightInputAdapterNode riaNode1 = ( RightInputAdapterNode ) dNode.getSinkPropagator().getSinks()[0]; + TupleToObjectNode riaNode1 = (TupleToObjectNode) dNode.getSinkPropagator().getSinks()[0]; JoinNode eNode = ( JoinNode ) exists1n.getSinkPropagator().getSinks()[0]; @@ -571,14 +572,14 @@ public void testNonReactiveSubNetworkOwnSegmentMasks() throws Exception { assertThat(pmem.getSegmentMemories().length).isEqualTo(4); assertThat(pmem.getAllLinkedMaskTest()).isEqualTo(11); // the exists eval segment does not need to be linked in - RiaPathMemory riaMem = (RiaPathMemory) wm.getNodeMemory((MemoryFactory) exists1n.getRightInput()); + SubnetworkPathMemory riaMem = (SubnetworkPathMemory) wm.getNodeMemory((MemoryFactory) exists1n.getRightInput().getParent()); assertThat(riaMem.getAllLinkedMaskTest()).isEqualTo(2); // second segment must be linked in wm.insert( new B() ); wm.insert( new C() ); assertThat(riaMem.getSegmentMemories().length).isEqualTo(2); - riaMem = (RiaPathMemory) wm.getNodeMemory((MemoryFactory) exists2n.getRightInput()); + riaMem = (SubnetworkPathMemory) wm.getNodeMemory((MemoryFactory) exists2n.getRightInput().getParent()); assertThat(riaMem.getAllLinkedMaskTest()).isEqualTo(0); // no segments to be linked in } @@ -625,11 +626,11 @@ public void testNestedSubNetwork() throws Exception { JoinNode eNode = ( JoinNode) dNode.getSinkPropagator().getSinks()[0]; JoinNode fNode = ( JoinNode) eNode.getSinkPropagator().getSinks()[0]; - RightInputAdapterNode riaNode2 = ( RightInputAdapterNode ) fNode.getSinkPropagator().getSinks()[0]; - assertThat(riaNode2.getObjectSinkPropagator().getSinks()[0]).isEqualTo(exists2n); + TupleToObjectNode riaNode2 = (TupleToObjectNode) fNode.getSinkPropagator().getSinks()[0]; + assertThat(((RightInputAdapterNode)riaNode2.getObjectSinkPropagator().getSinks()[0]).getBetaNode()).isEqualTo(exists2n); - RightInputAdapterNode riaNode1 = ( RightInputAdapterNode ) exists2n.getSinkPropagator().getSinks()[0]; - assertThat(riaNode1.getObjectSinkPropagator().getSinks()[0]).isEqualTo(exists1n); + TupleToObjectNode riaNode1 = (TupleToObjectNode) exists2n.getSinkPropagator().getSinks()[0]; + assertThat(((RightInputAdapterNode)riaNode1.getObjectSinkPropagator().getSinks()[0]).getBetaNode()).isEqualTo(exists1n); JoinNode gNode = ( JoinNode) exists1n.getSinkPropagator().getSinks()[0]; RuleTerminalNode rtn = ( RuleTerminalNode) gNode.getSinkPropagator().getSinks()[0]; @@ -697,8 +698,8 @@ public void testNestedSubNetworkMasks() throws Exception { JoinNode eNode = ( JoinNode) dNode.getSinkPropagator().getSinks()[0]; JoinNode fNode = ( JoinNode) eNode.getSinkPropagator().getSinks()[0]; - RightInputAdapterNode riaNode2 = ( RightInputAdapterNode ) fNode.getSinkPropagator().getSinks()[0]; - RightInputAdapterNode riaNode1 = ( RightInputAdapterNode ) exists2n.getSinkPropagator().getSinks()[0]; + TupleToObjectNode riaNode2 = (TupleToObjectNode) fNode.getSinkPropagator().getSinks()[0]; + TupleToObjectNode riaNode1 = (TupleToObjectNode) exists2n.getSinkPropagator().getSinks()[0]; JoinNode gNode = ( JoinNode) exists1n.getSinkPropagator().getSinks()[0]; RuleTerminalNode rtn = ( RuleTerminalNode) gNode.getSinkPropagator().getSinks()[0]; @@ -720,8 +721,8 @@ public void testNestedSubNetworkMasks() throws Exception { BetaMemory fMem = (BetaMemory) wm.getNodeMemory(fNode); BetaMemory gMem = (BetaMemory) wm.getNodeMemory(gNode); - RiaPathMemory riaMem1 = (RiaPathMemory) wm.getNodeMemory(riaNode1); - RiaPathMemory riaMem2 = (RiaPathMemory) wm.getNodeMemory(riaNode2); + SubnetworkPathMemory riaMem1 = (SubnetworkPathMemory) wm.getNodeMemory(riaNode1); + SubnetworkPathMemory riaMem2 = (SubnetworkPathMemory) wm.getNodeMemory(riaNode2); PathMemory rs = wm.getNodeMemory(rtn); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/NodePositionInPathTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/NodePositionInPathTest.java index dec094bab13..35adaa30a55 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/NodePositionInPathTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/NodePositionInPathTest.java @@ -30,7 +30,7 @@ import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.Rete; import org.drools.core.reteoo.ReteDumper; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.RuleTerminalNode; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; @@ -104,12 +104,12 @@ public void test() { BetaNode join3 = (BetaNode) join1.getSinkPropagator().getSinks()[0]; assertThat(join3.getPathIndex()).isEqualTo(2); - RightInputAdapterNode ria1 = (RightInputAdapterNode) join3.getSinkPropagator().getSinks()[0]; + TupleToObjectNode ria1 = (TupleToObjectNode) join3.getSinkPropagator().getSinks()[0]; assertThat(ria1.getPathIndex()).isEqualTo(3); BetaNode join4 = (BetaNode) join1.getSinkPropagator().getSinks()[1]; assertThat(join4.getPathIndex()).isEqualTo(2); - RightInputAdapterNode ria2 = (RightInputAdapterNode) join4.getSinkPropagator().getSinks()[0]; + TupleToObjectNode ria2 = (TupleToObjectNode) join4.getSinkPropagator().getSinks()[0]; assertThat(ria2.getPathIndex()).isEqualTo(3); LeftTupleNode[] rtn1PathNodes = rtn1.getPathNodes(); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/NodesPartitioningTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/NodesPartitioningTest.java index 4c2fc022dab..65e55e1eb47 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/NodesPartitioningTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/NodesPartitioningTest.java @@ -86,7 +86,9 @@ private void traverse(BaseNode node ) { NetworkNode[] sinks = node.getSinks(); if (sinks != null) { for (NetworkNode sink : sinks) { - if (sink instanceof BaseNode) { + if (sink instanceof RightInputAdapterNode) { + traverse(((RightInputAdapterNode)sink).getBetaNode()); + } else if (sink instanceof BaseNode) { traverse((BaseNode)sink); } } @@ -99,13 +101,15 @@ private void checkNode(NetworkNode node) { } else if (node instanceof ObjectTypeNode) { assertThat(node.getPartitionId()).isSameAs(RuleBasePartitionId.MAIN_PARTITION); checkPartitionedSinks((ObjectTypeNode) node); - } else if (node instanceof ObjectSource ) { - ObjectSource source = ( (ObjectSource) node ).getParentObjectSource(); + } else if (node instanceof RightInputAdapterNode){ + assertThat(node.getPartitionId()).isSameAs(((RightInputAdapterNode)node).getBetaNode().getPartitionId()); + } if (node instanceof ObjectSource ) { + BaseNode source = ( (ObjectSource) node ).getParent(); if ( !(source instanceof ObjectTypeNode) ) { assertThat(node.getPartitionId()).isSameAs(source.getPartitionId()); } } else if (node instanceof BetaNode ) { - ObjectSource rightInput = ( (BetaNode) node ).getRightInput(); + ObjectSource rightInput = ( (BetaNode) node ).getRightInput().getParent(); if ( !(rightInput instanceof ObjectTypeNode) ) { assertThat(node.getPartitionId()).isSameAs(rightInput.getPartitionId()); } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/PathEndNodeTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/PathEndNodeTest.java index a42bdef04fe..c6dee81f547 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/PathEndNodeTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/PathEndNodeTest.java @@ -21,12 +21,13 @@ import java.util.Collection; import org.drools.base.base.ClassObjectType; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.core.reteoo.BetaNode; import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.LeftTupleSink; import org.drools.core.reteoo.ObjectTypeNode; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.RuleTerminalNode; import org.drools.base.rule.EntryPointId; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; @@ -74,9 +75,9 @@ public void testSubNetworkSharing() throws Exception { EntryPointNode epn = kbase.getRete().getEntryPointNode( EntryPointId.DEFAULT ); ObjectTypeNode otn = epn.getObjectTypeNodes().get( new ClassObjectType( Long.class) ); - BetaNode beta1 = (BetaNode) otn.getObjectSinkPropagator().getSinks()[0]; - RightInputAdapterNode rian = (RightInputAdapterNode) beta1.getSinkPropagator().getSinks()[0]; - BetaNode beta2 = (BetaNode) rian.getObjectSinkPropagator().getSinks()[0]; + BetaNode beta1 = ((RightInputAdapterNode)otn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + TupleToObjectNode rian = (TupleToObjectNode) beta1.getSinkPropagator().getSinks()[0]; + BetaNode beta2 = ((RightInputAdapterNode)rian.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); LeftTupleSink[] sinks = beta2.getSinkPropagator().getSinks(); RuleTerminalNode rtn1 = (RuleTerminalNode) sinks[0]; RuleTerminalNode rtn2 = (RuleTerminalNode) sinks[1]; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/PropertySpecificTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/PropertySpecificTest.java index b2f09b3de22..dc35df236eb 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/PropertySpecificTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/PropertySpecificTest.java @@ -33,6 +33,7 @@ import org.drools.core.impl.InternalRuleBase; import org.drools.core.reteoo.AlphaNode; import org.drools.core.reteoo.BetaNode; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.LeftInputAdapterNode; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.base.reteoo.PropertySpecificUtil; @@ -186,10 +187,10 @@ public void testBetaNodeNoConstraintsNoPropertySpecific() { ObjectTypeNode otn = getObjectTypeNode(kbase, "Cheese" ); assertThat(otn).isNotNull(); - BetaNode betaNode = ( BetaNode ) otn.getObjectSinkPropagator().getSinks()[0]; + BetaNode betaNode = ((RightInputAdapterNode)otn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); - assertThat(betaNode.getRightDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNode.getRightInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getRightInput().getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getRightInput().getInferredMask()).isEqualTo(AllSetBitMask.get()); } @Test @@ -217,10 +218,10 @@ public void testBetaNodeWithConstraintsNoPropertySpecific() { assertThat(alphaNode.getDeclaredMask()).isEqualTo(AllSetBitMask.get()); assertThat(alphaNode.getInferredMask()).isEqualTo(AllSetBitMask.get()); - BetaNode betaNode = ( BetaNode ) alphaNode.getObjectSinkPropagator().getSinks()[0]; + BetaNode betaNode = ((RightInputAdapterNode)alphaNode.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); - assertThat(betaNode.getRightDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNode.getRightInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getRightInput().getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getRightInput().getInferredMask()).isEqualTo(AllSetBitMask.get()); } @Test @@ -242,10 +243,10 @@ public void testInitialFactBetaNodeWithRightInputAdapter() { LeftInputAdapterNode liaNode = ( LeftInputAdapterNode ) otn.getObjectSinkPropagator().getSinks()[0]; BetaNode betaNode = ( BetaNode ) liaNode.getSinkPropagator().getSinks()[1]; - assertThat(betaNode.getLeftDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNode.getLeftInferredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNode.getRightDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNode.getRightInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getRightInput().getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getRightInput().getInferredMask()).isEqualTo(AllSetBitMask.get()); } @Test @@ -275,10 +276,10 @@ public void testPersonFactBetaNodeWithRightInputAdapter() { LeftInputAdapterNode liaNode = ( LeftInputAdapterNode ) otn.getObjectSinkPropagator().getSinks()[0]; BetaNode betaNode = ( BetaNode ) liaNode.getSinkPropagator().getSinks()[1]; - assertThat(betaNode.getLeftDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNode.getLeftInferredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNode.getRightDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNode.getRightInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getRightInput().getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode.getRightInput().getInferredMask()).isEqualTo(AllSetBitMask.get()); } @Test @@ -318,10 +319,10 @@ public void testSharedAlphanodeWithBetaNodeConstraintsNoPropertySpecific() { assertThat(alphaNode1_1.getDeclaredMask()).isEqualTo(AllSetBitMask.get()); assertThat(alphaNode1_1.getInferredMask()).isEqualTo(AllSetBitMask.get()); - BetaNode betaNode1 = ( BetaNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0]; + BetaNode betaNode1 = ((RightInputAdapterNode)alphaNode1_1.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); - assertThat(betaNode1.getRightDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNode1.getRightInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode1.getRightInput().getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode1.getRightInput().getInferredMask()).isEqualTo(AllSetBitMask.get()); // second share @@ -329,10 +330,10 @@ public void testSharedAlphanodeWithBetaNodeConstraintsNoPropertySpecific() { assertThat(alphaNode1_2.getDeclaredMask()).isEqualTo(AllSetBitMask.get()); assertThat(alphaNode1_2.getInferredMask()).isEqualTo(AllSetBitMask.get()); - BetaNode betaNode2 = ( BetaNode ) alphaNode1_2.getObjectSinkPropagator().getSinks()[0]; + BetaNode betaNode2 = ((RightInputAdapterNode)alphaNode1_2.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); - assertThat(betaNode2.getRightDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNode2.getRightInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode2.getRightInput().getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNode2.getRightInput().getInferredMask()).isEqualTo(AllSetBitMask.get()); } @@ -609,12 +610,12 @@ public void testBetaNoConstraintsNoWatches() { ObjectTypeNode otn = getObjectTypeNode(kbase, "A" ); assertThat(otn).isNotNull(); - BetaNode betaNode = ( BetaNode ) otn.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode.getRightDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNode.getRightInferredMask()).isEqualTo(EmptyBitMask.get()); + BetaNode betaNode = ((RightInputAdapterNode)otn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode.getRightInput().getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNode.getRightInput().getInferredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNode.getLeftDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNode.getLeftInferredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNode.getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNode.getInferredMask()).isEqualTo(EmptyBitMask.get()); } @Test @@ -627,12 +628,12 @@ public void testBetaNoConstraintsWithWatches() { assertThat(otn).isNotNull(); List sp = getSettableProperties(wm, otn); - BetaNode betaNode = ( BetaNode ) otn.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); - assertThat(betaNode.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); + BetaNode betaNode = ((RightInputAdapterNode)otn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); + assertThat(betaNode.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); - assertThat(betaNode.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); - assertThat(betaNode.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); + assertThat(betaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); + assertThat(betaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); } @Test @@ -650,17 +651,17 @@ public void testBetaWithConstraintsNoWatches() { assertThat(alphaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); assertThat(alphaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b"), sp)); - BetaNode betaNode = ( BetaNode ) alphaNode.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); // beta declares nothing - assertThat(betaNode.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b"), sp)); // beta infers from alpha + BetaNode betaNode = ((RightInputAdapterNode)alphaNode.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); // beta declares nothing + assertThat(betaNode.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b"), sp)); // beta infers from alpha otn = getObjectTypeNode(kbase, "B" ); alphaNode = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0]; assertThat(alphaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); assertThat(alphaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b"), sp)); - assertThat(betaNode.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); - assertThat(betaNode.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b"), sp)); + assertThat(betaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); + assertThat(betaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b"), sp)); } @Test @@ -678,19 +679,19 @@ public void testBetaWithConstraintsWithWatches() { assertThat(alphaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); assertThat(alphaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "s"), sp)); - BetaNode betaNode = ( BetaNode ) alphaNode.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "s"), sp)); - assertThat(betaNode.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "s"), sp)); - assertThat(betaNode.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); + BetaNode betaNode =((RightInputAdapterNode)alphaNode.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "s"), sp)); + assertThat(betaNode.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "s"), sp)); + assertThat(betaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); otn = getObjectTypeNode(kbase, "B" ); alphaNode = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0]; assertThat(alphaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); assertThat(alphaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); - assertThat(betaNode.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); + assertThat(betaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); } @Test @@ -708,19 +709,19 @@ public void testBetaWithConstraintsWithNegativeWatches() { assertThat(alphaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); assertThat(alphaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "s"), sp)); - BetaNode betaNode = ( BetaNode ) alphaNode.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "s"), sp)); - assertThat(betaNode.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("s"), sp)); - assertThat(betaNode.getRightNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a", "!b"), sp)); + BetaNode betaNode = ((RightInputAdapterNode)alphaNode.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "s"), sp)); + assertThat(betaNode.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("s"), sp)); + assertThat(betaNode.getRightInput().getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a", "!b"), sp)); otn = getObjectTypeNode(kbase, "B" ); alphaNode = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0]; assertThat(alphaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); assertThat(alphaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); - assertThat(betaNode.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode.getLeftNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); + assertThat(betaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode.getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); } @Test @@ -744,26 +745,26 @@ public void testBetaSharedAlphaNoWatches() { assertThat(alphaNode1_1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("s"), sp)); assertThat(alphaNode1_1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "s", "b"), sp)); - BetaNode betaNode1 = ( BetaNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode1.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); - assertThat(betaNode1.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "s", "b"), sp)); + BetaNode betaNode1 = ((RightInputAdapterNode)alphaNode1_1.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode1.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); + assertThat(betaNode1.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "s", "b"), sp)); - assertThat(betaNode1.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode1.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode1.getLeftNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); + assertThat(betaNode1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode1.getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); // second share AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[1]; assertThat(alphaNode1_2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i"), sp)); assertThat(alphaNode1_2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b"), sp)); - BetaNode betaNode2 = ( BetaNode ) alphaNode1_2.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode2.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); - assertThat(betaNode2.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b"), sp)); + BetaNode betaNode2 = ((RightInputAdapterNode)alphaNode1_2.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode2.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); + assertThat(betaNode2.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b"), sp)); - assertThat(betaNode2.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); - assertThat(betaNode2.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "j"), sp)); - assertThat(betaNode2.getLeftNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!i"), sp)); + assertThat(betaNode2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); + assertThat(betaNode2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "j"), sp)); + assertThat(betaNode2.getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!i"), sp)); // test rule removal kbase.removeRule( "org.drools.mvel.integrationtests", "r0" ); @@ -773,12 +774,12 @@ public void testBetaSharedAlphaNoWatches() { assertThat(alphaNode1_2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i"), sp)); assertThat(alphaNode1_2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b"), sp)); - assertThat(betaNode2.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); - assertThat(betaNode2.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b"), sp)); + assertThat(betaNode2.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); + assertThat(betaNode2.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b"), sp)); - assertThat(betaNode1.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode1.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode1.getLeftNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); + assertThat(betaNode1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode1.getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); // have to rebuild to remove r1 kbase = getKnowledgeBase(rule1, rule2); @@ -794,13 +795,13 @@ public void testBetaSharedAlphaNoWatches() { assertThat(alphaNode1_1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("s"), sp)); assertThat(alphaNode1_1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "s", "b"), sp)); - betaNode1 = ( BetaNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode1.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); - assertThat(betaNode1.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "s", "b"), sp)); + betaNode1 = ((RightInputAdapterNode)alphaNode1_1.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode1.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); + assertThat(betaNode1.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "s", "b"), sp)); - assertThat(betaNode2.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); - assertThat(betaNode2.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "j"), sp)); - assertThat(betaNode2.getLeftNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!i"), sp)); + assertThat(betaNode2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); + assertThat(betaNode2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "j"), sp)); + assertThat(betaNode2.getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!i"), sp)); } @Test @@ -824,14 +825,14 @@ public void testBetaSharedAlphaWithWatches() { assertThat(alphaNode1_1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); assertThat(alphaNode1_1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); - BetaNode betaNode1 = ( BetaNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode1.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode1.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "c"), sp)); - assertThat(betaNode1.getRightNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!b"), sp)); + BetaNode betaNode1 = ((RightInputAdapterNode)alphaNode1_1.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode1.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode1.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "c"), sp)); + assertThat(betaNode1.getRightInput().getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!b"), sp)); - assertThat(betaNode1.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode1.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode1.getLeftNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); + assertThat(betaNode1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode1.getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); // second share AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[1]; @@ -839,15 +840,15 @@ public void testBetaSharedAlphaWithWatches() { assertThat(alphaNode1_2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b", "s"), sp)); - BetaNode betaNode2 = ( BetaNode ) alphaNode1_2.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode2.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "s"), sp)); - assertThat(betaNode2.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i", "b", "s"), sp)); - assertThat(betaNode2.getRightNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); + BetaNode betaNode2 = ((RightInputAdapterNode)alphaNode1_2.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode2.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "s"), sp)); + assertThat(betaNode2.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i", "b", "s"), sp)); + assertThat(betaNode2.getRightInput().getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); - assertThat(betaNode1.getLeftNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); - assertThat(betaNode2.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); - assertThat(betaNode2.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "j"), sp)); - assertThat(betaNode2.getLeftNegativeMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNode1.getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); + assertThat(betaNode2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); + assertThat(betaNode2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "j"), sp)); + assertThat(betaNode2.getNegativeMask()).isEqualTo(EmptyBitMask.get()); // test rule removal kbase.removeRule( "org.drools.mvel.integrationtests", "r0" ); @@ -857,13 +858,13 @@ public void testBetaSharedAlphaWithWatches() { assertThat(alphaNode1_2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i"), sp)); assertThat(alphaNode1_2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b", "s"), sp)); - assertThat(betaNode2.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "s"), sp)); - assertThat(betaNode2.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i", "b", "s"), sp)); - assertThat(betaNode2.getRightNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); + assertThat(betaNode2.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "s"), sp)); + assertThat(betaNode2.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i", "b", "s"), sp)); + assertThat(betaNode2.getRightInput().getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); - assertThat(betaNode2.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); - assertThat(betaNode2.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "j"), sp)); - assertThat(betaNode2.getLeftNegativeMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNode2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); + assertThat(betaNode2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "j"), sp)); + assertThat(betaNode2.getNegativeMask()).isEqualTo(EmptyBitMask.get()); // have to rebuild to remove r1 kbase = getKnowledgeBase(rule1, rule2); @@ -879,14 +880,14 @@ public void testBetaSharedAlphaWithWatches() { assertThat(alphaNode1_1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); assertThat(alphaNode1_1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); - betaNode1 = ( BetaNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode1.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode1.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "c"), sp)); - assertThat(betaNode1.getRightNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!b"), sp)); + betaNode1 = ((RightInputAdapterNode)alphaNode1_1.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode1.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode1.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "c"), sp)); + assertThat(betaNode1.getRightInput().getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!b"), sp)); - assertThat(betaNode1.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode1.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); - assertThat(betaNode1.getLeftNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); + assertThat(betaNode1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "c"), sp)); + assertThat(betaNode1.getNegativeMask()).isEqualTo(calculateNegativeMask(otn.getObjectType(), list("!a"), sp)); } @Test @@ -911,12 +912,12 @@ public void testComplexBetaSharedAlphaWithWatches() { assertThat(alphaNode1_1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); assertThat(alphaNode1_1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); - BetaNode betaNode1 = ( BetaNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode1.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c"), sp)); - assertThat(betaNode1.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); + BetaNode betaNode1 = ((RightInputAdapterNode)alphaNode1_1.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode1.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c"), sp)); + assertThat(betaNode1.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); - assertThat(betaNode1.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i"), sp)); - assertThat(betaNode1.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "i"), sp)); + assertThat(betaNode1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i"), sp)); + assertThat(betaNode1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "i"), sp)); // second share AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[1]; @@ -924,12 +925,12 @@ public void testComplexBetaSharedAlphaWithWatches() { assertThat(alphaNode1_2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "i", "s", "j"), sp)); - BetaNode betaNode2 = ( BetaNode ) alphaNode1_2.getObjectSinkPropagator().getSinks()[1]; - assertThat(betaNode2.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("s"), sp)); - assertThat(betaNode2.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "s"), sp)); + BetaNode betaNode2 = ((RightInputAdapterNode)alphaNode1_2.getObjectSinkPropagator().getSinks()[1]).getBetaNode(); + assertThat(betaNode2.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("s"), sp)); + assertThat(betaNode2.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "s"), sp)); - assertThat(betaNode2.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); - assertThat(betaNode2.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); + assertThat(betaNode2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); + assertThat(betaNode2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); // third share AlphaNode alphaNode1_4 = ( AlphaNode ) alphaNode1_2.getObjectSinkPropagator().getSinks()[0]; @@ -937,12 +938,12 @@ public void testComplexBetaSharedAlphaWithWatches() { assertThat(alphaNode1_4.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "i", "j"), sp)); - BetaNode betaNode3 = ( BetaNode ) alphaNode1_4.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode3.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); - assertThat(betaNode3.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b", "j"), sp)); + BetaNode betaNode3 = ((RightInputAdapterNode)alphaNode1_4.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode3.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); + assertThat(betaNode3.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b", "j"), sp)); - assertThat(betaNode3.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("k"), sp)); - assertThat(betaNode3.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c", "k"), sp)); + assertThat(betaNode3.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("k"), sp)); + assertThat(betaNode3.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c", "k"), sp)); } @Test @@ -969,24 +970,24 @@ public void testComplexBetaSharedAlphaWithWatchesRemoveR1() { assertThat(alphaNode1_1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i"), sp)); assertThat(alphaNode1_1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b", "s", "j"), sp)); - BetaNode betaNode1 = ( BetaNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[1]; - assertThat(betaNode1.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("s"), sp)); - assertThat(betaNode1.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "s"), sp)); + BetaNode betaNode1 = ((RightInputAdapterNode)alphaNode1_1.getObjectSinkPropagator().getSinks()[1]).getBetaNode(); + assertThat(betaNode1.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("s"), sp)); + assertThat(betaNode1.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "s"), sp)); - assertThat(betaNode1.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); - assertThat(betaNode1.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); + assertThat(betaNode1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); + assertThat(betaNode1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); // second split, third alpha AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0]; assertThat(alphaNode1_2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); assertThat(alphaNode1_2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "i", "j"), sp)); - BetaNode betaNode3 = ( BetaNode ) alphaNode1_2.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode3.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); - assertThat(betaNode3.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b", "j"), sp)); + BetaNode betaNode3 = ((RightInputAdapterNode)alphaNode1_2.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode3.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); + assertThat(betaNode3.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b", "j"), sp)); - assertThat(betaNode3.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("k"), sp)); - assertThat(betaNode3.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c", "k"), sp)); + assertThat(betaNode3.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("k"), sp)); + assertThat(betaNode3.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c", "k"), sp)); } @Test @@ -1013,12 +1014,12 @@ public void testComplexBetaSharedAlphaWithWatchesRemoveR2() { assertThat(alphaNode1_1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); assertThat(alphaNode1_1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); - BetaNode betaNode1 = ( BetaNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode1.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c"), sp)); - assertThat(betaNode1.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); + BetaNode betaNode1 = ((RightInputAdapterNode)alphaNode1_1.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode1.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c"), sp)); + assertThat(betaNode1.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); - assertThat(betaNode1.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i"), sp)); - assertThat(betaNode1.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "i"), sp)); + assertThat(betaNode1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i"), sp)); + assertThat(betaNode1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "i"), sp)); // fist share, second alpha AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[1]; @@ -1030,12 +1031,12 @@ public void testComplexBetaSharedAlphaWithWatchesRemoveR2() { assertThat(alphaNode1_3.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b", "j"), sp)); - BetaNode betaNode2 = ( BetaNode ) alphaNode1_3.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode2.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); - assertThat(betaNode2.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b", "j"), sp)); + BetaNode betaNode2 = ((RightInputAdapterNode)alphaNode1_3.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode2.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); + assertThat(betaNode2.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "b", "j"), sp)); - assertThat(betaNode2.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("k"), sp)); - assertThat(betaNode2.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c", "k"), sp)); + assertThat(betaNode2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("k"), sp)); + assertThat(betaNode2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c", "k"), sp)); } @@ -1064,12 +1065,12 @@ public void testComplexBetaSharedAlphaWithWatchesRemoveR3() { assertThat(alphaNode1_1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); // first split - BetaNode betaNode1 = ( BetaNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode1.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c"), sp)); - assertThat(betaNode1.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); + BetaNode betaNode1 = ((RightInputAdapterNode)alphaNode1_1.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode1.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c"), sp)); + assertThat(betaNode1.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); - assertThat(betaNode1.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i"), sp)); - assertThat(betaNode1.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "i"), sp)); + assertThat(betaNode1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("i"), sp)); + assertThat(betaNode1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "i"), sp)); // second split AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[1]; @@ -1077,12 +1078,12 @@ public void testComplexBetaSharedAlphaWithWatchesRemoveR3() { assertThat(alphaNode1_2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "s"), sp)); - BetaNode betaNode2 = ( BetaNode ) alphaNode1_2.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNode2.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("s"), sp)); - assertThat(betaNode2.getRightInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "s"), sp)); + BetaNode betaNode2 = ((RightInputAdapterNode)alphaNode1_2.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNode2.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("s"), sp)); + assertThat(betaNode2.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "i", "s"), sp)); - assertThat(betaNode2.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); - assertThat(betaNode2.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); + assertThat(betaNode2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("j"), sp)); + assertThat(betaNode2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b", "j"), sp)); } @Test @@ -2065,17 +2066,17 @@ public void testBetaWithWatchAfterBeta() { ObjectTypeNode otnC = getObjectTypeNode(kbase, "C" ); List sp = getSettableProperties(wm, otnA); - BetaNode betaNodeA = ( BetaNode ) otnA.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNodeA.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("i", "b", "c"), sp)); - assertThat(betaNodeA.getRightInferredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("i", "b", "c"), sp)); - assertThat(betaNodeA.getLeftDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNodeA.getLeftInferredMask()).isEqualTo(AllSetBitMask.get()); - - BetaNode betaNodeC = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNodeC.getRightDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC.getRightInferredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otnC.getObjectType(), list("j", "k"), sp)); - assertThat(betaNodeC.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otnC.getObjectType(), list("a", "j", "k"), sp)); + BetaNode betaNodeA = ((RightInputAdapterNode)otnA.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNodeA.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("i", "b", "c"), sp)); + assertThat(betaNodeA.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("i", "b", "c"), sp)); + assertThat(betaNodeA.getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNodeA.getInferredMask()).isEqualTo(AllSetBitMask.get()); + + BetaNode betaNodeC = ((RightInputAdapterNode)otnC.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNodeC.getRightInput().getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC.getRightInput().getInferredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC.getDeclaredMask()).isEqualTo(calculatePositiveMask(otnC.getObjectType(), list("j", "k"), sp)); + assertThat(betaNodeC.getInferredMask()).isEqualTo(calculatePositiveMask(otnC.getObjectType(), list("a", "j", "k"), sp)); } @Test @@ -2088,17 +2089,17 @@ public void testBetaAfterBetaWithWatch() { ObjectTypeNode otnC = getObjectTypeNode(kbase, "C" ); List sp = getSettableProperties(wm, otnA); - BetaNode betaNodeA = ( BetaNode ) otnA.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNodeA.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("i", "b", "c"), sp)); - assertThat(betaNodeA.getRightInferredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("i", "b", "c"), sp)); - assertThat(betaNodeA.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("j", "k"), sp)); - assertThat(betaNodeA.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("a", "j", "k"), sp)); - - BetaNode betaNodeC = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[0]; - assertThat(betaNodeC.getRightDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC.getRightInferredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC.getLeftDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNodeC.getLeftInferredMask()).isEqualTo(AllSetBitMask.get()); + BetaNode betaNodeA = ((RightInputAdapterNode)otnA.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNodeA.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("i", "b", "c"), sp)); + assertThat(betaNodeA.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("i", "b", "c"), sp)); + assertThat(betaNodeA.getDeclaredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("j", "k"), sp)); + assertThat(betaNodeA.getInferredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("a", "j", "k"), sp)); + + BetaNode betaNodeC = ((RightInputAdapterNode)otnC.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + assertThat(betaNodeC.getRightInput().getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC.getRightInput().getInferredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC.getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNodeC.getInferredMask()).isEqualTo(AllSetBitMask.get()); } @Test @@ -2116,23 +2117,23 @@ public void test2DifferentAlphaWatchBeforeSameBeta() { assertThat(alphaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b", "c"), sp)); ObjectTypeNode otnC = getObjectTypeNode(kbase, "C" ); - BetaNode betaNodeC1 = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[0]; - BetaNode betaNodeC2 = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[1]; + BetaNode betaNodeC1 = ((RightInputAdapterNode)otnC.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + BetaNode betaNodeC2 = ((RightInputAdapterNode)otnC.getObjectSinkPropagator().getSinks()[1]).getBetaNode(); LeftInputAdapterNode lia1 = (LeftInputAdapterNode)alphaNode.getObjectSinkPropagator().getSinks()[0]; assertThat(lia1.getSinkPropagator().getSinks()[0]).isSameAs(betaNodeC1); LeftInputAdapterNode lia2 = (LeftInputAdapterNode)alphaNode.getObjectSinkPropagator().getSinks()[1]; assertThat(lia2.getSinkPropagator().getSinks()[0]).isSameAs(betaNodeC2); - assertThat(betaNodeC1.getRightDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC1.getRightInferredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC1.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); - assertThat(betaNodeC1.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b"), sp)); + assertThat(betaNodeC1.getRightInput().getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC1.getRightInput().getInferredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("b"), sp)); + assertThat(betaNodeC1.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "b"), sp)); - assertThat(betaNodeC2.getRightDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC2.getRightInferredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC2.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c"), sp)); - assertThat(betaNodeC2.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "c"), sp)); + assertThat(betaNodeC2.getRightInput().getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC2.getRightInput().getInferredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c"), sp)); + assertThat(betaNodeC2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "c"), sp)); kbase.removeRule( "org.drools.mvel.integrationtests", "r0" ); assertThat(alphaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a"), sp)); @@ -2141,10 +2142,10 @@ public void test2DifferentAlphaWatchBeforeSameBeta() { assertThat(lia2.getSinkPropagator().getSinks().length).isEqualTo(1); BetaNode betaNodeC = ( BetaNode ) lia2.getSinkPropagator().getSinks()[0]; - assertThat(betaNodeC2.getRightDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC2.getRightInferredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC2.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c"), sp)); - assertThat(betaNodeC2.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "c"), sp)); + assertThat(betaNodeC2.getRightInput().getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC2.getRightInput().getInferredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("c"), sp)); + assertThat(betaNodeC2.getInferredMask()).isEqualTo(calculatePositiveMask(otn.getObjectType(), list("a", "c"), sp)); } @Test @@ -2158,28 +2159,28 @@ public void testSameBetasWith2RTNSinks() { ObjectTypeNode otnC = getObjectTypeNode(kbase, "C"); List sp = getSettableProperties(wm, otnA); - BetaNode betaNodeC = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[0]; - BetaNode betaNodeA1 = ( BetaNode ) otnA.getObjectSinkPropagator().getSinks()[0]; - BetaNode betaNodeA2 = ( BetaNode ) otnA.getObjectSinkPropagator().getSinks()[1]; + BetaNode betaNodeC = ((RightInputAdapterNode)otnC.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + BetaNode betaNodeA1 = ((RightInputAdapterNode)otnA.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + BetaNode betaNodeA2 = ((RightInputAdapterNode)otnA.getObjectSinkPropagator().getSinks()[1]).getBetaNode(); assertThat(betaNodeA1).isSameAs(betaNodeC.getSinkPropagator().getSinks()[0]); assertThat(betaNodeA2).isSameAs(betaNodeC.getSinkPropagator().getSinks()[1]); assertThat(betaNodeC).isSameAs(betaNodeA1.getLeftTupleSource()); assertThat(betaNodeC).isSameAs(betaNodeA2.getLeftTupleSource()); - assertThat(betaNodeC.getRightDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC.getRightInferredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC.getLeftDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("a"), sp)); + assertThat(betaNodeC.getRightInput().getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC.getRightInput().getInferredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC.getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC.getInferredMask()).isEqualTo(calculatePositiveMask(otnA.getObjectType(), list("a"), sp)); - assertThat(betaNodeA1.getRightDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeA1.getRightInferredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeA1.getLeftDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNodeA1.getLeftInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNodeA1.getRightInput().getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeA1.getRightInput().getInferredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeA1.getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNodeA1.getInferredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNodeA2.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otnC.getObjectType(), list("b", "c"), sp)); - assertThat(betaNodeA2.getRightInferredMask()).isEqualTo(calculatePositiveMask(otnC.getObjectType(), list("b", "c"), sp)); - assertThat(betaNodeA2.getLeftDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNodeA2.getLeftInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNodeA2.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otnC.getObjectType(), list("b", "c"), sp)); + assertThat(betaNodeA2.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otnC.getObjectType(), list("b", "c"), sp)); + assertThat(betaNodeA2.getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNodeA2.getInferredMask()).isEqualTo(AllSetBitMask.get()); kbase.removeRule( "org.drools.mvel.integrationtests", "r0" ); assertThat(betaNodeC.getSinkPropagator().getSinks().length).isEqualTo(1); @@ -2200,34 +2201,34 @@ public void testBetaWith2BetaSinks() { assertThat(alphaNode.getInferredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("a", "b", "c"), sp)); ObjectTypeNode otnA = getObjectTypeNode(kbase, "A" ); - BetaNode betaNodeA1 = ( BetaNode ) otnA.getObjectSinkPropagator().getSinks()[0]; - BetaNode betaNodeA2 = ( BetaNode ) otnA.getObjectSinkPropagator().getSinks()[1]; + BetaNode betaNodeA1 = ((RightInputAdapterNode)otnA.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); + BetaNode betaNodeA2 = ((RightInputAdapterNode)otnA.getObjectSinkPropagator().getSinks()[1]).getBetaNode(); - assertThat(betaNodeA1.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("i"), sp)); - assertThat(betaNodeA1.getRightInferredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("i"), sp)); - assertThat(betaNodeA1.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("b"), sp)); - assertThat(betaNodeA1.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("a", "b"), sp)); + assertThat(betaNodeA1.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("i"), sp)); + assertThat(betaNodeA1.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("i"), sp)); + assertThat(betaNodeA1.getDeclaredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("b"), sp)); + assertThat(betaNodeA1.getInferredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("a", "b"), sp)); - assertThat(betaNodeA2.getRightDeclaredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("j"), sp)); - assertThat(betaNodeA2.getRightInferredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("j"), sp)); - assertThat(betaNodeA2.getLeftDeclaredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("c"), sp)); - assertThat(betaNodeA2.getLeftInferredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("a", "c"), sp)); + assertThat(betaNodeA2.getRightInput().getDeclaredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("j"), sp)); + assertThat(betaNodeA2.getRightInput().getInferredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("j"), sp)); + assertThat(betaNodeA2.getDeclaredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("c"), sp)); + assertThat(betaNodeA2.getInferredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("a", "c"), sp)); ObjectTypeNode otnC = getObjectTypeNode(kbase, "C" ); - BetaNode betaNodeC = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[0]; + BetaNode betaNodeC = ((RightInputAdapterNode)otnC.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); - assertThat(betaNodeC.getRightDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC.getRightInferredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeC.getLeftDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNodeC.getLeftInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNodeC.getRightInput().getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC.getRightInput().getInferredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeC.getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNodeC.getInferredMask()).isEqualTo(AllSetBitMask.get()); ObjectTypeNode otnD = getObjectTypeNode(kbase, "D" ); - BetaNode betaNodeD = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[0]; + BetaNode betaNodeD = ((RightInputAdapterNode)otnC.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); - assertThat(betaNodeD.getRightDeclaredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeD.getRightInferredMask()).isEqualTo(EmptyBitMask.get()); - assertThat(betaNodeD.getLeftDeclaredMask()).isEqualTo(AllSetBitMask.get()); - assertThat(betaNodeD.getLeftInferredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNodeD.getRightInput().getDeclaredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeD.getRightInput().getInferredMask()).isEqualTo(EmptyBitMask.get()); + assertThat(betaNodeD.getDeclaredMask()).isEqualTo(AllSetBitMask.get()); + assertThat(betaNodeD.getInferredMask()).isEqualTo(AllSetBitMask.get()); kbase.removeRule( "org.drools.mvel.integrationtests", "r1" ); assertThat(alphaNode.getDeclaredMask()).isEqualTo(calculatePositiveMask(otnB.getObjectType(), list("a"), sp)); @@ -2584,7 +2585,7 @@ public static class LongFact { private Long longDiff; public LongFact( int i) { - this.longVal = new Long(i); + this.longVal = Long.valueOf(i); } public Long getLongDiff() { diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/SegmentCreationTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/SegmentCreationTest.java index 0e88c104d1f..09f35e3bec0 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/SegmentCreationTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/SegmentCreationTest.java @@ -30,13 +30,14 @@ import org.drools.core.reteoo.ConditionalBranchNode; import org.drools.base.reteoo.InitialFactImpl; import org.drools.core.reteoo.JoinNode; +import org.drools.core.reteoo.JoinRightAdapterNode; import org.drools.core.reteoo.LeftInputAdapterNode; import org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory; import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.NotNode; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.PathMemory; -import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.RuleTerminalNode; import org.drools.core.reteoo.SegmentMemory; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; @@ -188,7 +189,7 @@ public void testMultiSharedPattern() throws Exception { LeftInputAdapterNode lian = (LeftInputAdapterNode) dotn.getObjectSinkPropagator().getSinks()[0]; - JoinNode beta = (JoinNode) aotn.getObjectSinkPropagator().getSinks()[0]; + JoinNode beta = ((JoinRightAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); RuleTerminalNode rtn1 = ( RuleTerminalNode) beta.getSinkPropagator().getSinks()[0]; JoinNode bNode = ( JoinNode ) beta.getSinkPropagator().getSinks()[1]; RuleTerminalNode rtn2 = ( RuleTerminalNode) bNode.getSinkPropagator().getSinks()[0]; @@ -245,8 +246,8 @@ public void testSubnetworkNoSharing() throws Exception { LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0]; JoinNode bNode = ( JoinNode ) liaNode.getSinkPropagator().getSinks()[0]; - JoinNode cNode = ( JoinNode ) bNode.getSinkPropagator().getSinks()[0]; - RightInputAdapterNode riaNode = ( RightInputAdapterNode ) cNode.getSinkPropagator().getSinks()[0]; + JoinNode cNode = ( JoinNode ) bNode.getSinkPropagator().getSinks()[0]; + TupleToObjectNode riaNode = (TupleToObjectNode) cNode.getSinkPropagator().getSinks()[0]; NotNode notNode = ( NotNode ) liaNode.getSinkPropagator().getSinks()[1]; RuleTerminalNode rtn1 = ( RuleTerminalNode) notNode.getSinkPropagator().getSinks()[0]; @@ -271,7 +272,7 @@ public void testSubnetworkNoSharing() throws Exception { BetaMemory bm = (BetaMemory) wm.getNodeMemory(notNode); assertThat(smem.getNext()).isEqualTo(bm.getSegmentMemory()); - assertThat(bm.getRiaRuleMemory().getSegmentMemory()).isEqualTo(bSmem); // check subnetwork ref was made + assertThat(bm.getSubnetworkPathMemory().getSegmentMemory()).isEqualTo(bSmem); // check subnetwork ref was made } @@ -287,12 +288,12 @@ public void tesSubnetworkAfterShare() throws Exception { LeftInputAdapterNode lian = (LeftInputAdapterNode) dotn.getObjectSinkPropagator().getSinks()[0]; - JoinNode joinNode = (JoinNode) aotn.getObjectSinkPropagator().getSinks()[0]; + JoinNode joinNode = ((JoinRightAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); RuleTerminalNode rtn1 = ( RuleTerminalNode) joinNode.getSinkPropagator().getSinks()[0]; JoinNode bNode = ( JoinNode ) joinNode.getSinkPropagator().getSinks()[1]; - JoinNode cNode = ( JoinNode ) bNode.getSinkPropagator().getSinks()[0]; - RightInputAdapterNode riaNode = ( RightInputAdapterNode ) cNode.getSinkPropagator().getSinks()[0]; + JoinNode cNode = ( JoinNode ) bNode.getSinkPropagator().getSinks()[0]; + TupleToObjectNode riaNode = (TupleToObjectNode) cNode.getSinkPropagator().getSinks()[0]; NotNode notNode = ( NotNode ) joinNode.getSinkPropagator().getSinks()[2]; RuleTerminalNode rtn2 = ( RuleTerminalNode) notNode.getSinkPropagator().getSinks()[0]; @@ -337,13 +338,13 @@ public void tesShareInSubnetwork() throws Exception { LeftInputAdapterNode lian = (LeftInputAdapterNode) dotn.getObjectSinkPropagator().getSinks()[0]; - JoinNode beta = (JoinNode) aotn.getObjectSinkPropagator().getSinks()[0]; + JoinNode beta = ((JoinRightAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); RuleTerminalNode rtn1 = ( RuleTerminalNode) beta.getSinkPropagator().getSinks()[0]; JoinNode bNode = ( JoinNode ) beta.getSinkPropagator().getSinks()[1]; JoinNode cNode = ( JoinNode ) bNode.getSinkPropagator().getSinks()[0]; - RuleTerminalNode rtn2 = ( RuleTerminalNode ) cNode.getSinkPropagator().getSinks()[0]; - RightInputAdapterNode riaNode = ( RightInputAdapterNode ) cNode.getSinkPropagator().getSinks()[1]; + RuleTerminalNode rtn2 = ( RuleTerminalNode ) cNode.getSinkPropagator().getSinks()[0]; + TupleToObjectNode riaNode = (TupleToObjectNode) cNode.getSinkPropagator().getSinks()[1]; NotNode notNode = ( NotNode ) beta.getSinkPropagator().getSinks()[2]; RuleTerminalNode rtn3 = ( RuleTerminalNode) notNode.getSinkPropagator().getSinks()[0]; @@ -448,7 +449,7 @@ public void testBranchCEMultipleSegments() throws Exception { ObjectTypeNode aotn = getObjectTypeNode(kbase, LinkingTest.A.class ); - LeftTupleSource liaNode = (LeftTupleSource) aotn.getObjectSinkPropagator().getSinks()[0]; + LeftTupleSource liaNode = ((JoinRightAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); ConditionalBranchNode cen1Node = ( ConditionalBranchNode ) liaNode.getSinkPropagator().getSinks()[1]; JoinNode bNode = ( JoinNode ) cen1Node.getSinkPropagator().getSinks()[0]; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/AddRuleTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/AddRuleTest.java index e0b5bf652b8..80b3040611e 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/AddRuleTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/AddRuleTest.java @@ -39,9 +39,11 @@ import org.drools.core.phreak.PhreakBuilder; import org.drools.core.reteoo.BetaMemory; import org.drools.core.reteoo.BetaNode; +import org.drools.core.reteoo.RightInputAdapterNode; import org.drools.core.reteoo.EvalConditionNode; import org.drools.core.reteoo.ExistsNode; import org.drools.core.reteoo.JoinNode; +import org.drools.core.reteoo.JoinRightAdapterNode; import org.drools.core.reteoo.LeftInputAdapterNode; import org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory; import org.drools.core.reteoo.LeftTupleNode; @@ -99,7 +101,7 @@ public void testAddThenSplitProtoAllJoins() { ObjectTypeNode cotn = getObjectTypeNode(kbase1.getRete(), C.class); LeftInputAdapterNode lian = (LeftInputAdapterNode) aotn.getSinks()[0]; - BetaNode cbeta = (BetaNode) cotn.getSinks()[0]; + BetaNode cbeta = ((RightInputAdapterNode)cotn.getSinks()[0]).getBetaNode(); insertAndFlush(wm); @@ -152,7 +154,7 @@ public void testAddThenSplitProtoWithNot() { ObjectTypeNode cotn = getObjectTypeNode(kbase1.getRete(), C.class); LeftInputAdapterNode lian = (LeftInputAdapterNode) aotn.getSinks()[0]; - BetaNode cbeta = (BetaNode) cotn.getSinks()[0]; + BetaNode cbeta = ((RightInputAdapterNode)cotn.getSinks()[0]).getBetaNode(); insertAndFlush(wm); @@ -188,9 +190,9 @@ public void testAddWithSplitThenCreateThirdSplit() { ObjectTypeNode xotn = getObjectTypeNode(kbase1.getRete(), X.class); LeftInputAdapterNode lian = (LeftInputAdapterNode) aotn.getSinks()[0]; - BetaNode ebeta = (BetaNode) eotn.getSinks()[0].getSinks()[0]; - BetaNode ebeta3 = (BetaNode) eotn.getSinks()[2].getSinks()[0]; - BetaNode xbeta = (BetaNode) xotn.getSinks()[0]; + BetaNode ebeta = ((RightInputAdapterNode)eotn.getSinks()[0].getSinks()[0]).getBetaNode(); + BetaNode ebeta3 = ((RightInputAdapterNode)eotn.getSinks()[2].getSinks()[0]).getBetaNode(); + BetaNode xbeta = ((RightInputAdapterNode)xotn.getSinks()[0]).getBetaNode(); insertAndFlush(wm); @@ -246,10 +248,10 @@ public void testAddWithSplitThenCreateThirdSplitInSamePos() { ObjectTypeNode yotn = getObjectTypeNode(kbase1.getRete(), Y.class); LeftInputAdapterNode lian = (LeftInputAdapterNode) aotn.getSinks()[0]; - BetaNode ebeta = (BetaNode) eotn.getSinks()[0].getSinks()[0]; - BetaNode cbeta = (BetaNode) cotn.getSinks()[0]; - BetaNode ebeta3 = (BetaNode) eotn.getSinks()[2].getSinks()[0]; - BetaNode xbeta = (BetaNode) xotn.getSinks()[0]; + BetaNode ebeta = ((RightInputAdapterNode)eotn.getSinks()[0].getSinks()[0]).getBetaNode(); + BetaNode cbeta = ((RightInputAdapterNode)cotn.getSinks()[0]).getBetaNode(); + BetaNode ebeta3 = ((RightInputAdapterNode)eotn.getSinks()[2].getSinks()[0]).getBetaNode(); + BetaNode xbeta = ((RightInputAdapterNode)xotn.getSinks()[0]).getBetaNode(); insertAndFlush(wm); wm.fireAllRules(); @@ -268,7 +270,7 @@ public void testAddWithSplitThenCreateThirdSplitInSamePos() { // now add a rule at the given split, so we can check paths were all updated correctly addRuleAtGivenSplit(kbase1, wm, cbeta, yotn); - BetaNode jbeta = (BetaNode) yotn.getSinks()[1]; + BetaNode jbeta = ((RightInputAdapterNode)yotn.getSinks()[1]).getBetaNode(); assertThat(((ClassObjectType)jbeta.getObjectTypeNode().getObjectType()).getClassType()).isSameAs(Y.class); assertThat(jbeta.getLeftTupleSource()).isSameAs(cbeta); @@ -295,7 +297,7 @@ private static void addRuleAtGivenSplit(InternalKnowledgeBase kbase1, InternalWo RuleTerminalNode rtn = new RuleTerminalNode(buildContext.getNextNodeId(), joinNode, rule, new GroupElement(), 0, buildContext); rtn.setPathEndNodes(new PathEndNode[]{rtn}); rtn.doAttach(buildContext); - Arrays.stream(rtn.getPathNodes()).forEach( n -> {n.addAssociatedTerminal(rtn); ((BaseNode)n).addAssociation(rule);}); + Arrays.stream(rtn.getPathNodes()).forEach( n -> {n.addAssociatedTerminal(rtn); ((BaseNode)n).addAssociation(rule, null);}); new EagerPhreakBuilder().addRule(rtn, Collections.singletonList(wm), kbase1); } @@ -313,8 +315,8 @@ public void testAddWithSplitAndEvalThenCreateThirdSplit() { ObjectTypeNode eotn = getObjectTypeNode(kbase1.getRete(), E.class); LeftInputAdapterNode lian = (LeftInputAdapterNode) aotn.getSinks()[0]; - BetaNode cbeta = (BetaNode) cotn.getSinks()[0]; - BetaNode ebeta3 = (BetaNode) eotn.getSinks()[0].getSinks()[0]; + BetaNode cbeta = ((RightInputAdapterNode)cotn.getSinks()[0]).getBetaNode(); + BetaNode ebeta3 = ((RightInputAdapterNode)eotn.getSinks()[0].getSinks()[0]).getBetaNode(); EvalConditionNode evnode = (EvalConditionNode) cbeta.getSinks()[0]; insertAndFlush(wm); @@ -356,7 +358,7 @@ public void testChildProtosPosAndEndNodeSegmentsUpdated() { ObjectTypeNode botn = getObjectTypeNode(kbase1.getRete(), B.class); LeftInputAdapterNode lian = (LeftInputAdapterNode) aotn.getSinks()[0]; - BetaNode bbeta = (BetaNode) botn.getSinks()[0]; + BetaNode bbeta = ((RightInputAdapterNode)botn.getSinks()[0]).getBetaNode(); insertAndFlush(wm); @@ -396,7 +398,7 @@ public void testDataStructuresWithSubnetwork() { SegmentPrototype smemProto0 = kbase1.getSegmentPrototype(lian); PathEndNode endNode0 = smemProto0.getPathEndNodes()[0]; - assertThat(endNode0.getType()).isEqualTo(NodeTypeEnums.RightInputAdapterNode); + assertThat(endNode0.getType()).isEqualTo(NodeTypeEnums.TupleToObjectNode); assertThat(endNode0.getPathMemSpec().allLinkedTestMask()).isEqualTo(2); assertThat(endNode0.getPathMemSpec().smemCount()).isEqualTo(2); @@ -415,8 +417,8 @@ public void testFindNewBrancheRootsSimple() { ObjectTypeNode cotn = getObjectTypeNode(kbase1.getRete(), C.class); ObjectTypeNode xotn = getObjectTypeNode(kbase1.getRete(), X.class); - BetaNode cBeta = (BetaNode) cotn.getSinks()[0]; - BetaNode xBeta = (BetaNode) xotn.getSinks()[0]; + BetaNode cBeta = ((RightInputAdapterNode)cotn.getSinks()[0]).getBetaNode(); + BetaNode xBeta = ((RightInputAdapterNode)xotn.getSinks()[0]).getBetaNode(); TerminalNode[] tns = kbase1.getReteooBuilder().getTerminalNodes("org.kie.r0"); assertThat(tns.length).isEqualTo(1); @@ -442,9 +444,9 @@ public void testNewBrancheRootsWithSubnetwork() { ObjectTypeNode xotn = getObjectTypeNode(kbase1.getRete(), X.class); ObjectTypeNode botn = getObjectTypeNode(kbase1.getRete(), B.class); - BetaNode fBeta = (BetaNode) fotn.getSinks()[0]; - BetaNode xBeta = (BetaNode) xotn.getSinks()[0]; - ExistsNode exists = (ExistsNode) ((LeftTupleNode)botn.getSinks()[1].getSinks()[0]).getLeftTupleSource(); + BetaNode fBeta = ((RightInputAdapterNode)fotn.getSinks()[0]).getBetaNode(); + BetaNode xBeta = ((RightInputAdapterNode)xotn.getSinks()[0]).getBetaNode(); + ExistsNode exists = (ExistsNode) ((RightInputAdapterNode)botn.getSinks()[1].getSinks()[0]).getBetaNode().getLeftTupleSource(); TerminalNode[] tns = kbase1.getReteooBuilder().getTerminalNodes("org.kie.r0"); assertThat(tns.length).isEqualTo(1); @@ -830,7 +832,7 @@ public void testPopulatedSharedToRtn() throws Exception { kbase1.addPackages( buildKnowledgePackage("r2", " A() B() C() X() E()\n") ); ObjectTypeNode eotn = getObjectTypeNode(kbase1, E.class ); - JoinNode eNode = (JoinNode) eotn.getObjectSinkPropagator().getSinks()[0]; + JoinNode eNode = ((JoinRightAdapterNode)eotn.getObjectSinkPropagator().getSinks()[0]).getBetaNode(); RuleTerminalNode rtn = ( RuleTerminalNode ) eNode.getSinkPropagator().getLastLeftTupleSink(); PathMemory pm = wm.getNodeMemory(rtn); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/BetaNodeBuilder.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/BetaNodeBuilder.java index bb5a51a6658..c090e958152 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/BetaNodeBuilder.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/BetaNodeBuilder.java @@ -18,6 +18,7 @@ */ package org.drools.mvel.integrationtests.phreak; +import org.drools.core.reteoo.JoinRightAdapterNode; import org.drools.core.reteoo.LeftTupleSource; import org.drools.mvel.accessors.ClassFieldAccessorStore; import org.drools.base.base.ClassObjectType; @@ -135,11 +136,14 @@ public BetaNode build(LeftTupleSource leftInput, ObjectSource rightInput) { switch (nodeType) { case NodeTypeEnums.JoinNode: - return new JoinNode(buildContext.getNextNodeId(), leftInput, rightInput, betaConstraints, buildContext); + return new JoinNode(buildContext.getNextNodeId(), leftInput, + new JoinRightAdapterNode(buildContext.getNextNodeId(), rightInput, buildContext), betaConstraints, buildContext); case NodeTypeEnums.NotNode: - return new NotNode(buildContext.getNextNodeId(), leftInput, rightInput, betaConstraints, buildContext); + return new NotNode(buildContext.getNextNodeId(), leftInput, + new JoinRightAdapterNode(buildContext.getNextNodeId(), rightInput, buildContext), betaConstraints, buildContext); case NodeTypeEnums.ExistsNode: - return new ExistsNode(buildContext.getNextNodeId(), leftInput, rightInput, betaConstraints, buildContext); + return new ExistsNode(buildContext.getNextNodeId(), leftInput, + new JoinRightAdapterNode(buildContext.getNextNodeId(), rightInput, buildContext), betaConstraints, buildContext); } throw new IllegalStateException("Unable to build Node"); } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/RightBuilder.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/RightBuilder.java index 98267e1419d..24df9037179 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/RightBuilder.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/RightBuilder.java @@ -28,15 +28,15 @@ import org.drools.core.reteoo.TupleImpl; public class RightBuilder { - private InternalWorkingMemory wm; - private RightTupleSink sink; - private TupleSets rightTuples; - private Scenario scenario; + private InternalWorkingMemory wm; + private RightTupleSink sink; + private TupleSets rightTuples; + private Scenario scenario; public RightBuilder(Scenario scenario) { this.wm = scenario.getWorkingMemory(); this.scenario = scenario; - this.sink = scenario.getBetaNode(); + this.sink = scenario.getBetaNode().getRightInput(); this.rightTuples = scenario.getRightTuples(); } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/RightMemory.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/RightMemory.java index 088c3218112..28c1fae6ed1 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/RightMemory.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/RightMemory.java @@ -53,7 +53,7 @@ public List getRightTuples(Object... objects) { List rightTuples = new ArrayList<>(); for ( Object object : objects ) { InternalFactHandle fh = (InternalFactHandle) wm.insert( object ); - TupleImpl expectedRightTuple = new RightTuple(fh, node ); //node.createLeftTuple( fh, node, true ); + TupleImpl expectedRightTuple = new RightTuple(fh, node.getRightInput() ); //node.createLeftTuple( fh, node, true ); expectedRightTuple.setPropagationContext( new PhreakPropagationContext() ); rightTuples.add( expectedRightTuple ); } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/util/RightTupleIndexHashTableTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/util/RightTupleIndexHashTableTest.java index c059a168989..1885446a8ea 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/util/RightTupleIndexHashTableTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/util/RightTupleIndexHashTableTest.java @@ -20,11 +20,14 @@ import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.drools.base.rule.accessor.RightTupleValueExtractor; import org.drools.core.base.ClassFieldAccessorCache; +import org.drools.core.impl.KnowledgeBaseImpl; import org.drools.core.reteoo.MockLeftTupleSink; +import org.drools.core.reteoo.builder.BuildContext; import org.drools.core.util.index.IndexSpec; import org.drools.mvel.accessors.ClassFieldAccessorStore; import org.drools.base.base.ClassObjectType; @@ -63,6 +66,9 @@ public AbstractHashTable.Index getIndexSupplier(IndexedValueReader fieldIndex) { @Test public void testSingleEntry() throws Exception { + BuildContext bctx = new BuildContext(new KnowledgeBaseImpl("01"), Collections.emptyList()); + MockLeftTupleSink sink = new MockLeftTupleSink(0, bctx); + final ReadAccessor extractor = store.getReader( Cheese.class, "type" ); @@ -84,7 +90,7 @@ public void testSingleEntry() throws Exception { assertThat(map.size()).isEqualTo(0); assertThat(map.getFirst(new LeftTuple( cheddarHandle1, - new MockLeftTupleSink(0), + sink, true ))).isNull(); final Cheese stilton1 = new Cheese( "stilton", @@ -104,14 +110,17 @@ public void testSingleEntry() throws Exception { stilton2 ); final Tuple tuple = map.getFirst( new LeftTuple( stiltonHandle2, - new MockLeftTupleSink(0), - true ) ); + sink, + true ) ); assertThat(tuple.getFactHandle()).isSameAs(stiltonRighTuple.getFactHandle()); assertThat(tuple.getNext()).isNull(); } @Test public void testTwoDifferentEntries() throws Exception { + BuildContext bctx = new BuildContext(new KnowledgeBaseImpl("01"), Collections.emptyList()); + MockLeftTupleSink sink = new MockLeftTupleSink(0, bctx); + final ReadAccessor extractor = store.getReader( Cheese.class, "type" ); @@ -150,8 +159,8 @@ public void testTwoDifferentEntries() throws Exception { final InternalFactHandle stiltonHandle2 = new DefaultFactHandle( 2, stilton2 ); Tuple tuple = map.getFirst( new LeftTuple( stiltonHandle2, - new MockLeftTupleSink(0), - true ) ); + sink, + true ) ); assertThat(tuple.getFactHandle()).isSameAs(stiltonHandle1); assertThat(tuple.getNext()).isNull(); @@ -160,8 +169,8 @@ public void testTwoDifferentEntries() throws Exception { final InternalFactHandle cheddarHandle2 = new DefaultFactHandle( 2, cheddar2 ); tuple = map.getFirst( new LeftTuple( cheddarHandle2, - new MockLeftTupleSink(0), - true ) ); + sink, + true ) ); assertThat(tuple.getFactHandle()).isSameAs(cheddarHandle1); assertThat(tuple.getNext()).isNull(); } @@ -214,8 +223,11 @@ public void testTwoEqualEntries() throws Exception { final InternalFactHandle stiltonHandle3 = new DefaultFactHandle( 4, stilton2 ); + BuildContext bctx = new BuildContext(new KnowledgeBaseImpl("01"), Collections.emptyList()); + MockLeftTupleSink sink = new MockLeftTupleSink(0, bctx); + final TupleImpl tuple = map.getFirst( new LeftTuple( stiltonHandle3, - new MockLeftTupleSink(0), + sink, true ) ); assertThat(tuple.getFactHandle()).isSameAs(stiltonHandle1); assertThat(tuple.getNext().getFactHandle()).isSameAs(stiltonHandle2); @@ -574,7 +586,9 @@ public void testEmptyIterator() { final InternalFactHandle stiltonHandle = new DefaultFactHandle( 2, stilton ); - assertThat(map.getFirst(new LeftTuple(stiltonHandle, new MockLeftTupleSink(0), true ))).isNull(); + BuildContext bctx = new BuildContext(new KnowledgeBaseImpl("01"), Collections.emptyList()); + MockLeftTupleSink sink = new MockLeftTupleSink(0, bctx); + assertThat(map.getFirst(new LeftTuple(stiltonHandle, sink, true ))).isNull(); } } From d7d149d523c7c1f6a2267fa17f64b51f383d1d25 Mon Sep 17 00:00:00 2001 From: Mark Proctor Date: Wed, 8 May 2024 16:22:20 +0100 Subject: [PATCH 2/5] Sequencing v1 --- .../org/drools/base/base/ValueResolver.java | 30 + .../base/definitions/rule/impl/RuleImpl.java | 2 +- .../org/drools/base/reteoo/NodeTypeEnums.java | 1 + .../main/java/org/drools/base}/time/Job.java | 2 +- .../org/drools/base}/time/JobContext.java | 19 +- .../drools/base/time/{impl => }/Timer.java | 4 +- .../drools/core/phreak/PropagationEntry.java | 44 ++ .../actions/AbstractPropagationEntry.java | 41 ++ .../org/drools/core/reteoo/DynamicFilter.java | 50 ++ .../core/reteoo/DynamicFilterProto.java | 21 + .../org/drools/core/reteoo/SignalAdapter.java | 25 + .../java/org/drools/core/reteoo/Sink.java | 0 .../reteoo/sequencing/DynamicFilters.java | 9 + .../core/reteoo/sequencing/Sequence.java | 657 ++++++++++++++++++ .../core/reteoo/sequencing/Sequencer.java | 72 ++ .../reteoo/sequencing/SequencerMemory.java | 37 + .../ConditionalSignalCounter.java | 108 +++ .../sequencing/signalprocessors/Gates.java | 22 + .../signalprocessors/LogicCircuit.java | 19 + .../signalprocessors/LogicGate.java | 412 +++++++++++ .../LogicGateOutputSignalProcessor.java | 66 ++ .../signalprocessors/SignalIndex.java | 23 + .../signalprocessors/SignalProcessor.java | 13 + .../signalprocessors/SignalStatus.java | 18 + .../TerminatingSignalProcessor.java | 27 + .../reteoo/sequencing/steps/AbstractStep.java | 51 ++ .../reteoo/sequencing/steps/ActionStep.java | 26 + .../sequencing/steps/AggregatorStep.java | 13 + .../sequencing/steps/LogicCircuitStep.java | 32 + .../reteoo/sequencing/steps/SequenceStep.java | 42 ++ .../core/reteoo/sequencing/steps/Step.java | 111 +++ .../drools/core/time/SchedulerService.java | 2 + .../org/drools/core/time/TimerService.java | 0 .../time/impl}/InternalSchedulerService.java | 4 +- .../time/impl/TimerJobFactoryManager.java | 5 +- .../core/time/impl/TimerJobInstance.java | 4 +- .../core/util/AbstractLinkedListNode.java | 0 .../drools/core/util/CircularArrayList.java | 91 +++ .../drools/core/util/DoubleLinkedEntry.java | 3 - .../org/drools/core/util/FastIterator.java | 0 .../java/org/drools/core/util/Iterator.java | 0 .../java/org/drools/core/util/LinkedList.java | 6 +- .../org/drools/core/util/LinkedListEntry.java | 0 .../drools/core/util/SingleLinkedEntry.java | 0 .../compiler/rule/builder/RuleBuilder.java | 2 +- .../core/common/AgendaGroupQueueImpl.java | 8 +- .../org/drools/core/common/ReteEvaluator.java | 15 - .../core/common/WorkingMemoryAction.java | 2 +- .../impl/WorkingMemoryReteExpireAction.java | 6 +- .../phreak/BuildtimeSegmentUtilities.java | 11 + .../core/phreak/PhreakNetworkNodeFactory.java | 3 + .../phreak/PhreakNetworkNodeFactoryImpl.java | 7 + .../drools/core/phreak/PhreakTimerNode.java | 23 +- .../drools/core/phreak/PropagationEntry.java | 483 ------------- .../core/phreak/ReactiveObjectUtil.java | 3 +- .../org/drools/core/phreak/RuleExecutor.java | 2 +- .../core/phreak/RuleNetworkEvaluator.java | 12 +- .../AbstractPartitionedPropagationEntry.java | 15 + .../drools/core/phreak/actions/Delete.java | 45 ++ .../core/phreak/actions/ExecuteQuery.java | 71 ++ .../drools/core/phreak/actions/Insert.java | 131 ++++ .../phreak/actions/PartitionedDelete.java | 43 ++ .../phreak/actions/PartitionedUpdate.java | 45 ++ .../actions/PropagationEntryWithResult.java | 30 + .../drools/core/phreak/actions/Update.java | 80 +++ .../drools/core/reteoo/AsyncReceiveNode.java | 6 +- ...positePartitionAwareObjectSinkAdapter.java | 6 +- .../drools/core/reteoo/EntryPointNode.java | 16 +- .../org/drools/core/reteoo/ObjectRouter.java | 214 ++++++ .../drools/core/reteoo/ObjectTypeNode.java | 14 +- .../org/drools/core/reteoo/SegmentMemory.java | 14 + .../org/drools/core/reteoo/SequenceNode.java | 507 ++++++++++++++ .../org/drools/core/reteoo/TimerNode.java | 4 +- .../org/drools/core/reteoo/TupleFactory.java | 6 + .../builder/NamedConsequenceBuilder.java | 2 +- .../core/reteoo/builder/NodeFactory.java | 2 +- .../core/reteoo/builder/PatternBuilder.java | 2 +- .../reteoo/builder/PhreakNodeFactory.java | 2 +- .../reteoo/builder/ReteooRuleBuilder.java | 2 +- .../core/reteoo/builder/TimerBuilder.java | 2 +- .../sequencing/SequencerMemoryImpl.java | 143 ++++ .../drools/core/rule/SlidingTimeWindow.java | 11 +- .../time/EnqueuedSelfRemovalJobContext.java | 8 +- .../java/org/drools/core/time/Scheduler.java | 2 + .../org/drools/core/time/SelfRemovalJob.java | 3 + .../core/time/SelfRemovalJobContext.java | 7 +- .../time/impl/CompositeMaxDurationTimer.java | 2 +- .../org/drools/core/time/impl/CronTimer.java | 2 +- .../core/time/impl/DefaultJobHandle.java | 2 +- .../impl/DefaultTimerJobFactoryManager.java | 5 +- .../time/impl/DefaultTimerJobInstance.java | 7 +- .../drools/core/time/impl/DurationTimer.java | 2 +- .../time/impl/ExpressionIntervalTimer.java | 2 +- .../drools/core/time/impl/IntervalTimer.java | 2 +- .../core/time/impl/JDKTimerService.java | 5 +- .../core/time/impl/PseudoClockScheduler.java | 9 +- ...eadSafeTrackableTimeJobFactoryManager.java | 2 +- .../impl/TrackableTimeJobFactoryManager.java | 5 +- .../core/time/impl/JDKTimerServiceTest.java | 7 +- .../time/impl/PseudoClockSchedulerTest.java | 9 +- .../kiesession/agenda/DefaultAgenda.java | 6 +- .../StatefulKnowledgeSessionForRHS.java | 6 + .../session/StatefulKnowledgeSessionImpl.java | 16 +- .../kiesession/ReteooWorkingMemoryTest.java | 4 +- .../MetricPhreakNetworkNodeFactoryImpl.java | 9 + .../phreak/PhreakSequenceNodeMetric.java | 34 + .../modelcompiler/KiePackagesBuilder.java | 2 +- .../persistence/jpa/JpaJDKTimerService.java | 6 +- .../jpa/JpaTimeJobFactoryManager.java | 6 +- .../persistence/jpa/JpaTimerJobInstance.java | 6 +- .../core/ReliableSessionInitializer.java | 5 +- .../impl/sessions/RuleUnitExecutorImpl.java | 10 +- .../protobuf/ProtobufOutputMarshaller.java | 2 +- .../protobuf/TimersOutputMarshaller.java | 2 +- .../WorkingMemoryReteAssertAction.java | 4 +- ...ProtobufWorkingMemoryReteAssertAction.java | 1 + ...haviorJobContextTimerOutputMarshaller.java | 2 +- .../ExpireJobContextTimerInputMarshaller.java | 2 +- ...ExpireJobContextTimerOutputMarshaller.java | 2 +- .../TimerNodeTimerOutputMarshaller.java | 2 +- .../compiler/command/PropagationListTest.java | 4 +- .../mvel/integrationtests/phreak/A.java | 6 + .../mvel/integrationtests/phreak/B.java | 22 +- .../mvel/integrationtests/phreak/C.java | 22 +- .../mvel/integrationtests/phreak/D.java | 99 +++ .../mvel/integrationtests/phreak/E.java | 16 + ...bstractPhreakSequencerSubsequenceTest.java | 83 +++ .../sequencing/CircularArrayListTest.java | 60 ++ .../sequencing/MultiInputNodeBuilder.java | 152 ++++ .../sequencing/PhreakSequencerActionTest.java | 149 ++++ ...akSequencerActivateDeactivateStepTest.java | 213 ++++++ .../PhreakSequencerAggregatorTest.java | 189 +++++ .../PhreakSequencerEventsMemoryTest.java | 156 +++++ .../PhreakSequencerLogicGateTest.java | 210 ++++++ .../PhreakSequencerSequenceLoopTest.java | 139 ++++ .../PhreakSequencerSequenceTimerTest.java | 136 ++++ ...akSequencerSignalProcessorCounterTest.java | 316 +++++++++ ...reakSequencerSignalProcessorTimerTest.java | 262 +++++++ .../PhreakSequencerSubsequenceLoopTest.java | 192 +++++ .../PhreakSequencerSubsequenceTest.java | 145 ++++ .../PhreakSequencerSubsequenceTimerTest.java | 207 ++++++ .../simple/BeliefSystemLogicalCallback.java | 5 +- .../api/runtime/rule/PropagationContext.java | 68 -- 143 files changed, 6431 insertions(+), 730 deletions(-) rename {drools-core/src/main/java/org/drools/core => drools-base/src/main/java/org/drools/base}/time/Job.java (96%) rename {drools-core/src/main/java/org/drools/core => drools-base/src/main/java/org/drools/base}/time/JobContext.java (65%) rename drools-base/src/main/java/org/drools/base/time/{impl => }/Timer.java (93%) create mode 100644 drools-base/src/main/java/org/drools/core/phreak/PropagationEntry.java create mode 100644 drools-base/src/main/java/org/drools/core/phreak/actions/AbstractPropagationEntry.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/DynamicFilter.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/DynamicFilterProto.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/SignalAdapter.java rename {drools-core => drools-base}/src/main/java/org/drools/core/reteoo/Sink.java (100%) create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/DynamicFilters.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequence.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequencer.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemory.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/ConditionalSignalCounter.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/Gates.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicCircuit.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGate.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGateOutputSignalProcessor.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalIndex.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalProcessor.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalStatus.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/TerminatingSignalProcessor.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AbstractStep.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/ActionStep.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AggregatorStep.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/LogicCircuitStep.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/SequenceStep.java create mode 100644 drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/Step.java rename {drools-core => drools-base}/src/main/java/org/drools/core/time/SchedulerService.java (95%) rename {drools-core => drools-base}/src/main/java/org/drools/core/time/TimerService.java (100%) rename {drools-core/src/main/java/org/drools/core/time => drools-base/src/main/java/org/drools/core/time/impl}/InternalSchedulerService.java (91%) rename {drools-core => drools-base}/src/main/java/org/drools/core/time/impl/TimerJobFactoryManager.java (92%) rename {drools-core => drools-base}/src/main/java/org/drools/core/time/impl/TimerJobInstance.java (93%) rename {drools-core => drools-base}/src/main/java/org/drools/core/util/AbstractLinkedListNode.java (100%) create mode 100644 drools-base/src/main/java/org/drools/core/util/CircularArrayList.java rename {drools-core => drools-base}/src/main/java/org/drools/core/util/DoubleLinkedEntry.java (93%) rename {drools-core => drools-base}/src/main/java/org/drools/core/util/FastIterator.java (100%) rename {drools-core => drools-base}/src/main/java/org/drools/core/util/Iterator.java (100%) rename {drools-core => drools-base}/src/main/java/org/drools/core/util/LinkedList.java (98%) rename {drools-core => drools-base}/src/main/java/org/drools/core/util/LinkedListEntry.java (100%) rename {drools-core => drools-base}/src/main/java/org/drools/core/util/SingleLinkedEntry.java (100%) delete mode 100644 drools-core/src/main/java/org/drools/core/phreak/PropagationEntry.java create mode 100644 drools-core/src/main/java/org/drools/core/phreak/actions/AbstractPartitionedPropagationEntry.java create mode 100644 drools-core/src/main/java/org/drools/core/phreak/actions/Delete.java create mode 100644 drools-core/src/main/java/org/drools/core/phreak/actions/ExecuteQuery.java create mode 100644 drools-core/src/main/java/org/drools/core/phreak/actions/Insert.java create mode 100644 drools-core/src/main/java/org/drools/core/phreak/actions/PartitionedDelete.java create mode 100644 drools-core/src/main/java/org/drools/core/phreak/actions/PartitionedUpdate.java create mode 100644 drools-core/src/main/java/org/drools/core/phreak/actions/PropagationEntryWithResult.java create mode 100644 drools-core/src/main/java/org/drools/core/phreak/actions/Update.java create mode 100644 drools-core/src/main/java/org/drools/core/reteoo/ObjectRouter.java create mode 100644 drools-core/src/main/java/org/drools/core/reteoo/SequenceNode.java create mode 100644 drools-core/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemoryImpl.java create mode 100644 drools-metric/src/main/java/org/drools/metric/phreak/PhreakSequenceNodeMetric.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/D.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/CircularArrayListTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java delete mode 100644 kie-api/src/main/java/org/kie/api/runtime/rule/PropagationContext.java diff --git a/drools-base/src/main/java/org/drools/base/base/ValueResolver.java b/drools-base/src/main/java/org/drools/base/base/ValueResolver.java index 1c1e3306ec7..f2aa60acae6 100644 --- a/drools-base/src/main/java/org/drools/base/base/ValueResolver.java +++ b/drools-base/src/main/java/org/drools/base/base/ValueResolver.java @@ -20,6 +20,11 @@ import org.drools.base.RuleBase; import org.drools.base.rule.accessor.GlobalResolver; +import org.drools.core.phreak.PropagationEntry; +import org.drools.core.time.TimerService; +import org.kie.api.runtime.KieSessionConfiguration; + +import java.util.function.Consumer; public interface ValueResolver { @@ -32,4 +37,29 @@ default Object getGlobal(String identifier) { GlobalResolver getGlobalResolver(); RuleBase getRuleBase(); + + void addPropagation(PropagationEntry propagationEntry); + + KieSessionConfiguration getKieSessionConfiguration(); + + default T as(Class t) { + return (T) this; + } + + default void setWorkingMemoryActionListener(Consumer listener) { + throw new UnsupportedOperationException(); + } + + default Consumer getWorkingMemoryActionListener() { + return null; + } + + default void onWorkingMemoryAction(PropagationEntry entry) { + Consumer listener = getWorkingMemoryActionListener(); + if (listener != null) { + listener.accept(entry); + } + } + + TimerService getTimerService(); } diff --git a/drools-base/src/main/java/org/drools/base/definitions/rule/impl/RuleImpl.java b/drools-base/src/main/java/org/drools/base/definitions/rule/impl/RuleImpl.java index 1a2add11c0a..e9f7f02535d 100644 --- a/drools-base/src/main/java/org/drools/base/definitions/rule/impl/RuleImpl.java +++ b/drools-base/src/main/java/org/drools/base/definitions/rule/impl/RuleImpl.java @@ -51,7 +51,7 @@ import org.drools.base.rule.accessor.Salience; import org.drools.base.rule.accessor.Wireable; import org.drools.base.rule.consequence.Consequence; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.util.StringUtils; import org.kie.api.definition.rule.Query; import org.kie.api.io.Resource; diff --git a/drools-base/src/main/java/org/drools/base/reteoo/NodeTypeEnums.java b/drools-base/src/main/java/org/drools/base/reteoo/NodeTypeEnums.java index ce509eb8516..0ed660c1572 100644 --- a/drools-base/src/main/java/org/drools/base/reteoo/NodeTypeEnums.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/NodeTypeEnums.java @@ -75,6 +75,7 @@ public class NodeTypeEnums { public static final int AsyncReceiveNode = (260 << shift) | TupleSourceMask | TupleSinkMask | TupleNodeMask | MemoryFactoryMask; public static final int FromNode = (270 << shift) | TupleSourceMask | TupleSinkMask | TupleNodeMask | MemoryFactoryMask; public static final int ReactiveFromNode = (280 << shift) | TupleSourceMask | TupleSinkMask | TupleNodeMask | MemoryFactoryMask; + public static final int SequenceNode = (290 << shift) | TupleSourceMask | TupleSinkMask | TupleNodeMask | MemoryFactoryMask; public static final int QueryElementNode = (300 << shift) | TupleSourceMask | TupleSinkMask | TupleNodeMask | MemoryFactoryMask; public static final int ConditionalBranchNode = (310 << shift) | TupleSourceMask | TupleSinkMask | TupleNodeMask | MemoryFactoryMask; diff --git a/drools-core/src/main/java/org/drools/core/time/Job.java b/drools-base/src/main/java/org/drools/base/time/Job.java similarity index 96% rename from drools-core/src/main/java/org/drools/core/time/Job.java rename to drools-base/src/main/java/org/drools/base/time/Job.java index cd086a06915..1325bc3d829 100644 --- a/drools-core/src/main/java/org/drools/core/time/Job.java +++ b/drools-base/src/main/java/org/drools/base/time/Job.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.time; +package org.drools.base.time; public interface Job { void execute(JobContext ctx); diff --git a/drools-core/src/main/java/org/drools/core/time/JobContext.java b/drools-base/src/main/java/org/drools/base/time/JobContext.java similarity index 65% rename from drools-core/src/main/java/org/drools/core/time/JobContext.java rename to drools-base/src/main/java/org/drools/base/time/JobContext.java index 07988d7c0c7..697eadaeb7b 100644 --- a/drools-core/src/main/java/org/drools/core/time/JobContext.java +++ b/drools-base/src/main/java/org/drools/base/time/JobContext.java @@ -16,15 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.time; +package org.drools.base.time; import java.io.Serializable; -import java.util.Optional; -import org.drools.base.time.JobHandle; -import org.drools.core.common.InternalKnowledgeRuntime; -import org.drools.core.common.InternalWorkingMemory; -import org.drools.core.common.ReteEvaluator; +import org.drools.base.base.ValueResolver; public interface JobContext extends Serializable { /** @@ -34,9 +30,10 @@ public interface JobContext extends Serializable { JobHandle getJobHandle(); - ReteEvaluator getReteEvaluator(); - - default Optional getInternalKnowledgeRuntime() { - return getReteEvaluator() instanceof InternalWorkingMemory ? Optional.ofNullable(((InternalWorkingMemory)getReteEvaluator()).getKnowledgeRuntime()) : Optional.empty(); - } + ValueResolver getValueResolver(); +// ReteEvaluator getReteEvaluator(); +// +// default Optional getInternalKnowledgeRuntime() { +// return getReteEvaluator() instanceof InternalWorkingMemory ? Optional.ofNullable(((InternalWorkingMemory)getReteEvaluator()).getKnowledgeRuntime()) : Optional.empty(); +// } } diff --git a/drools-base/src/main/java/org/drools/base/time/impl/Timer.java b/drools-base/src/main/java/org/drools/base/time/Timer.java similarity index 93% rename from drools-base/src/main/java/org/drools/base/time/impl/Timer.java rename to drools-base/src/main/java/org/drools/base/time/Timer.java index 429dade8776..4248694e7fc 100644 --- a/drools-base/src/main/java/org/drools/base/time/impl/Timer.java +++ b/drools-base/src/main/java/org/drools/base/time/Timer.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.base.time.impl; +package org.drools.base.time; import java.io.Serializable; @@ -25,8 +25,6 @@ import org.drools.base.rule.Declaration; import org.drools.base.rule.RuleComponent; import org.drools.base.rule.RuleConditionElement; -import org.drools.base.time.JobHandle; -import org.drools.base.time.Trigger; import org.kie.api.runtime.Calendars; public interface Timer extends Serializable, RuleComponent, RuleConditionElement { diff --git a/drools-base/src/main/java/org/drools/core/phreak/PropagationEntry.java b/drools-base/src/main/java/org/drools/core/phreak/PropagationEntry.java new file mode 100644 index 00000000000..97aafe8aa34 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/phreak/PropagationEntry.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.core.phreak; + +import org.drools.base.base.ValueResolver; + +public interface PropagationEntry { + + default void execute(T t) { + internalExecute(t); + t.onWorkingMemoryAction(this); + } + + void internalExecute(T t); + + PropagationEntry getNext(); + void setNext(PropagationEntry next); + + boolean requiresImmediateFlushing(); + + boolean isCalledFromRHS(); + + boolean isPartitionSplittable(); + PropagationEntry getSplitForPartition(int partitionNr); + + boolean defersExpiration(); + +} diff --git a/drools-base/src/main/java/org/drools/core/phreak/actions/AbstractPropagationEntry.java b/drools-base/src/main/java/org/drools/core/phreak/actions/AbstractPropagationEntry.java new file mode 100644 index 00000000000..d9867249b87 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/phreak/actions/AbstractPropagationEntry.java @@ -0,0 +1,41 @@ +package org.drools.core.phreak.actions; + +import org.drools.base.base.ValueResolver; +import org.drools.core.phreak.PropagationEntry; + +public abstract class AbstractPropagationEntry implements PropagationEntry { + protected PropagationEntry next; + + public void setNext(PropagationEntry next) { + this.next = next; + } + + public PropagationEntry getNext() { + return next; + } + + @Override + public boolean requiresImmediateFlushing() { + return false; + } + + @Override + public boolean isCalledFromRHS() { + return false; + } + + @Override + public boolean isPartitionSplittable() { + return false; + } + + @Override + public boolean defersExpiration() { + return false; + } + + @Override + public PropagationEntry getSplitForPartition(int partitionNr) { + throw new UnsupportedOperationException(); + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/DynamicFilter.java b/drools-base/src/main/java/org/drools/core/reteoo/DynamicFilter.java new file mode 100644 index 00000000000..6863ba9956b --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/DynamicFilter.java @@ -0,0 +1,50 @@ +package org.drools.core.reteoo; + +import org.drools.base.base.ValueResolver; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.util.AbstractLinkedListNode; +import org.drools.core.util.LinkedList; +import org.kie.api.runtime.rule.FactHandle; + +public class DynamicFilter extends AbstractLinkedListNode { + private AlphaNodeFieldConstraint constraint; + private LinkedList signalAdapters; + private int activeFilterIndex; + + public DynamicFilter(DynamicFilterProto proto) { + this.constraint = proto.getConstraint(); + this.activeFilterIndex = proto.getFilterIndex(); + this.signalAdapters = new LinkedList<>(); + } + + public AlphaNodeFieldConstraint getConstraint() { + return constraint; + } + + public int getActiveFilterIndex() { + return activeFilterIndex; + } + + public void addSignalAdapter(SignalAdapter signalAdapter) { + signalAdapters.add(signalAdapter); + } + + public void removeSignalAdapter(SignalAdapter signalAdapter) { + signalAdapters.remove(signalAdapter); + } + + public LinkedList getSignalAdapters() { + return signalAdapters; + } + + public void assertObject(final FactHandle factHandle, + final ValueResolver valueResolver) { + System.out.println("true : " + factHandle.getObject()); + + if (constraint.isAllowed(factHandle, valueResolver)) { + for (SignalAdapter signal = signalAdapters.getFirst(); signal != null; signal = signal.getNext()) { + signal.receive(valueResolver, factHandle); + } + } + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/DynamicFilterProto.java b/drools-base/src/main/java/org/drools/core/reteoo/DynamicFilterProto.java new file mode 100644 index 00000000000..68f8a86a86b --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/DynamicFilterProto.java @@ -0,0 +1,21 @@ +package org.drools.core.reteoo; + +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; + +public class DynamicFilterProto { + private AlphaNodeFieldConstraint constraint; + private int filterIndex; + + public DynamicFilterProto(AlphaNodeFieldConstraint constraint, int filterIndex) { + this.constraint = constraint; + this.filterIndex = filterIndex; + } + + public AlphaNodeFieldConstraint getConstraint() { + return constraint; + } + + public int getFilterIndex() { + return filterIndex; + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/SignalAdapter.java b/drools-base/src/main/java/org/drools/core/reteoo/SignalAdapter.java new file mode 100644 index 00000000000..85e4f1a5ba8 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/SignalAdapter.java @@ -0,0 +1,25 @@ +package org.drools.core.reteoo; + +import org.drools.base.base.ValueResolver; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.signalprocessors.SignalProcessor; +import org.drools.core.reteoo.sequencing.signalprocessors.SignalStatus; +import org.drools.core.util.AbstractLinkedListNode; +import org.kie.api.runtime.rule.FactHandle; + +public class SignalAdapter extends AbstractLinkedListNode { + private SignalProcessor output; + private int signalBitIndex; + private SequenceMemory memory; + + public SignalAdapter(SignalProcessor output, int signalBitIndex, SequenceMemory memory) { + this.output = output; + this.signalBitIndex = signalBitIndex; + this.memory = memory; + } + + public void receive(ValueResolver reteEvaluator, FactHandle factHandle) { + memory.getSequencerMemory().getEvents().add(factHandle); + output.consume(signalBitIndex, SignalStatus.MATCHED, memory, reteEvaluator); + } +} diff --git a/drools-core/src/main/java/org/drools/core/reteoo/Sink.java b/drools-base/src/main/java/org/drools/core/reteoo/Sink.java similarity index 100% rename from drools-core/src/main/java/org/drools/core/reteoo/Sink.java rename to drools-base/src/main/java/org/drools/core/reteoo/Sink.java diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/DynamicFilters.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/DynamicFilters.java new file mode 100644 index 00000000000..82461680573 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/DynamicFilters.java @@ -0,0 +1,9 @@ +package org.drools.core.reteoo.sequencing; + +import org.drools.core.reteoo.DynamicFilter; + +public interface DynamicFilters { + DynamicFilter getActiveDynamicFilter(int filterIndex); + + void removeActiveFilter(DynamicFilter filter); +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequence.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequence.java new file mode 100644 index 00000000000..554938a3595 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequence.java @@ -0,0 +1,657 @@ +package org.drools.core.reteoo.sequencing; + +import org.drools.base.base.ValueResolver; +import org.drools.base.rule.Declaration; +import org.drools.base.rule.RuleConditionElement; +import org.drools.base.time.JobHandle; +import org.drools.base.time.Trigger; +import org.drools.base.time.Timer; +import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.core.reteoo.DynamicFilter; +import org.drools.core.reteoo.SignalAdapter; +import org.drools.core.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.signalprocessors.SignalStatus; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.steps.LogicCircuitStep; +import org.drools.core.reteoo.sequencing.steps.Step.StepFactory; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Predicate; + +public class Sequence implements RuleConditionElement { + private final int sequenceIndex; + + private Step[] steps; + + private LogicGate[] gates; + + private SequenceController controller; + + private Consumer onStart; + private Consumer onEnd; + + private int outputSize; + + public Sequence(int sequenceIndex, StepFactory... stepFactories) { + this.steps = new Step[stepFactories.length]; + for ( int i = 0; i < steps.length; i++ ) { + steps[i] = stepFactories[i].createStep(i,this); + } + this.sequenceIndex = sequenceIndex; + populateLogicGates(); + controller = new DefaultController(); + } + + public int getOutputSize() { + return outputSize; + } + + public void setOutputSize(int outputSize) { + this.outputSize = outputSize; + } + + public Consumer getOnStart() { + return onStart; + } + + public void setOnStart(Consumer onStart) { + this.onStart = onStart; + } + + public Consumer getOnEnd() { + return onEnd; + } + + public void setOnEnd(Consumer onEnd) { + this.onEnd = onEnd; + } + + public void populateLogicGates() { + List list = new ArrayList<>(); + for (Step step : getSteps()) { + if ( step instanceof LogicCircuitStep) { + Arrays.stream(((LogicCircuitStep) step).getCircuit().getGates()).forEach( g -> list.add(g)); + } + } + + gates = list.toArray(new LogicGate[0]); + } + + public int getSequenceIndex() { + return sequenceIndex; + } + + public Step[] getSteps() { + return steps; + } + + public void setSteps(Step[] steps) { + this.steps = steps; + } + + public LogicGate[] getGates() { + return gates; + } + + + public SequenceController getController() { + return controller; + } + + public void setController(SequenceController controller) { + this.controller = controller; + } + + @Override + public Map getInnerDeclarations() { + return Map.of(); + } + + @Override + public Map getOuterDeclarations() { + return Map.of(); + } + + @Override + public Declaration resolveDeclaration(String identifier) { + return null; + } + + @Override + public RuleConditionElement clone() { + return null; + } + + @Override + public List getNestedElements() { + return List.of(); + } + + @Override + public boolean isPatternScopeDelimiter() { + return false; + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + } + + public void start(SequencerMemory memory, ValueResolver valueResolver) { + SequenceMemory sequenceMemory = memory.getSequenceMemory(this); + memory.pushSequence(sequenceMemory); + sequenceMemory.setStep(0); + getSteps()[0].activate(sequenceMemory, valueResolver); + if(onStart != null) { + onStart.accept(sequenceMemory); + } + controller.start(sequenceMemory, valueResolver); + } + + private void restart(SequenceMemory sequenceMemory, ValueResolver valueResolver) { + sequenceMemory.setStep(0); + sequenceMemory.getSequencerMemory().getEvents().resetHeadByOffset(sequenceMemory.getSequencerMemory().getEvents().size() - sequenceMemory.getEventsStartPosition()); + getSteps()[0].activate(sequenceMemory, valueResolver); + } + + public void next(SequenceMemory sequenceMemory, ValueResolver valueResolver) { + int step = sequenceMemory.getStep(); + + sequenceMemory.getSequence().getSteps()[step].deactivate(sequenceMemory, valueResolver); + step = sequenceMemory.incrementStep(); + + if (step < sequenceMemory.getSequence().getSteps().length) { + sequenceMemory.getSequence().getSteps()[step].activate(sequenceMemory, valueResolver); + } else { + if(onEnd != null) { + onEnd.accept(sequenceMemory); + } + controller.end(sequenceMemory, valueResolver); + } + } + + public interface SequenceController { + default void start(SequenceMemory memory, ValueResolver valueResolver) { + + } + + default void restart(SequenceMemory memory, ValueResolver valueResolver) { + + } + + void end(SequenceMemory memory, ValueResolver valueResolver); + } + + public static class DefaultController implements SequenceController { + private static final DefaultController INSTANCE = new DefaultController(); + + public static DefaultController getINSTANCE() { + return INSTANCE; + } + + @Override + public void end(SequenceMemory sequenceMemory, ValueResolver valueResolver) { + SequencerMemory sequencerMemory = sequenceMemory.getSequencerMemory(); + sequencerMemory.popSequence(); // pop is here, but the push was in the start step + sequencerMemory.getSequencer().next(sequencerMemory, valueResolver); + } + + @Override + public String toString() { + return "DefaultController{}"; + } + } + + public static class LoopController implements SequenceController { + private final Predicate predicate; + + public LoopController(Predicate predicate) { + this.predicate = predicate; + } + + @Override + public void end(SequenceMemory sequenceMemory, ValueResolver valueResolver) { + int counts = sequenceMemory.getCount(); + boolean restart = predicate.test(sequenceMemory); + sequenceMemory.setCount(counts+1); + SequencerMemory sequencerMemory = sequenceMemory.getSequencerMemory(); + if (restart) { + sequenceMemory.getSequence().restart(sequenceMemory, valueResolver); + } else { + sequencerMemory.popSequence(); // pop is here, but the push was in the start step + sequencerMemory.getSequencer().next(sequencerMemory, valueResolver); + } + } + + @Override + public String toString() { + return "LoopController{}"; + } + } + + public static class TimoutController implements SequenceController { + private final Timer timer; + private final DefaultController defaultController = DefaultController.getINSTANCE(); + + public TimoutController(Timer timer) { + this.timer = timer; + } + + @Override + public void start(SequenceMemory memory, ValueResolver valueResolver) { + defaultController.start(memory, valueResolver); + Trigger trigger = timer.createTrigger(valueResolver.getTimerService().getCurrentTime(), null, null); + SequenceTimerJobContext ctx = new SequenceTimerJobContext(SequenceTimerJobContext.TIMEOUT, trigger, valueResolver, memory); + + JobHandle jobHandle = valueResolver.getTimerService().scheduleJob(SequenceJob.getINSTANCE(), ctx, trigger); + memory.setJobHandle(jobHandle); + System.out.println("handle created"); + } + + @Override + public void restart(SequenceMemory memory, ValueResolver valueResolver) { + defaultController.restart(memory, valueResolver); + valueResolver.getTimerService().removeJob(memory.getJobHandle()); + } + + @Override + public void end(SequenceMemory memory, ValueResolver valueResolver) { + defaultController.end(memory, valueResolver); + valueResolver.getTimerService().removeJob(memory.getJobHandle()); + memory.setJobHandle(null); + } + + @Override + public String toString() { + return "TimoutController{" + + "timer=" + timer + + '}'; + } + } + + public static class CompositeController implements SequenceController { + private final SequenceController[] controllers; + + public CompositeController(SequenceController... controllers) { + this.controllers = controllers; + } + + @Override + public void start(SequenceMemory memory, ValueResolver valueResolver) { + for ( SequenceController controller : controllers ) { + controller.start(memory, valueResolver); + } + } + + @Override + public void restart(SequenceMemory memory, ValueResolver valueResolver) { + for ( SequenceController controller : controllers ) { + controller.restart(memory, valueResolver); + } + } + + @Override + public void end(SequenceMemory memory, ValueResolver valueResolver) { + for ( SequenceController controller : controllers ) { + controller.end(memory, valueResolver); + } + } + } + + + public static class SequenceJob + implements + Job { + private static final SequenceJob INSTANCE = new SequenceJob(); + + public static SequenceJob getINSTANCE() { + return INSTANCE; + } + + public void execute(JobContext ctx) { + SequenceTimerJobContext timerJobCtx = (SequenceTimerJobContext) ctx; + ValueResolver valueResolver = timerJobCtx.getValueResolver(); + System.out.println("add propagation"); + valueResolver.addPropagation( new SequenceTimerAction(timerJobCtx )); + } + } + + public static class SequenceTimerJobContext + implements + JobContext { + private static final int DELAY = 0; + private static final int TIMEOUT = 1; + + private JobHandle jobHandle; + private final Trigger trigger; + private final ValueResolver valueResolver; + + private final SequenceMemory sequenceMemory; + + private final int actionType; + + public SequenceTimerJobContext(int actionType, Trigger trigger, ValueResolver valueResolver, SequenceMemory sequenceMemory) { + this.trigger = trigger; + this.valueResolver = valueResolver; + this.sequenceMemory = sequenceMemory; + this.actionType = actionType; + } + + public JobHandle getJobHandle() { + return this.jobHandle; + } + + @Override + public ValueResolver getValueResolver() { + return valueResolver; + } + + public void setJobHandle(JobHandle jobHandle) { + this.jobHandle = jobHandle; + } + + public Trigger getTrigger() { + return trigger; + } + + public SequenceMemory getSequenceMemory() { + return sequenceMemory; + } + + public int getActionType() { + return actionType; + } + } + + public static class SequenceTimerAction extends AbstractPropagationEntry { + + private final SequenceTimerJobContext jobCtx; + + private SequenceTimerAction(SequenceTimerJobContext jobCtx) { + this.jobCtx = jobCtx; + } + + @Override + public boolean requiresImmediateFlushing() { + return true; + } + + @Override + public void internalExecute(final ValueResolver reteEvaluator) { + execute( reteEvaluator, false ); + } + + public void execute( final ValueResolver reteEvaluator, boolean needEvaluation ) { + SequenceMemory sequenceMemory = jobCtx.getSequenceMemory(); + + switch (jobCtx.getActionType()) { + case SequenceTimerJobContext.DELAY: +// if (status == SignalStatus.MATCHED) { +// // transition +// gate.propapate(sequencerMemory, reteEvaluator, status); +// System.out.println("1"); +// } else { +// // fail +//// sequencerMemory.getNode().getSequencer().fail(sequencerMemory); +// System.out.println("2"); +// } + System.out.println("1"); + break; + case SequenceTimerJobContext.TIMEOUT: + // fail, if not already transitioned +// if (status != SignalStatus.MATCHED) { +// // fail +// sequencerMemory.getNode().getSequencer().fail(sequencerMemory); + sequenceMemory.getSequence().fail(sequenceMemory, reteEvaluator); + + System.out.println("2"); +// } + break; + } + } + } + + private void fail(SequenceMemory sequenceMemory, ValueResolver valueResolver) { + int index = sequenceMemory.getStep(); + Step step = sequenceMemory.getSequence().getSteps()[index]; + step.onFail(sequenceMemory, valueResolver); + } + + public static class SequenceMemory { + private final Sequence sequence; + + private int step; + + private int count; + + private final SequencerMemory sequencerMemory; + + private final SignalAdapter[] signalAdapters; + + private final SignalAdapter[] activeSignalAdapters; + + private final long[] gateMemory; + + private final long[] counterMemories; + + private JobHandle[] jobHandles; + + private JobHandle jobHandle; + + private final SignalStatus[] signalStatuses; + + private int eventsStartPosition; + + public SequenceMemory(SequencerMemory sequencerMemory, Sequence sequence, + SignalAdapter[] signalAdapters, SignalAdapter[] activeSignalAdapters, + long[] gateMemory, long[] counterMemories) { + this.sequencerMemory = sequencerMemory; + this.sequence = sequence; + this.signalAdapters = signalAdapters; + this.activeSignalAdapters = activeSignalAdapters; + this.gateMemory = gateMemory; + this.counterMemories = counterMemories; + this.signalStatuses = new SignalStatus[gateMemory.length + counterMemories.length]; + } + + + public Sequence getSequence() { + return sequence; + } + + public SequencerMemory getSequencerMemory() { + return sequencerMemory; + } + + + public SignalStatus getCounterSignalStatus(int index) { + return signalStatuses[gateMemory.length + index]; + } + + public void setCounterSignalStatus(int index, SignalStatus status) { + signalStatuses[gateMemory.length + index] = status; + } + + + public SignalStatus getLogicGateSignalStatus(int index) { + return signalStatuses[index]; + } + + public SignalStatus[] getLogicGateSignalStatus() { + return signalStatuses; + } + + public void setLogicGateSignalStatus(int index, SignalStatus status) { + signalStatuses[index] = status; + } + + public SignalAdapter[] getSignalAdapters() { + return signalAdapters; + } + + public SignalAdapter[] getActiveSignalAdapters() { + return activeSignalAdapters; + } + + public long[] getLogicGateMemory() { + return gateMemory; + } + + public long[] getCounterMemories() { + return counterMemories; + } + + public JobHandle[] getJobHandles() { + return jobHandles; + } + + public JobHandle getJobHandle() { + return jobHandle; + } + + public void setJobHandle(JobHandle jobHandle) { + this.jobHandle = jobHandle; + } + + public SignalStatus[] getSignalStatuses() { + return signalStatuses; + } + + public int incrementStep() { + return ++step; + } + + public int getStep() { + return step; + } + + public void setStep(int step) { + this.step = step; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public int getEventsStartPosition() { + return eventsStartPosition; + } + + public void setEventsStartPosition(int eventsStartPosition) { + this.eventsStartPosition = eventsStartPosition; + } + + public SignalAdapter activateSignalAdapter(int filterIndex, LogicGate gate, int signalAdapterIndex, int signalBitIndex) { + if (activeSignalAdapters[signalAdapterIndex] != null) { + throw new RuntimeException("Defensive coding, this should not be re-entrant"); + } + + SignalAdapter signalAdapter = signalAdapters[signalAdapterIndex]; + + if (signalAdapter == null) { + ConditionalSignalCounter counter = null; + for ( ConditionalSignalCounter c : gate.getInputSignalCounters()) { + if ( c.getSignalIndex() == signalAdapterIndex) { + counter = c; + break; + } + } + signalAdapter = new SignalAdapter(counter == null ? gate : counter, signalBitIndex, this); + signalAdapters[signalAdapterIndex] = signalAdapter; + } + + activeSignalAdapters[signalAdapterIndex] = signalAdapter; + + DynamicFilter filter = sequencerMemory.getActiveDynamicFilter(filterIndex); + filter.addSignalAdapter(signalAdapter); + + return signalAdapter; + } + + public void setJobHandle(int index, JobHandle handle) { + if (jobHandles == null) { + // lazily create + jobHandles = new JobHandle[gateMemory.length]; // each gate can potentially have a job handle + } + jobHandles[index] = handle; + } + + + public JobHandle getJobHandle(int index) { + return jobHandles != null ? jobHandles[index] : null; + } + + public void deactivateSignalAdapter(int filterIndex, LogicGate gate, int signalAdapterIndex) { + SignalAdapter signalAdapter = activeSignalAdapters[signalAdapterIndex]; + activeSignalAdapters[signalAdapterIndex] = null; + + DynamicFilter filter = sequencerMemory.getActiveDynamicFilter(filterIndex); + filter.removeSignalAdapter(signalAdapter); + + if (filter.getSignalAdapters().isEmpty()) { + sequencerMemory.removeActiveFilter(filter); + } + } + + public void resetLogicGateMemory(int gateIndex, ValueResolver valueResolver) { + gateMemory[gateIndex] = 0; + signalStatuses[gateIndex] = null; + } + + public void resetSignalCounterMemory(int counterIndex) { + signalStatuses[gateMemory.length + counterIndex] = null; + counterMemories[counterIndex] = 0; + } + + public void cancelJobHandle(int gateIndex, ValueResolver valueResolver) { + if (jobHandles != null) { + JobHandle handle = jobHandles[gateIndex]; + valueResolver.getTimerService().removeJob(handle); + jobHandles[gateIndex] = null; + System.out.println("Job handle cancelled: " + handle); + } + } + + public void clearJobHandle(int gateIndex, ValueResolver valueResolver) { + jobHandles[gateIndex] = null; + System.out.println("Job handle cleared: "); + } + + @Override + public String toString() { + return "SequenceMemory{" + + "sequence=" + sequence.getSequenceIndex() + + ", step=" + step + + ", count=" + count + + '}'; + } + } + + @Override + public String toString() { + return "Sequence{" + + "sequenceIndex=" + sequenceIndex + + ", steps=" + Arrays.toString(steps) + + ", controller=" + controller + + '}'; + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequencer.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequencer.java new file mode 100644 index 00000000000..9ec79416b35 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequencer.java @@ -0,0 +1,72 @@ +package org.drools.core.reteoo.sequencing; + +import org.drools.base.base.ValueResolver; +import org.drools.base.reteoo.BaseTuple; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.steps.SequenceStep; + +import java.util.ArrayList; +import java.util.List; + +public class Sequencer { + + private final Sequence sequence; + + private final Sequence[] sequencences; + + public Sequencer(Sequence sequence) { + this.sequence = sequence; + this.sequencences = populateSequences(sequence, new ArrayList<>()).stream().toArray(Sequence[]::new); + } + + public static List populateSequences(Sequence sequence, List list) { + list.add(sequence); + for (Step step : sequence.getSteps()) { + if (step instanceof SequenceStep) { + populateSequences(((SequenceStep)step).getSequence(), list); + } + } + + return list; + } + + public Sequence[] getSequencences() { + return sequencences; + } + + public void start(SequencerMemory memory, ValueResolver valueResolver) { + sequence.start(memory, valueResolver); + } + + public void stop(SequencerMemory memory, ValueResolver valueResolver) { + // deactive each active sequence on the stack. + ArrayList stack = memory.getSequenceStack(); + for (int i = stack.size()-1; i >= 0; i--) { + SequenceMemory sequenceMemory = stack.get(i); + sequenceMemory.getSequence().getSteps()[sequenceMemory.getStep()].deactivate(sequenceMemory, valueResolver); + } + stack.clear(); + } + + public void next(SequencerMemory sequencerMemory, ValueResolver valueResolver) { + SequenceMemory sequenceMemory = sequencerMemory.getCurrentSequence(); + if (sequenceMemory != null) { + sequenceMemory.getSequence().next(sequenceMemory, valueResolver); + } else { + // the root sequence has completed + sequencerMemory.match(); + } + } + + public void fail(SequenceMemory memory) { + //node.fail(memory); + // TODO reset all memory + } + + public Sequence getSequence() { + return sequence; + } + + +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemory.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemory.java new file mode 100644 index 00000000000..1b5c7225eca --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemory.java @@ -0,0 +1,37 @@ +package org.drools.core.reteoo.sequencing; + +import org.drools.base.reteoo.BaseTuple; +import org.drools.core.reteoo.DynamicFilter; +import org.drools.core.reteoo.Sink; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.util.CircularArrayList; + +import java.util.ArrayList; + +public interface SequencerMemory { + BaseTuple getLeftTuple(); + + CircularArrayList getEvents(); + + Sink getSink(); + + Sequencer getSequencer(); + + SequenceMemory getCurrentSequence(); + + SequenceMemory popSequence(); + + void pushSequence(SequenceMemory sequenceMemory); + + int getCurrentStep(); + + ArrayList getSequenceStack(); + + SequenceMemory getSequenceMemory(Sequence sequence); + + void match(); + + DynamicFilter getActiveDynamicFilter(int filterIndex); + + void removeActiveFilter(DynamicFilter filter); +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/ConditionalSignalCounter.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/ConditionalSignalCounter.java new file mode 100644 index 00000000000..70d9ed1ca6f --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/ConditionalSignalCounter.java @@ -0,0 +1,108 @@ +package org.drools.core.reteoo.sequencing.signalprocessors; + +import org.drools.base.base.ValueResolver; +import org.drools.base.util.index.ConstraintTypeOperator; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; + +import java.util.function.Consumer; +import java.util.function.LongPredicate; + +public class ConditionalSignalCounter extends SignalProcessor { + private final int signalIndex; + private final int counterIndex; + private final LongPredicate constraint; + + private SignalProcessor output; + + public ConditionalSignalCounter(int signalIndex, int counterIndex, LongPredicate constraint) { + this.signalIndex = signalIndex; + this.counterIndex = counterIndex; + this.constraint = constraint; + } + + public ConditionalSignalCounter(int signalIndex, int counterIndex, ConstraintTypeOperator operator, long cardinal) { + this.signalIndex = signalIndex; + this.counterIndex = counterIndex; + this.constraint = c -> { + switch (operator) { + case EQUAL: + return c == cardinal; + case NOT_EQUAL: + return c != cardinal; + case GREATER_THAN: + return c > cardinal; + case GREATER_OR_EQUAL: + return c >= cardinal; + case LESS_THAN: + return c < cardinal; + case LESS_OR_EQUAL: + return c <= cardinal; + + } + throw new IllegalStateException("Unknown operator: " + operator); + }; + } + + public int getSignalIndex() { + return signalIndex; + } + + public int getCounterIndex() { + return counterIndex; + } + + public SignalProcessor getOutput() { + return output; + } + + public void setOutput(SignalProcessor output) { + this.output = output; + } + + @Override + public void consume(SignalStatus incommingSignalStatus, SequenceMemory memory, ValueResolver valueResolver) { + consume(incommingSignalStatus, memory, + (SignalStatus status) -> output.consume(status, memory, valueResolver)); + } + + @Override + public void consume(int signalBitIndex, SignalStatus incommingSignalStatus, SequenceMemory memory, ValueResolver valueResolver) { + consume(incommingSignalStatus, memory, + (SignalStatus status) -> output.consume(signalBitIndex, incommingSignalStatus, memory, valueResolver)); + } + + private void consume(SignalStatus inputSignalStatus, SequenceMemory memory, Consumer propagator) { + SignalStatus status = memory.getCounterSignalStatus(counterIndex); + + SignalStatus priorStatus = status; + long originalCount = memory.getCounterMemories()[counterIndex]; + long newCount = ++originalCount; + memory.getCounterMemories()[counterIndex] = newCount; + + boolean matched = constraint.test(newCount); + if (matched) { + status = SignalStatus.MATCHED; + } else if (priorStatus == SignalStatus.MATCHED) { + // was matched, now unmatched, so it has failed. + status = SignalStatus.FAILED; + } + + memory.setCounterSignalStatus(counterIndex, status); + + if (status == SignalStatus.FAILED) { + memory.getSequencerMemory().getSequencer().fail(memory); + } else if (priorStatus != status) { + propagator.accept(status); + } + } + + LongPredicate ONE = c -> c == 1; + + LongPredicate NONE = c -> c == 0; + + LongPredicate ANY = c -> true; + + public void reset(SequenceMemory memory, ValueResolver valueResolver) { + memory.resetSignalCounterMemory(counterIndex); + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/Gates.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/Gates.java new file mode 100644 index 00000000000..3480b69f33b --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/Gates.java @@ -0,0 +1,22 @@ +package org.drools.core.reteoo.sequencing.signalprocessors; + +public class Gates { + public static boolean and(long a, long b) {return a == b;} + + public static boolean or(long a, long b) {return (a & b) > 0;} + + + public static boolean nor(long a, long b) {return (a | b) == 0;} + + public static boolean nand(long a, long b) {return (a & b) == 0;} + + public static boolean xor(long a, long b) { + long v = a & b; + return v > 0 && v != b && (v & -v) == 0; + } + + public static boolean xnor(long a, long b) { + long v = a & b; + return v == 0 || v == b; + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicCircuit.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicCircuit.java new file mode 100644 index 00000000000..4862c9d72d2 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicCircuit.java @@ -0,0 +1,19 @@ +package org.drools.core.reteoo.sequencing.signalprocessors; + +public class LogicCircuit { + + private final LogicGate[] gates; + + public LogicCircuit(LogicGate... gates) { + this.gates = gates; + } + + public LogicGate[] getGates() { + return gates; + } + + public interface LongBiPredicate { + boolean test(long a, long b); + } + +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGate.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGate.java new file mode 100644 index 00000000000..b55f4c1b76d --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGate.java @@ -0,0 +1,412 @@ +package org.drools.core.reteoo.sequencing.signalprocessors; + +import org.drools.base.base.ValueResolver; +import org.drools.base.time.JobHandle; +import org.drools.base.time.Trigger; +import org.drools.base.time.Timer; +import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit.LongBiPredicate; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; + +public class LogicGate extends SignalProcessor { + protected long allMatched; + + private SignalProcessor output; + + private final LongBiPredicate predicate; + + private final int gateIndex; + + private LogicGate[] inputGates = EMPTY_INPUT_GATES; + + private final int[] filterIndexes; + + private int[] signalAdapterIndexes; + + private static final LogicGate[] EMPTY_INPUT_GATES = new LogicGate[0]; + + private static final ConditionalSignalCounter[] EMPTY_CONDITIONAL_SIGNAL_COUNTERS = new ConditionalSignalCounter[0]; + + private ConditionalSignalCounter[] inputSignalCounters = EMPTY_CONDITIONAL_SIGNAL_COUNTERS; + + private PropagationTimer propagationTimer; + + public LogicGate(LongBiPredicate predicate, int gateIndex, int[] filterIndexes, int[] signalAdapterIndexes, int nbrOfInputGates) { + this.predicate = predicate; + + this.filterIndexes = filterIndexes; + this.signalAdapterIndexes = signalAdapterIndexes; + + for (int i = 0; i < (signalAdapterIndexes.length + nbrOfInputGates); i++) { + allMatched = allMatched | (1L << i); + } + + this.gateIndex = gateIndex; + } + + public int getGateIndex() { + return gateIndex; + } + + public int[] getFilterIndexes() { + return filterIndexes; + } + + public PropagationTimer getPropagationTimer() { + return propagationTimer; + } + + public void setPropagationTimer(PropagationTimer propagationTimer) { + this.propagationTimer = propagationTimer; + } + + public int[] getSignalAdapterIndexes() { + return signalAdapterIndexes; + } + + public void setSignalAdapterIndexes(int[] signalAdapterIndexes) { + this.signalAdapterIndexes = signalAdapterIndexes; + } + + public LogicGate[] getInputGates() { + return inputGates; + } + + public void setInputGates(LogicGate... inputGates) { + this.inputGates = inputGates; + } + + public ConditionalSignalCounter[] getInputSignalCounters() { + return inputSignalCounters; + } + + public void setInputSignalCounters(ConditionalSignalCounter[] inputSignalCounters) { + this.inputSignalCounters = inputSignalCounters; + } + + public SignalProcessor getOutput() { + return output; + } + + public void setOutput(SignalProcessor output) { + this.output = output; + } + + @Override + public void consume(SignalStatus signalStatus, SequenceMemory memory, ValueResolver valueResolver) { + throw new UnsupportedOperationException(); + } + + @Override + public void consume(int signalBitIndex, SignalStatus signalStatus, SequenceMemory memory, ValueResolver valueResolver) { + SignalStatus status = memory.getLogicGateSignalStatus(gateIndex); + + if (status == SignalStatus.FAILED) { + throw new RuntimeException("Defensive Programming: LogicGate " + gateIndex + " failed"); + } + + SignalStatus priorStatus = status; + + long currentMatched = memory.getLogicGateMemory()[gateIndex]; + + switch (signalStatus) { + case MATCHED: + currentMatched = currentMatched | (1L << (signalBitIndex - 1)); // ensures position is on, if it wasn't before. If it was on before, it remains on. + break; + case UNMATCHED: + currentMatched = currentMatched & ~(1L << (signalBitIndex - 1)); // ensures position is off, if it wasn't before. If it was off before, it remains off. + break; + } + + memory.getLogicGateMemory()[gateIndex] = currentMatched; + + boolean matched = predicate.test(currentMatched, allMatched); + + if (matched) { + status = SignalStatus.MATCHED;//repetition.newMatch(); + } +// else { +// status = SignalStatus.UNMATCHED; +// } + + memory.setLogicGateSignalStatus(gateIndex, status); + if (priorStatus != status) { + if (propagationTimer != null) { + propagationTimer.matched(memory, valueResolver, status); + } else { + propapate(memory, valueResolver, status); + } + } + } + + public void propapate(SequenceMemory memory, ValueResolver valueResolver, SignalStatus status) { + resetPrior(memory, valueResolver); + output.consume(status, memory, valueResolver); + } + + public void resetPrior(SequenceMemory memory, ValueResolver valueResolver) { + for (LogicGate gate : inputGates) { + gate.reset(memory, valueResolver); + } + + memory.resetLogicGateMemory(gateIndex, valueResolver); + + for (ConditionalSignalCounter counter : inputSignalCounters) { + counter.reset(memory, valueResolver); + } + } + + public void reset(SequenceMemory memory, ValueResolver valueResolver) { + resetPrior(memory, valueResolver); + output.reset(memory, valueResolver); + } + + public void activate(SequenceMemory memory, ValueResolver valueResolver) { + if (memory.getLogicGateSignalStatus()[gateIndex] == null) { + memory.getLogicGateSignalStatus()[gateIndex] = SignalStatus.UNMATCHED; + } + for (int i = 0; i < filterIndexes.length; i++) { + memory.activateSignalAdapter(filterIndexes[i], this, signalAdapterIndexes[i], i + 1); // bit indexes start at 1 + } + + if (propagationTimer != null) { + propagationTimer.activated(memory, valueResolver); + } + } + + public void deactivate(SequenceMemory memory, ValueResolver valueResolver) { + for (int i = 0; i < filterIndexes.length; i++) { + memory.deactivateSignalAdapter(filterIndexes[i], this, signalAdapterIndexes[i]); + } + + memory.resetLogicGateMemory(gateIndex, valueResolver); + } + + public interface PropagationTimer { + default void activated(SequenceMemory memory, ValueResolver valueResolver) { + + } + + default void matched(SequenceMemory memory, ValueResolver valueResolver, SignalStatus status) { + + } + + default void failed(SequenceMemory memory, ValueResolver valueResolver) { + + } + } + + public static class TimeoutTimer implements PropagationTimer { + private final LogicGate gate; + private final Timer timer; + + public TimeoutTimer(LogicGate gate, Timer timer) { + this.gate = gate; + this.timer = timer; + } + + @Override + public void activated(SequenceMemory memory, ValueResolver valueResolver) { + Trigger trigger = timer.createTrigger(valueResolver.getTimerService().getCurrentTime(), null, null); + LogicGateTimerJobContext ctx = new LogicGateTimerJobContext(LogicGateTimerJobContext.TIMEOUT, trigger, valueResolver, gate, memory); + JobHandle jobHandle = valueResolver.getTimerService().scheduleJob(LogicGateJob.getINSTANCE(), ctx, trigger); + memory.setJobHandle(gate.getGateIndex(), jobHandle); + System.out.println("handle created"); + } + + @Override + public void matched(SequenceMemory memory, ValueResolver valueResolver, SignalStatus status) { + memory.cancelJobHandle(gate.getGateIndex(), valueResolver); + gate.propapate(memory, valueResolver, status); + } + + @Override + public void failed(SequenceMemory memory, ValueResolver valueResolver) { + memory.cancelJobHandle(gate.getGateIndex(), valueResolver); + } + } + + public static class DelayFromActivatedTimer implements PropagationTimer { + private final LogicGate gate; + private final Timer timer; + + public DelayFromActivatedTimer(LogicGate gate, Timer timer) { + this.gate = gate; + this.timer = timer; + } + + @Override + public void activated(SequenceMemory memory, ValueResolver valueResolver) { + Trigger trigger = timer.createTrigger(valueResolver.getTimerService().getCurrentTime(), null, null); + LogicGateTimerJobContext ctx = new LogicGateTimerJobContext(LogicGateTimerJobContext.TIMEOUT, trigger, valueResolver, gate, memory); + JobHandle jobHandle = valueResolver.getTimerService().scheduleJob(LogicGateJob.getINSTANCE(), ctx, trigger); + memory.setJobHandle(gate.getGateIndex(), jobHandle); + } + + @Override + public void matched(SequenceMemory memory, ValueResolver valueResolver, SignalStatus status) { + //gate.propapate(memory, reteEvaluator, status); + } + + @Override + public void failed(SequenceMemory memory, ValueResolver valueResolver) { + memory.cancelJobHandle(gate.getGateIndex(), valueResolver); + } + } + + public static class DelayFromMatchTimer implements PropagationTimer { + private final LogicGate gate; + private final Timer timer; + + public DelayFromMatchTimer(LogicGate gate, Timer timer) { + this.gate = gate; + this.timer = timer; + } + + @Override + public void activated(SequenceMemory memory, ValueResolver valueResolver) { + + } + + @Override + public void matched(SequenceMemory memory, ValueResolver valueResolver, SignalStatus status) { + Trigger trigger = timer.createTrigger(valueResolver.getTimerService().getCurrentTime(), null, null); + LogicGateTimerJobContext ctx = new LogicGateTimerJobContext(LogicGateTimerJobContext.DELAY, trigger, valueResolver, gate, memory); + JobHandle jobHandle = valueResolver.getTimerService().scheduleJob(LogicGateJob.getINSTANCE(), ctx, trigger); + memory.setJobHandle(gate.getGateIndex(), jobHandle); + System.out.println("delayed match"); + } + + @Override + public void failed(SequenceMemory memory, ValueResolver valueResolver) { + memory.cancelJobHandle(gate.getGateIndex(), valueResolver); + } + } + + public static class LogicGateJob + implements + Job { + private static final LogicGateJob INSTANCE = new LogicGateJob(); + + public static LogicGateJob getINSTANCE() { + return INSTANCE; + } + + public void execute(JobContext ctx) { + LogicGateTimerJobContext timerJobCtx = (LogicGateTimerJobContext) ctx; + ValueResolver resolver = timerJobCtx.getValueResolver(); + System.out.println("add propagation"); + resolver.addPropagation( new LogicGateTimerAction(timerJobCtx )); + } + } + + public static class LogicGateTimerJobContext + implements + JobContext { + private static final int DELAY = 0; + private static final int TIMEOUT = 1; + + private JobHandle jobHandle; + private final Trigger trigger; + private final ValueResolver valueResolver; + + private final LogicGate gate; + private final SequenceMemory sequenceMemory; + + private final int actionType; + + public LogicGateTimerJobContext(int actionType, Trigger trigger, ValueResolver valueResolver, LogicGate gate, SequenceMemory sequenceMemory) { + this.trigger = trigger; + this.valueResolver = valueResolver; + this.gate = gate; + this.sequenceMemory = sequenceMemory; + this.actionType = actionType; + } + + public JobHandle getJobHandle() { + return this.jobHandle; + } + + @Override + public ValueResolver getValueResolver() { + return valueResolver; + } + + public void setJobHandle(JobHandle jobHandle) { + this.jobHandle = jobHandle; + } + + public Trigger getTrigger() { + return trigger; + } + + public LogicGate getGate() { + return gate; + } + + public SequenceMemory getSequenceMemory() { + return sequenceMemory; + } + + public int getActionType() { + return actionType; + } + } + + public static class LogicGateTimerAction + extends AbstractPropagationEntry { + + private final LogicGateTimerJobContext jobCtx; + + private LogicGateTimerAction( LogicGateTimerJobContext jobCtx) { + this.jobCtx = jobCtx; + } + + @Override + public boolean requiresImmediateFlushing() { + return true; + } + + @Override + public void internalExecute(final ValueResolver valueResolver) { + execute( valueResolver, false ); + } + + public void execute( final ValueResolver valueResolver, boolean needEvaluation ) { + LogicGate gate = jobCtx.getGate(); + SequenceMemory sequenceMemory = jobCtx.getSequenceMemory(); + + SignalStatus status = sequenceMemory.getLogicGateSignalStatus(gate.getGateIndex()); + + sequenceMemory.clearJobHandle(gate.getGateIndex(), valueResolver); // clear rather than cancel, as it's actually firing + System.out.println("execute"); + + switch (jobCtx.getActionType()) { + case LogicGateTimerJobContext.DELAY: + if (status == SignalStatus.MATCHED) { + // transition + gate.propapate(sequenceMemory, valueResolver, status); + System.out.println("1"); + } else { + // fail + sequenceMemory.getSequencerMemory().getSequencer().fail(sequenceMemory); + System.out.println("2"); + } + break; + case LogicGateTimerJobContext.TIMEOUT: + // fail, if not already transitioned + if (status != SignalStatus.MATCHED) { + // fail + sequenceMemory.getSequencerMemory().getSequencer().fail(sequenceMemory); + System.out.println("3"); + } + break; + } + + // Logic is satsified and waiting to transition + // Logic is not satsified and has run out of time. + } + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGateOutputSignalProcessor.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGateOutputSignalProcessor.java new file mode 100644 index 00000000000..44a925179c7 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGateOutputSignalProcessor.java @@ -0,0 +1,66 @@ +package org.drools.core.reteoo.sequencing.signalprocessors; + +import org.drools.base.base.ValueResolver; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; + +public class LogicGateOutputSignalProcessor extends SignalProcessor { + private final SignalIndex[] gates; + + private LogicGate gate1; + private int index1; + private LogicGate gate2; + private int index2; + private LogicGate gate3; + private int index3; + private LogicGate gate4; + private int index4; + + + public LogicGateOutputSignalProcessor(SignalIndex... gates) { + this.gates = gates; + + switch (gates.length) { + case 4: + gate4 = gates[3].getGate(); + index4 = gates[3].getBitIndex(); + case 3: + gate3 = gates[2].getGate(); + index3 = gates[2].getBitIndex(); + case 2: + gate2 = gates[1].getGate(); + index2 = gates[1].getBitIndex(); + case 1: + gate1 = gates[0].getGate(); + index1 = gates[0].getBitIndex(); + break; + } + } + + public void consume(SignalStatus signalStatus, SequenceMemory memory, ValueResolver valueResolver) { + switch (gates.length) { + case 4: + gate4.consume(index4, signalStatus, memory, valueResolver); + case 3: + gate3.consume(index3, signalStatus, memory, valueResolver); + case 2: + gate2.consume(index2, signalStatus, memory, valueResolver); + case 1: + gate1.consume(index1, signalStatus, memory, valueResolver); + break; + default: + for (int i = gates.length - 1; i >= 0; i--) { + gates[i].getGate().consume(gates[i].getBitIndex(), signalStatus, memory, valueResolver); + } + } + } + + @Override + public void consume(int signalBitIndex, SignalStatus signalStatus, SequenceMemory memory, ValueResolver valueResolver) { + throw new UnsupportedOperationException(); + } + + @Override + protected void reset(SequenceMemory memory, ValueResolver valueResolver) { + // Do nothing + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalIndex.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalIndex.java new file mode 100644 index 00000000000..7ab07dfc405 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalIndex.java @@ -0,0 +1,23 @@ +package org.drools.core.reteoo.sequencing.signalprocessors; + +public class SignalIndex { + private final LogicGate gate; + private final int bitIndex; + + public static SignalIndex of(LogicGate gate, int bitIndex) { + return new SignalIndex(gate, bitIndex); + } + + public SignalIndex(LogicGate gate, int bitIndex) { + this.gate = gate; + this.bitIndex = bitIndex; + } + + public LogicGate getGate() { + return gate; + } + + public int getBitIndex() { + return bitIndex; + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalProcessor.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalProcessor.java new file mode 100644 index 00000000000..682f8c5fc07 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalProcessor.java @@ -0,0 +1,13 @@ +package org.drools.core.reteoo.sequencing.signalprocessors; + +import org.drools.base.base.ValueResolver; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; + +public abstract class SignalProcessor { + + public abstract void consume(SignalStatus signalStatus, SequenceMemory memory, ValueResolver valueResolver); + + public abstract void consume(int signalBitIndex, SignalStatus signalStatus, SequenceMemory memory, ValueResolver valueResolver); + + protected abstract void reset(SequenceMemory memory, ValueResolver valueResolver); +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalStatus.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalStatus.java new file mode 100644 index 00000000000..f276996ea40 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalStatus.java @@ -0,0 +1,18 @@ +package org.drools.core.reteoo.sequencing.signalprocessors; + +public enum SignalStatus { + MATCHED(0), + UNMATCHED(1), + FAILED(2); + + private final int status; + + SignalStatus(int status) { + this.status = status; + } + + @Override + public String toString() { + return "SignalStatus{ status=" + super.toString() + "}"; + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/TerminatingSignalProcessor.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/TerminatingSignalProcessor.java new file mode 100644 index 00000000000..d23836a36e8 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/TerminatingSignalProcessor.java @@ -0,0 +1,27 @@ +package org.drools.core.reteoo.sequencing.signalprocessors; + +import org.drools.base.base.ValueResolver; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; + +public class TerminatingSignalProcessor extends SignalProcessor { + private static final TerminatingSignalProcessor INSTANCE = new TerminatingSignalProcessor(); + + public static TerminatingSignalProcessor get() { + return INSTANCE; + } + + @Override + public void consume(SignalStatus signalStatus, SequenceMemory memory, ValueResolver valueResolver) { + memory.getSequence().next(memory, valueResolver); + } + + @Override + public void consume(int signalBitIndex, SignalStatus signalStatus, SequenceMemory memory, ValueResolver valueResolver) { + throw new UnsupportedOperationException(); + } + + @Override + protected void reset(SequenceMemory memory, ValueResolver valueResolver) { + throw new UnsupportedOperationException(); + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AbstractStep.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AbstractStep.java new file mode 100644 index 00000000000..1e1308d99ee --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AbstractStep.java @@ -0,0 +1,51 @@ +package org.drools.core.reteoo.sequencing.steps; + +import org.drools.base.base.ValueResolver; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.SequencerMemory; + +public abstract class AbstractStep implements Step { + + protected final int index; + protected final Sequence parentSequence; + protected StepFailureHandler failureHandler = FailStackFailureHandler.getInstance(); + + public AbstractStep(int index, Sequence parentSequence) { + this.index = index; + this.parentSequence = parentSequence; + } + + public int getIndex() { + return index; + } + + public Sequence getParentSequence() { + return parentSequence; + } + + @Override + public void onFail(SequenceMemory memory, ValueResolver valueResolver) { + failureHandler.onFail(this, memory, valueResolver); + } + + public interface StepFailureHandler { + void onFail(Step step, SequenceMemory memory, ValueResolver valueResolver); + } + + public static class FailStackFailureHandler implements StepFailureHandler { + + public static final FailStackFailureHandler INSTANCE = new FailStackFailureHandler(); + + public static FailStackFailureHandler getInstance() { + return INSTANCE; + } + + @Override + public void onFail(Step step, SequenceMemory sequenceMemory, ValueResolver valueResolver) { + SequencerMemory sequencerMemory = sequenceMemory.getSequencerMemory(); + step.deactivate(sequenceMemory, valueResolver); + sequencerMemory.getSequencer().stop(sequencerMemory, valueResolver); + } + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/ActionStep.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/ActionStep.java new file mode 100644 index 00000000000..4d4c76721a2 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/ActionStep.java @@ -0,0 +1,26 @@ +package org.drools.core.reteoo.sequencing.steps; + +import org.drools.base.base.ValueResolver; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; + +import java.util.function.Consumer; + +public class ActionStep extends AbstractStep implements Step { + private final Consumer consumer; + + public ActionStep(int index, Sequence parentSequence, Consumer consumer) { + super(index, parentSequence); + this.consumer = consumer; + } + + @Override + public void activate(SequenceMemory memory, ValueResolver valueResolver) { + consumer.accept(memory); + memory.getSequence().next(memory, valueResolver); // transitions as soon as the action is fired + } + + @Override + public void deactivate(SequenceMemory memory, ValueResolver valueResolver) { + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AggregatorStep.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AggregatorStep.java new file mode 100644 index 00000000000..1261ef55103 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AggregatorStep.java @@ -0,0 +1,13 @@ +package org.drools.core.reteoo.sequencing.steps; + +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; + +import java.util.function.Consumer; + +public class AggregatorStep extends SequenceStep implements Step { + public AggregatorStep(int index, Sequence parentSequence, Sequence sequence, Consumer consumer) { + super(index, parentSequence, sequence); + sequence.setOnEnd(consumer); + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/LogicCircuitStep.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/LogicCircuitStep.java new file mode 100644 index 00000000000..3b7327529fa --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/LogicCircuitStep.java @@ -0,0 +1,32 @@ +package org.drools.core.reteoo.sequencing.steps; + +import org.drools.base.base.ValueResolver; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; + +public class LogicCircuitStep extends AbstractStep implements Step { + private final LogicCircuit circuit; + + public LogicCircuitStep(int index, Sequence parentSequence, LogicCircuit circuit) { + super(index, parentSequence); + this.circuit = circuit; + } + + public LogicCircuit getCircuit() { + return circuit; + } + + public void activate(SequenceMemory sequenceMemory, ValueResolver valueResolver) { + for (LogicGate gate : circuit.getGates()) { + gate.activate(sequenceMemory, valueResolver); + } + } + + public void deactivate(SequenceMemory sequenceMemory, ValueResolver valueResolver) { + for (LogicGate gate : circuit.getGates()) { + gate.deactivate(sequenceMemory, valueResolver); + } + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/SequenceStep.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/SequenceStep.java new file mode 100644 index 00000000000..04c3c084ac0 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/SequenceStep.java @@ -0,0 +1,42 @@ +package org.drools.core.reteoo.sequencing.steps; + +import org.drools.base.base.ValueResolver; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.util.CircularArrayList; + +public class SequenceStep extends AbstractStep implements Step { + protected Sequence sequence; + + public SequenceStep(int index, Sequence parentSequence, Sequence sequence) { + super(index, parentSequence); + this.sequence = sequence; + } + + public Sequence getSequence() { + return sequence; + } + + @Override + public void activate(SequenceMemory sequenceMemory, ValueResolver valueResolver) { + if (parentSequence != null) { + // reserved for any context or return data + // Also in the future it could be used to optional collect and hold nested array of subevents for later reference. + CircularArrayList events = sequenceMemory.getSequencerMemory().getEvents(); + + SequenceMemory subSequenceMemory = sequenceMemory.getSequencerMemory().getSequenceMemory(sequence); + events.addEmpty(subSequenceMemory.getSequence().getOutputSize()); + subSequenceMemory.setEventsStartPosition(sequenceMemory.getSequencerMemory().getEvents().size()); + } + sequence.start(sequenceMemory.getSequencerMemory(), valueResolver); + } + + @Override + public void deactivate(SequenceMemory sequenceMemory, ValueResolver valueResolver) { + if (parentSequence != null) { + SequenceMemory subSequenceMemory = sequenceMemory.getSequencerMemory().getSequenceMemory(sequence); + CircularArrayList events = sequenceMemory.getSequencerMemory().getEvents(); + events.resetHeadByOffset(events.size() - subSequenceMemory.getEventsStartPosition()); + } + } +} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/Step.java b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/Step.java new file mode 100644 index 00000000000..b5c4e78be20 --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/Step.java @@ -0,0 +1,111 @@ +package org.drools.core.reteoo.sequencing.steps; + +import org.drools.base.base.ValueResolver; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; + +import java.util.function.Consumer; + +public interface Step { + void activate(SequenceMemory memory, ValueResolver valueResolver); + + void deactivate(SequenceMemory memory, ValueResolver valueResolver); + + void onFail(SequenceMemory memory, ValueResolver valueResolver); + + static StepFactory of(LogicCircuit circuit) { + StepFactory factory = new StepFactory(StepFactoryType.LOGIC_CIRCUIT); + factory.setCircuit(circuit); + return factory; + } + + static StepFactory of(Sequence sequence) { + StepFactory factory = new StepFactory(StepFactoryType.SEQUENCE); + factory.setSequence(sequence); + return factory; + } + + static StepFactory of(Sequence sequence, Consumer function) { + StepFactory factory = new StepFactory(StepFactoryType.AGGREGATOR); + factory.setAggregator(function); + factory.setSequence(sequence); + return factory; + } + + static StepFactory of(Consumer function) { + StepFactory factory = new StepFactory(StepFactoryType.ACTION); + factory.setAction(function); + return factory; + } + + Sequence getParentSequence(); + + + enum StepFactoryType { + LOGIC_CIRCUIT, SEQUENCE, AGGREGATOR, ACTION + } + + class StepFactory { + private final StepFactoryType type; + private LogicCircuit circuit; + private Sequence sequence; + private Consumer aggregator; + private Consumer action; + + public StepFactory(StepFactoryType type) { + this.type = type; + } + + public StepFactoryType getType() { + return type; + } + + public LogicCircuit getCircuit() { + return circuit; + } + + public void setCircuit(LogicCircuit circuit) { + this.circuit = circuit; + } + + public Sequence getSequence() { + return sequence; + } + + public void setSequence(Sequence sequence) { + this.sequence = sequence; + } + + public Consumer getAggregator() { + return aggregator; + } + + public void setAggregator(Consumer aggregator) { + this.aggregator = aggregator; + } + + public Consumer getAction() { + return action; + } + + public void setAction(Consumer action) { + this.action = action; + } + + public Step createStep(int index, Sequence parentSequence) { + switch (type) { + case LOGIC_CIRCUIT: + return new LogicCircuitStep(index, parentSequence, circuit); + case AGGREGATOR: + return new AggregatorStep(index, parentSequence, sequence, aggregator); + case SEQUENCE: + return new SequenceStep(index, parentSequence, sequence); + case ACTION: + return new ActionStep(index, parentSequence, action); + } + throw new IllegalArgumentException("Unsupported step type: " + type); + } + } + +} diff --git a/drools-core/src/main/java/org/drools/core/time/SchedulerService.java b/drools-base/src/main/java/org/drools/core/time/SchedulerService.java similarity index 95% rename from drools-core/src/main/java/org/drools/core/time/SchedulerService.java rename to drools-base/src/main/java/org/drools/core/time/SchedulerService.java index 89005ac20b8..e9fbc37c274 100644 --- a/drools-core/src/main/java/org/drools/core/time/SchedulerService.java +++ b/drools-base/src/main/java/org/drools/core/time/SchedulerService.java @@ -18,6 +18,8 @@ */ package org.drools.core.time; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; diff --git a/drools-core/src/main/java/org/drools/core/time/TimerService.java b/drools-base/src/main/java/org/drools/core/time/TimerService.java similarity index 100% rename from drools-core/src/main/java/org/drools/core/time/TimerService.java rename to drools-base/src/main/java/org/drools/core/time/TimerService.java diff --git a/drools-core/src/main/java/org/drools/core/time/InternalSchedulerService.java b/drools-base/src/main/java/org/drools/core/time/impl/InternalSchedulerService.java similarity index 91% rename from drools-core/src/main/java/org/drools/core/time/InternalSchedulerService.java rename to drools-base/src/main/java/org/drools/core/time/impl/InternalSchedulerService.java index b0ba3951f5b..a89cb4a65ab 100644 --- a/drools-core/src/main/java/org/drools/core/time/InternalSchedulerService.java +++ b/drools-base/src/main/java/org/drools/core/time/impl/InternalSchedulerService.java @@ -16,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.time; - -import org.drools.core.time.impl.TimerJobInstance; +package org.drools.core.time.impl; public interface InternalSchedulerService { public void internalSchedule(TimerJobInstance timerJobInstance); diff --git a/drools-core/src/main/java/org/drools/core/time/impl/TimerJobFactoryManager.java b/drools-base/src/main/java/org/drools/core/time/impl/TimerJobFactoryManager.java similarity index 92% rename from drools-core/src/main/java/org/drools/core/time/impl/TimerJobFactoryManager.java rename to drools-base/src/main/java/org/drools/core/time/impl/TimerJobFactoryManager.java index a10c1560550..9df535340a2 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/TimerJobFactoryManager.java +++ b/drools-base/src/main/java/org/drools/core/time/impl/TimerJobFactoryManager.java @@ -22,9 +22,8 @@ import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.core.time.InternalSchedulerService; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; public interface TimerJobFactoryManager { TimerJobInstance createTimerJobInstance(Job job, diff --git a/drools-core/src/main/java/org/drools/core/time/impl/TimerJobInstance.java b/drools-base/src/main/java/org/drools/core/time/impl/TimerJobInstance.java similarity index 93% rename from drools-core/src/main/java/org/drools/core/time/impl/TimerJobInstance.java rename to drools-base/src/main/java/org/drools/core/time/impl/TimerJobInstance.java index fe8bcb5e00f..e469c6e6cce 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/TimerJobInstance.java +++ b/drools-base/src/main/java/org/drools/core/time/impl/TimerJobInstance.java @@ -20,8 +20,8 @@ import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; public interface TimerJobInstance { JobHandle getJobHandle(); diff --git a/drools-core/src/main/java/org/drools/core/util/AbstractLinkedListNode.java b/drools-base/src/main/java/org/drools/core/util/AbstractLinkedListNode.java similarity index 100% rename from drools-core/src/main/java/org/drools/core/util/AbstractLinkedListNode.java rename to drools-base/src/main/java/org/drools/core/util/AbstractLinkedListNode.java diff --git a/drools-base/src/main/java/org/drools/core/util/CircularArrayList.java b/drools-base/src/main/java/org/drools/core/util/CircularArrayList.java new file mode 100644 index 00000000000..5b2610fbb1d --- /dev/null +++ b/drools-base/src/main/java/org/drools/core/util/CircularArrayList.java @@ -0,0 +1,91 @@ +package org.drools.core.util; + +import java.lang.reflect.Array; +import java.util.Arrays; + +public class CircularArrayList { + private E[] array; + private int head = 0; + private int capacity; + private Class cls; + + public CircularArrayList(int capacity) { + this(Object.class, capacity); + } + + public CircularArrayList(Class cls, int capacity) { + this.capacity = capacity; + this.array = (E[]) new Object[capacity]; + this.cls = cls; + } + + public void resetHeadByOffset(int offset) { + head = head-offset; + } + + public boolean set(int index, E e) { + array[index % capacity] = e; + return true; + } + + public boolean add(E e) { + array[head++ % capacity] = e; + return true; + } + + public void addEmpty(int size) { + head = head + size; + } + + public E getHead() { + return array[(head-1) % capacity]; + } + + public E getHeadMinus(int i) { + return array[(head-1-i) % capacity]; + } + + public E fastGet(int index) { + return array[index % capacity]; + } + + public E get(int index) { + if (index < head - capacity ) { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + capacity); + } + + return array[index % capacity]; + } + + public int size() { + return head; + } + + public boolean isEmpty() { + return size() == 0; + } + + public E[] toArray() { + int headIndex = head % capacity; + E[] trg; + if (head < array.length) { + trg = (E[]) Array.newInstance(cls, head); + System.arraycopy(array, 0, trg, 0, headIndex); + } else { + trg = (E[]) Array.newInstance(cls, array.length); + System.arraycopy(array, headIndex, trg, 0, array.length-headIndex); + System.arraycopy(array, 0, trg, array.length-headIndex, headIndex); + } + + return trg; + } + + @Override + public String toString() { + return "CircularArrayList{" + + "array=" + Arrays.toString(array) + + ", head=" + head + + ", capacity=" + capacity + + '}'; + } +} diff --git a/drools-core/src/main/java/org/drools/core/util/DoubleLinkedEntry.java b/drools-base/src/main/java/org/drools/core/util/DoubleLinkedEntry.java similarity index 93% rename from drools-core/src/main/java/org/drools/core/util/DoubleLinkedEntry.java rename to drools-base/src/main/java/org/drools/core/util/DoubleLinkedEntry.java index 5cbc474061c..5039ed15675 100644 --- a/drools-core/src/main/java/org/drools/core/util/DoubleLinkedEntry.java +++ b/drools-base/src/main/java/org/drools/core/util/DoubleLinkedEntry.java @@ -18,9 +18,6 @@ */ package org.drools.core.util; -import org.drools.core.reteoo.TupleImpl; -import org.drools.core.util.index.TupleList; - /** * Items placed in a LinkedList must implement this interface . * diff --git a/drools-core/src/main/java/org/drools/core/util/FastIterator.java b/drools-base/src/main/java/org/drools/core/util/FastIterator.java similarity index 100% rename from drools-core/src/main/java/org/drools/core/util/FastIterator.java rename to drools-base/src/main/java/org/drools/core/util/FastIterator.java diff --git a/drools-core/src/main/java/org/drools/core/util/Iterator.java b/drools-base/src/main/java/org/drools/core/util/Iterator.java similarity index 100% rename from drools-core/src/main/java/org/drools/core/util/Iterator.java rename to drools-base/src/main/java/org/drools/core/util/Iterator.java diff --git a/drools-core/src/main/java/org/drools/core/util/LinkedList.java b/drools-base/src/main/java/org/drools/core/util/LinkedList.java similarity index 98% rename from drools-core/src/main/java/org/drools/core/util/LinkedList.java rename to drools-base/src/main/java/org/drools/core/util/LinkedList.java index cc436849cfd..64ddbd2294a 100644 --- a/drools-core/src/main/java/org/drools/core/util/LinkedList.java +++ b/drools-base/src/main/java/org/drools/core/util/LinkedList.java @@ -25,8 +25,6 @@ import java.util.Collection; import java.util.NoSuchElementException; -import org.drools.core.reteoo.TupleImpl; - /** * This is a simple linked implementation. Each node must implement LinkedListNode so that it references * the node before and after it. This way a node can be removed without having to scan the list to find it. This class @@ -391,9 +389,9 @@ public FastIterator fastIterator() { } // All the tuples except for TMS are AbstractTuple - public static class LinkedListFastIterator implements FastIterator { + public static class LinkedListFastIterator> implements FastIterator { - public TupleImpl next(TupleImpl object) { + public T next(T object) { return object.getNext(); } diff --git a/drools-core/src/main/java/org/drools/core/util/LinkedListEntry.java b/drools-base/src/main/java/org/drools/core/util/LinkedListEntry.java similarity index 100% rename from drools-core/src/main/java/org/drools/core/util/LinkedListEntry.java rename to drools-base/src/main/java/org/drools/core/util/LinkedListEntry.java diff --git a/drools-core/src/main/java/org/drools/core/util/SingleLinkedEntry.java b/drools-base/src/main/java/org/drools/core/util/SingleLinkedEntry.java similarity index 100% rename from drools-core/src/main/java/org/drools/core/util/SingleLinkedEntry.java rename to drools-base/src/main/java/org/drools/core/util/SingleLinkedEntry.java diff --git a/drools-compiler/src/main/java/org/drools/compiler/rule/builder/RuleBuilder.java b/drools-compiler/src/main/java/org/drools/compiler/rule/builder/RuleBuilder.java index 07dc0190f00..2de5d2dbd07 100644 --- a/drools-compiler/src/main/java/org/drools/compiler/rule/builder/RuleBuilder.java +++ b/drools-compiler/src/main/java/org/drools/compiler/rule/builder/RuleBuilder.java @@ -37,7 +37,7 @@ import org.drools.base.rule.GroupElement; import org.drools.base.rule.accessor.Salience; import org.drools.base.time.TimeUtils; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.compiler.compiler.DroolsWarning; import org.drools.compiler.compiler.RuleBuildError; import org.drools.compiler.compiler.RuleBuildWarning; diff --git a/drools-core/src/main/java/org/drools/core/common/AgendaGroupQueueImpl.java b/drools-core/src/main/java/org/drools/core/common/AgendaGroupQueueImpl.java index 94be988bc22..c0ccc66a919 100644 --- a/drools-core/src/main/java/org/drools/core/common/AgendaGroupQueueImpl.java +++ b/drools-core/src/main/java/org/drools/core/common/AgendaGroupQueueImpl.java @@ -27,8 +27,8 @@ import org.drools.core.conflict.RuleAgendaConflictResolver; import org.drools.core.impl.InternalRuleBase; import org.drools.core.marshalling.MarshallerReaderContext; -import org.drools.core.phreak.PropagationEntry; import org.drools.core.phreak.RuleAgendaItem; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.util.ArrayQueue; import org.drools.core.util.Queue; import org.drools.core.util.QueueFactory; @@ -112,7 +112,7 @@ public void clear() { reteEvaluator.addPropagation( new ClearAction( this.name ) ); } - public class ClearAction extends PropagationEntry.AbstractPropagationEntry { + public class ClearAction extends AbstractPropagationEntry { private final String name; @@ -130,7 +130,7 @@ public void setFocus() { reteEvaluator.addPropagation( new SetFocusAction( this.name ) ); } - public class SetFocusAction extends PropagationEntry.AbstractPropagationEntry { + public class SetFocusAction extends AbstractPropagationEntry { private final String name; @@ -267,7 +267,7 @@ public void setClearedForRecency(long recency) { } public static class DeactivateCallback - extends PropagationEntry.AbstractPropagationEntry + extends AbstractPropagationEntry implements WorkingMemoryAction { private static final long serialVersionUID = 510l; diff --git a/drools-core/src/main/java/org/drools/core/common/ReteEvaluator.java b/drools-core/src/main/java/org/drools/core/common/ReteEvaluator.java index fc0a6e3df28..c8bb8ce6acd 100644 --- a/drools-core/src/main/java/org/drools/core/common/ReteEvaluator.java +++ b/drools-core/src/main/java/org/drools/core/common/ReteEvaluator.java @@ -138,19 +138,4 @@ default KnowledgeHelper createKnowledgeHelper() { int fireAllRules(int max); int fireAllRules(AgendaFilter agendaFilter); int fireAllRules(AgendaFilter agendaFilter, int max); - - default void setWorkingMemoryActionListener(Consumer listener) { - throw new UnsupportedOperationException(); - } - - default Consumer getWorkingMemoryActionListener() { - return null; - } - - default void onWorkingMemoryAction(PropagationEntry entry) { - Consumer listener = getWorkingMemoryActionListener(); - if (listener != null) { - listener.accept(entry); - } - } } diff --git a/drools-core/src/main/java/org/drools/core/common/WorkingMemoryAction.java b/drools-core/src/main/java/org/drools/core/common/WorkingMemoryAction.java index 3f8acc5546d..866add5915b 100644 --- a/drools-core/src/main/java/org/drools/core/common/WorkingMemoryAction.java +++ b/drools-core/src/main/java/org/drools/core/common/WorkingMemoryAction.java @@ -20,7 +20,7 @@ import org.drools.core.phreak.PropagationEntry; -public interface WorkingMemoryAction extends PropagationEntry { +public interface WorkingMemoryAction extends PropagationEntry { short WorkingMemoryReteAssertAction = 1; short DeactivateCallback = 2; short PropagateAction = 3; diff --git a/drools-core/src/main/java/org/drools/core/impl/WorkingMemoryReteExpireAction.java b/drools-core/src/main/java/org/drools/core/impl/WorkingMemoryReteExpireAction.java index 920e4075194..e7179f6fdb4 100644 --- a/drools-core/src/main/java/org/drools/core/impl/WorkingMemoryReteExpireAction.java +++ b/drools-core/src/main/java/org/drools/core/impl/WorkingMemoryReteExpireAction.java @@ -30,13 +30,15 @@ import org.drools.core.common.WorkingMemoryAction; import org.drools.core.marshalling.MarshallerReaderContext; import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.AbstractPartitionedPropagationEntry; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.RightTuple; import static org.drools.core.common.PhreakPropagationContextFactory.createPropagationContextForFact; public class WorkingMemoryReteExpireAction - extends PropagationEntry.AbstractPropagationEntry + extends AbstractPropagationEntry implements WorkingMemoryAction, Externalizable { protected DefaultEventHandle factHandle; @@ -127,7 +129,7 @@ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundExcept this.factHandle = (DefaultEventHandle) in.readObject(); } - public static class PartitionAwareWorkingMemoryReteExpireAction extends PropagationEntry.AbstractPartitionedPropagationEntry { + public static class PartitionAwareWorkingMemoryReteExpireAction extends AbstractPartitionedPropagationEntry { private final DefaultEventHandle factHandle; private final ObjectTypeNode node; diff --git a/drools-core/src/main/java/org/drools/core/phreak/BuildtimeSegmentUtilities.java b/drools-core/src/main/java/org/drools/core/phreak/BuildtimeSegmentUtilities.java index d3b64d0130e..a9a50345649 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/BuildtimeSegmentUtilities.java +++ b/drools-core/src/main/java/org/drools/core/phreak/BuildtimeSegmentUtilities.java @@ -41,6 +41,8 @@ import org.drools.core.reteoo.PathEndNode.PathMemSpec; import org.drools.core.reteoo.QueryElementNode; import org.drools.core.reteoo.ReactiveFromNode; +import org.drools.core.reteoo.SegmentMemory.SequenceMemoryPrototype; +import org.drools.core.reteoo.SequenceNode; import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.SegmentMemory.AccumulateMemoryPrototype; import org.drools.core.reteoo.SegmentMemory.AsyncReceiveMemoryPrototype; @@ -230,6 +232,9 @@ public static SegmentPrototype createSegmentMemory(LeftTupleNode segmentRoot, Le case NodeTypeEnums.TimerConditionNode: processTimerNode((TimerNode) node, memories, nodes, nodePosMask); break; + case NodeTypeEnums.SequenceNode: + processSequenceNode((SequenceNode) node, memories, nodes, nodePosMask); + break; case NodeTypeEnums.AsyncSendNode: processAsyncSendNode((AsyncSendNode) node, memories, nodes); break; @@ -345,6 +350,12 @@ private static void processTimerNode(TimerNode tupleSource, List memories, List nodes, long nodePosMask) { + SequenceMemoryPrototype seqMem = new SequenceMemoryPrototype(nodePosMask); + memories.add(seqMem); + nodes.add(tupleSource); + } + private static long processLiaNode(LeftInputAdapterNode tupleSource, List memories, List nodes, long nodePosMask, long allLinkedTestMask) { LiaMemoryPrototype liaMemory = new LiaMemoryPrototype(nodePosMask); diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakNetworkNodeFactory.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakNetworkNodeFactory.java index 062d441bf29..f9b8afd0312 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakNetworkNodeFactory.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakNetworkNodeFactory.java @@ -18,6 +18,7 @@ */ package org.drools.core.phreak; +import org.drools.core.reteoo.SequenceNode.PhreakSequenceNode; import org.kie.api.internal.utils.KieService; public interface PhreakNetworkNodeFactory extends KieService { @@ -44,6 +45,8 @@ public interface PhreakNetworkNodeFactory extends KieService { PhreakTimerNode createPhreakTimerNode(); + PhreakSequenceNode createPhreakSequenceNode(); + PhreakAsyncSendNode createPhreakAsyncSendNode(); PhreakAsyncReceiveNode createPhreakAsyncReceiveNode(); diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakNetworkNodeFactoryImpl.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakNetworkNodeFactoryImpl.java index 1c8d023b91f..1889f4eeec8 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakNetworkNodeFactoryImpl.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakNetworkNodeFactoryImpl.java @@ -18,6 +18,8 @@ */ package org.drools.core.phreak; +import org.drools.core.reteoo.SequenceNode.PhreakSequenceNode; + public class PhreakNetworkNodeFactoryImpl implements PhreakNetworkNodeFactory { @Override @@ -75,6 +77,11 @@ public PhreakTimerNode createPhreakTimerNode() { return new PhreakTimerNode(); } + @Override + public PhreakSequenceNode createPhreakSequenceNode() { + return new PhreakSequenceNode(); + } + @Override public PhreakAsyncSendNode createPhreakAsyncSendNode() { return new PhreakAsyncSendNode(); diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakTimerNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakTimerNode.java index a895bfc6f64..f5429df7e32 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakTimerNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakTimerNode.java @@ -21,10 +21,12 @@ import java.util.Date; import java.util.List; +import org.drools.base.base.ValueResolver; import org.drools.base.common.NetworkNode; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; +import org.drools.core.RuleSessionConfiguration; import org.drools.core.common.ActivationsManager; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; @@ -32,18 +34,19 @@ import org.drools.core.common.TupleSets; import org.drools.core.common.WorkingMemoryAction; import org.drools.core.marshalling.TupleKey; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.LeftTupleSink; import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.SegmentMemory; +import org.drools.core.reteoo.SegmentNodeMemory; import org.drools.core.reteoo.TimerNode; import org.drools.core.reteoo.TimerNode.TimerNodeMemory; -import org.drools.core.reteoo.Tuple; import org.drools.core.reteoo.TupleFactory; import org.drools.core.reteoo.TupleImpl; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.core.time.TimerService; import org.drools.core.time.impl.DefaultJobHandle; import org.drools.core.util.LinkedList; @@ -364,13 +367,13 @@ public static class TimerNodeJob Job { public void execute(JobContext ctx) { TimerNodeJobContext timerJobCtx = (TimerNodeJobContext) ctx; - ReteEvaluator reteEvaluator = timerJobCtx.getReteEvaluator(); + ValueResolver reteEvaluator = timerJobCtx.getValueResolver(); reteEvaluator.addPropagation( new TimerAction( timerJobCtx ) ); } } public static class TimerAction - extends PropagationEntry.AbstractPropagationEntry + extends AbstractPropagationEntry implements WorkingMemoryAction { private final TimerNodeJobContext timerJobCtx; @@ -381,7 +384,7 @@ private TimerAction( TimerNodeJobContext timerJobCtx ) { @Override public boolean requiresImmediateFlushing() { - return timerJobCtx.getReteEvaluator().getRuleSessionConfiguration().getTimedRuleExecutionFilter() != null; + return timerJobCtx.getValueResolver().getKieSessionConfiguration().as(RuleSessionConfiguration.KEY).getTimedRuleExecutionFilter() != null; } @Override @@ -433,10 +436,10 @@ private void evaluateAndFireRule(PathMemory pmem, ActivationsManager activations } } - private static void evaluate(PathMemory pmem, + public static void evaluate(PathMemory pmem, ActivationsManager activationsManager, LeftTupleSink sink, - TimerNodeMemory tm, + SegmentNodeMemory tm, TupleSets trgLeftTuples) { SegmentMemory[] smems = pmem.getSegmentMemories(); SegmentMemory sm = tm.getSegmentMemory(); @@ -495,7 +498,7 @@ public JobHandle getJobHandle() { } @Override - public ReteEvaluator getReteEvaluator() { + public ValueResolver getValueResolver() { return reteEvaluator; } diff --git a/drools-core/src/main/java/org/drools/core/phreak/PropagationEntry.java b/drools-core/src/main/java/org/drools/core/phreak/PropagationEntry.java deleted file mode 100644 index a3c02ff3498..00000000000 --- a/drools-core/src/main/java/org/drools/core/phreak/PropagationEntry.java +++ /dev/null @@ -1,483 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.drools.core.phreak; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.concurrent.CountDownLatch; - -import org.drools.base.reteoo.NodeTypeEnums; -import org.drools.core.base.DroolsQueryImpl; -import org.drools.core.common.DefaultEventHandle; -import org.drools.core.common.InternalFactHandle; -import org.drools.core.common.PropagationContext; -import org.drools.core.common.ReteEvaluator; -import org.drools.core.impl.WorkingMemoryReteExpireAction; -import org.drools.core.reteoo.ClassObjectTypeConf; -import org.drools.core.reteoo.CompositePartitionAwareObjectSinkAdapter; -import org.drools.core.reteoo.EntryPointNode; -import org.drools.core.reteoo.LeftInputAdapterNode; -import org.drools.core.reteoo.LeftTupleSource; -import org.drools.core.reteoo.ModifyPreviousTuples; -import org.drools.core.reteoo.ObjectTypeConf; -import org.drools.core.reteoo.ObjectTypeNode; -import org.drools.core.reteoo.PathMemory; -import org.drools.core.reteoo.QueryTerminalNode; -import org.drools.core.reteoo.TerminalNode; -import org.drools.core.time.JobContext; -import org.drools.core.time.impl.DefaultJobHandle; -import org.drools.core.time.impl.PointInTimeTrigger; -import org.kie.api.prototype.PrototypeEventInstance; - -import static org.drools.base.rule.TypeDeclaration.NEVER_EXPIRES; -import static org.drools.core.reteoo.EntryPointNode.removeRightTuplesMatchingOTN; - -public interface PropagationEntry { - - default void execute(ReteEvaluator reteEvaluator) { - internalExecute(reteEvaluator); - reteEvaluator.onWorkingMemoryAction(this); - } - - void internalExecute(ReteEvaluator reteEvaluator); - - PropagationEntry getNext(); - void setNext(PropagationEntry next); - - boolean requiresImmediateFlushing(); - - boolean isCalledFromRHS(); - - boolean isPartitionSplittable(); - PropagationEntry getSplitForPartition(int partitionNr); - - boolean defersExpiration(); - - abstract class AbstractPropagationEntry implements PropagationEntry { - protected PropagationEntry next; - - public void setNext(PropagationEntry next) { - this.next = next; - } - - public PropagationEntry getNext() { - return next; - } - - @Override - public boolean requiresImmediateFlushing() { - return false; - } - - @Override - public boolean isCalledFromRHS() { - return false; - } - - @Override - public boolean isPartitionSplittable() { - return false; - } - - @Override - public boolean defersExpiration() { - return false; - } - - @Override - public PropagationEntry getSplitForPartition(int partitionNr) { - throw new UnsupportedOperationException(); - } - } - - abstract class AbstractPartitionedPropagationEntry extends AbstractPropagationEntry { - protected final int partition; - - protected AbstractPartitionedPropagationEntry( int partition ) { - this.partition = partition; - } - - protected boolean isMainPartition() { - return partition == 0; - } - } - - abstract class PropagationEntryWithResult extends PropagationEntry.AbstractPropagationEntry { - private final CountDownLatch done = new CountDownLatch( 1 ); - - private T result; - - public final T getResult() { - try { - done.await(); - } catch (InterruptedException e) { - throw new RuntimeException( e ); - } - return result; - } - - protected void done(T result) { - this.result = result; - done.countDown(); - } - - @Override - public boolean requiresImmediateFlushing() { - return true; - } - } - - class ExecuteQuery extends PropagationEntry.PropagationEntryWithResult { - - private final String queryName; - private final DroolsQueryImpl queryObject; - private final InternalFactHandle handle; - private final PropagationContext pCtx; - private final boolean calledFromRHS; - - public ExecuteQuery(String queryName, DroolsQueryImpl queryObject, InternalFactHandle handle, PropagationContext pCtx, boolean calledFromRHS) { - this.queryName = queryName; - this.queryObject = queryObject; - this.handle = handle; - this.pCtx = pCtx; - this.calledFromRHS = calledFromRHS; - } - - @Override - public void internalExecute(ReteEvaluator reteEvaluator ) { - QueryTerminalNode[] tnodes = reteEvaluator.getKnowledgeBase().getReteooBuilder().getTerminalNodesForQuery( queryName ); - if ( tnodes == null ) { - throw new RuntimeException( "Query '" + queryName + "' does not exist" ); - } - - QueryTerminalNode tnode = tnodes[0]; - - if (queryObject.getElements().length != tnode.getQuery().getParameters().length) { - throw new RuntimeException( "Query '" + queryName + "' has been invoked with a wrong number of arguments. Expected " + - tnode.getQuery().getParameters().length + ", actual " + queryObject.getElements().length ); - } - - LeftTupleSource lts = tnode.getLeftTupleSource(); - while ( !NodeTypeEnums.isLeftInputAdapterNode(lts)) { - lts = lts.getLeftTupleSource(); - } - LeftInputAdapterNode lian = (LeftInputAdapterNode) lts; - LeftInputAdapterNode.LiaNodeMemory lmem = reteEvaluator.getNodeMemory( lian ); - if ( lmem.getSegmentMemory() == null ) { - RuntimeSegmentUtilities.getOrCreateSegmentMemory(lmem, lts, reteEvaluator); - } - - LeftInputAdapterNode.doInsertObject( handle, pCtx, lian, reteEvaluator, lmem, false, queryObject.isOpen() ); - - for ( PathMemory rm : lmem.getSegmentMemory().getPathMemories() ) { - RuleAgendaItem evaluator = reteEvaluator.getActivationsManager().createRuleAgendaItem( Integer.MAX_VALUE, rm, (TerminalNode) rm.getPathEndNode() ); - evaluator.getRuleExecutor().setDirty( true ); - evaluator.getRuleExecutor().evaluateNetworkAndFire( reteEvaluator, null, 0, -1 ); - } - - done(tnodes); - } - - @Override - public boolean isCalledFromRHS() { - return calledFromRHS; - } - } - - class Insert extends AbstractPropagationEntry implements Externalizable { - private static final ObjectTypeNode.ExpireJob job = new ObjectTypeNode.ExpireJob(); - - private InternalFactHandle handle; - private PropagationContext context; - private ObjectTypeConf objectTypeConf; - - public Insert() { } - - public Insert( InternalFactHandle handle, PropagationContext context, ReteEvaluator reteEvaluator, ObjectTypeConf objectTypeConf) { - this.handle = handle; - this.context = context; - this.objectTypeConf = objectTypeConf; - - if ( handle.isEvent() ) { - scheduleExpiration(reteEvaluator, handle, context, objectTypeConf, reteEvaluator.getTimerService().getCurrentTime()); - } - } - - public static void execute( InternalFactHandle handle, PropagationContext context, ReteEvaluator reteEvaluator, ObjectTypeConf objectTypeConf) { - if ( handle.isEvent() ) { - scheduleExpiration(reteEvaluator, handle, context, objectTypeConf, reteEvaluator.getTimerService().getCurrentTime()); - } - propagate( handle, context, reteEvaluator, objectTypeConf ); - } - - private static void propagate( InternalFactHandle handle, PropagationContext context, ReteEvaluator reteEvaluator, ObjectTypeConf objectTypeConf ) { - if (objectTypeConf == null) { - // it can be null after deserialization - objectTypeConf = handle.getEntryPoint(reteEvaluator).getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(handle.getEntryPointId(), handle.getObject()); - } - for ( ObjectTypeNode otn : objectTypeConf.getObjectTypeNodes() ) { - otn.propagateAssert( handle, context, reteEvaluator ); - } - if ( isOrphanHandle(handle, reteEvaluator) ) { - handle.setDisconnected(true); - handle.getEntryPoint(reteEvaluator).getObjectStore().removeHandle( handle ); - } - } - - private static boolean isOrphanHandle(InternalFactHandle handle, ReteEvaluator reteEvaluator) { - return !handle.hasMatches() && !reteEvaluator.getKnowledgeBase().getKieBaseConfiguration().isMutabilityEnabled(); - } - - public void internalExecute(ReteEvaluator reteEvaluator ) { - propagate( handle, context, reteEvaluator, objectTypeConf ); - } - - private static void scheduleExpiration(ReteEvaluator reteEvaluator, InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf, long insertionTime) { - for ( ObjectTypeNode otn : objectTypeConf.getObjectTypeNodes() ) { - long expirationOffset = objectTypeConf.isPrototype() ? ((PrototypeEventInstance) handle.getObject()).getExpiration() : otn.getExpirationOffset(); - scheduleExpiration( reteEvaluator, handle, context, otn, insertionTime, expirationOffset ); - } - if ( objectTypeConf.getConcreteObjectTypeNode() == null ) { - long expirationOffset = objectTypeConf.isPrototype() ? ((PrototypeEventInstance) handle.getObject()).getExpiration() : ((ClassObjectTypeConf) objectTypeConf).getExpirationOffset(); - scheduleExpiration( reteEvaluator, handle, context, null, insertionTime, expirationOffset); - } - } - - private static void scheduleExpiration( ReteEvaluator reteEvaluator, InternalFactHandle handle, PropagationContext context, ObjectTypeNode otn, long insertionTime, long expirationOffset ) { - if ( expirationOffset == NEVER_EXPIRES || expirationOffset == Long.MAX_VALUE || context.getReaderContext() != null ) { - return; - } - - // DROOLS-455 the calculation of the effectiveEnd may overflow and become negative - DefaultEventHandle eventFactHandle = (DefaultEventHandle) handle; - long nextTimestamp = getNextTimestamp( insertionTime, expirationOffset, eventFactHandle ); - - WorkingMemoryReteExpireAction action = new WorkingMemoryReteExpireAction((DefaultEventHandle) handle, otn ); - if (nextTimestamp <= reteEvaluator.getTimerService().getCurrentTime()) { - reteEvaluator.addPropagation( action ); - } else { - JobContext jobctx = new ObjectTypeNode.ExpireJobContext( action, reteEvaluator ); - DefaultJobHandle jobHandle = (DefaultJobHandle) reteEvaluator.getTimerService() - .scheduleJob( job, jobctx, PointInTimeTrigger.createPointInTimeTrigger( nextTimestamp, null ) ); - jobctx.setJobHandle( jobHandle ); - eventFactHandle.addJob( jobHandle ); - } - } - - private static long getNextTimestamp( long insertionTime, long expirationOffset, DefaultEventHandle eventFactHandle) { - long effectiveEnd = eventFactHandle.getEndTimestamp() + expirationOffset; - return Math.max( insertionTime, effectiveEnd >= 0 ? effectiveEnd : Long.MAX_VALUE ); - } - - @Override - public String toString() { - return "Insert of " + handle.getObject(); - } - - public InternalFactHandle getHandle() { - return handle; - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - out.writeObject(next); - out.writeObject(handle); - out.writeObject(context); - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - this.next = (PropagationEntry) in.readObject(); - this.handle = (InternalFactHandle) in.readObject(); - this.context = (PropagationContext) in.readObject(); - } - } - - class Update extends AbstractPropagationEntry implements Externalizable { - private InternalFactHandle handle; - private PropagationContext context; - private ObjectTypeConf objectTypeConf; - - public Update(){} - - public Update(InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf) { - this.handle = handle; - this.context = context; - this.objectTypeConf = objectTypeConf; - } - - public void internalExecute(ReteEvaluator reteEvaluator) { - execute(handle, context, objectTypeConf, reteEvaluator); - } - - public static void execute(InternalFactHandle handle, PropagationContext pctx, ObjectTypeConf objectTypeConf, ReteEvaluator reteEvaluator) { - if (objectTypeConf == null) { - // it can be null after deserialization - objectTypeConf = handle.getEntryPoint(reteEvaluator).getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(handle.getEntryPointId(), handle.getObject()); - } - // make a reference to the previous tuples, then null then on the handle - ModifyPreviousTuples modifyPreviousTuples = new ModifyPreviousTuples( handle.detachLinkedTuples() ); - ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes(); - for ( int i = 0, length = cachedNodes.length; i < length; i++ ) { - cachedNodes[i].modifyObject( handle, modifyPreviousTuples, pctx, reteEvaluator ); - if (i < cachedNodes.length - 1) { - removeRightTuplesMatchingOTN( pctx, reteEvaluator, modifyPreviousTuples, cachedNodes[i], 0 ); - } - } - modifyPreviousTuples.retractTuples(pctx, reteEvaluator); - } - - @Override - public boolean isPartitionSplittable() { - return true; - } - - @Override - public PropagationEntry getSplitForPartition( int partitionNr ) { - return new PartitionedUpdate( handle, context, objectTypeConf, partitionNr ); - } - - @Override - public String toString() { - return "Update of " + handle.getObject(); - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - out.writeObject(next); - out.writeObject(handle); - out.writeObject(context); - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - this.next = (PropagationEntry) in.readObject(); - this.handle = (InternalFactHandle) in.readObject(); - this.context = (PropagationContext) in.readObject(); - } - } - - class PartitionedUpdate extends AbstractPartitionedPropagationEntry { - private final InternalFactHandle handle; - private final PropagationContext context; - private final ObjectTypeConf objectTypeConf; - - PartitionedUpdate(InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf, int partition) { - super( partition ); - this.handle = handle; - this.context = context; - this.objectTypeConf = objectTypeConf; - } - - public void internalExecute(ReteEvaluator reteEvaluator) { - ModifyPreviousTuples modifyPreviousTuples = new ModifyPreviousTuples( handle.detachLinkedTuplesForPartition(partition) ); - ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes(); - for ( int i = 0, length = cachedNodes.length; i < length; i++ ) { - ObjectTypeNode otn = cachedNodes[i]; - ( (CompositePartitionAwareObjectSinkAdapter) otn.getObjectSinkPropagator() ) - .propagateModifyObjectForPartition( handle, modifyPreviousTuples, - context.adaptModificationMaskForObjectType(otn.getObjectType(), reteEvaluator), - reteEvaluator, partition ); - if (i < cachedNodes.length - 1) { - removeRightTuplesMatchingOTN( context, reteEvaluator, modifyPreviousTuples, otn, partition ); - } - } - modifyPreviousTuples.retractTuples(context, reteEvaluator); - } - - @Override - public String toString() { - return "Update of " + handle.getObject() + " for partition " + partition; - } - } - - class Delete extends AbstractPropagationEntry { - private final EntryPointNode epn; - private final InternalFactHandle handle; - private final PropagationContext context; - private final ObjectTypeConf objectTypeConf; - - public Delete(EntryPointNode epn, InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf) { - this.epn = epn; - this.handle = handle; - this.context = context; - this.objectTypeConf = objectTypeConf; - } - - public void internalExecute(ReteEvaluator reteEvaluator) { - execute(reteEvaluator, epn, handle, context, objectTypeConf); - } - - public static void execute(ReteEvaluator reteEvaluator, EntryPointNode epn, InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf) { - epn.propagateRetract(handle, context, objectTypeConf, reteEvaluator); - } - - @Override - public boolean isPartitionSplittable() { - return true; - } - - @Override - public PropagationEntry getSplitForPartition( int partitionNr ) { - return new PartitionedDelete( handle, context, objectTypeConf, partitionNr ); - } - - @Override - public String toString() { - return "Delete of " + handle.getObject(); - } - } - - class PartitionedDelete extends AbstractPartitionedPropagationEntry { - private final InternalFactHandle handle; - private final PropagationContext context; - private final ObjectTypeConf objectTypeConf; - - PartitionedDelete(InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf, int partition) { - super( partition ); - this.handle = handle; - this.context = context; - this.objectTypeConf = objectTypeConf; - } - - public void internalExecute(ReteEvaluator reteEvaluator) { - ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes(); - - if ( cachedNodes == null ) { - // it is possible that there are no ObjectTypeNodes for an object being retracted - return; - } - - for ( ObjectTypeNode cachedNode : cachedNodes ) { - cachedNode.retractObject( handle, context, reteEvaluator, partition ); - } - - if (handle.isEvent() && isMainPartition()) { - ((DefaultEventHandle) handle).unscheduleAllJobs(reteEvaluator); - } - } - - @Override - public String toString() { - return "Delete of " + handle.getObject() + " for partition " + partition; - } - } -} diff --git a/drools-core/src/main/java/org/drools/core/phreak/ReactiveObjectUtil.java b/drools-core/src/main/java/org/drools/core/phreak/ReactiveObjectUtil.java index dbf1e0f7399..4f85d66165c 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/ReactiveObjectUtil.java +++ b/drools-core/src/main/java/org/drools/core/phreak/ReactiveObjectUtil.java @@ -26,6 +26,7 @@ import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.LeftTupleSinkNode; import org.drools.core.reteoo.ReactiveFromNode; import org.drools.core.reteoo.ReactiveFromNodeLeftTuple; @@ -63,7 +64,7 @@ public static void notifyModification(Object object, Collection leftT } } - static class ReactivePropagation extends PropagationEntry.AbstractPropagationEntry { + static class ReactivePropagation extends AbstractPropagationEntry { private final Object object; private final ReactiveFromNodeLeftTuple leftTuple; diff --git a/drools-core/src/main/java/org/drools/core/phreak/RuleExecutor.java b/drools-core/src/main/java/org/drools/core/phreak/RuleExecutor.java index 675ba550e3f..d4db8329ffd 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/RuleExecutor.java +++ b/drools-core/src/main/java/org/drools/core/phreak/RuleExecutor.java @@ -140,7 +140,7 @@ private int fire( ReteEvaluator reteEvaluator, ActivationsManager activationsMan Tuple lastTuple = null; for (; tuple != null; lastTuple = tuple, tuple = getNextTuple()) { - //check if the rule is not effective or + // check if the rule is not effective or // if the current Rule is no-loop and the origin rule is the same then return if (cancelAndContinue(reteEvaluator, rtn, tuple, filter)) { continue; diff --git a/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java b/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java index 9d17b80cdb6..516ef2283a2 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java +++ b/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java @@ -31,6 +31,9 @@ import org.drools.core.common.TupleSetsImpl; import org.drools.core.reteoo.AbstractTerminalNode; import org.drools.core.reteoo.RightInputAdapterNode; +import org.drools.core.reteoo.SequenceNode; +import org.drools.core.reteoo.SequenceNode.PhreakSequenceNode; +import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; import org.drools.core.reteoo.TupleFactory; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.AccumulateNode; @@ -97,8 +100,9 @@ public class RuleNetworkEvaluator { private static final PhreakAccumulateNode pGroupByNode = PhreakNetworkNodeFactory.Factory.get().createPhreakGroupByNode(); private static final PhreakBranchNode pBranchNode = PhreakNetworkNodeFactory.Factory.get().createPhreakBranchNode(); private static final PhreakQueryNode pQueryNode = PhreakNetworkNodeFactory.Factory.get().createPhreakQueryNode(); - private static final PhreakTimerNode pTimerNode = PhreakNetworkNodeFactory.Factory.get().createPhreakTimerNode(); - private static final PhreakAsyncSendNode pSendNode = PhreakNetworkNodeFactory.Factory.get().createPhreakAsyncSendNode(); + private static final PhreakTimerNode pTimerNode = PhreakNetworkNodeFactory.Factory.get().createPhreakTimerNode(); + private static final PhreakSequenceNode pSequenceNode = PhreakNetworkNodeFactory.Factory.get().createPhreakSequenceNode(); + private static final PhreakAsyncSendNode pSendNode = PhreakNetworkNodeFactory.Factory.get().createPhreakAsyncSendNode(); private static final PhreakAsyncReceiveNode pReceiveNode = PhreakNetworkNodeFactory.Factory.get().createPhreakAsyncReceiveNode(); private static final PhreakRuleTerminalNode pRtNode = PhreakNetworkNodeFactory.Factory.get().createPhreakRuleTerminalNode(); private static final PhreakQueryTerminalNode pQtNode = PhreakNetworkNodeFactory.Factory.get().createPhreakQueryTerminalNode(); @@ -424,6 +428,10 @@ public TupleSets evalNode(PathMemory pmem, NetworkNode node, long bit, Memory no pTimerNode.doNode( (TimerNode) node, (TimerNodeMemory) nodeMem, pmem, smem, sink, activationsManager, srcTuples, trgTuples, stagedLeftTuples); break; } + case NodeTypeEnums.SequenceNode: { + pSequenceNode.doNode((SequenceNode) node, (SequenceNodeMemory) nodeMem, sink, activationsManager.getReteEvaluator(), srcTuples, trgTuples, stagedLeftTuples); + break; + } case NodeTypeEnums.ConditionalBranchNode: { pBranchNode.doNode((ConditionalBranchNode) node, (ConditionalBranchMemory) nodeMem, sink, activationsManager, srcTuples, trgTuples, stagedLeftTuples, executor); diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/AbstractPartitionedPropagationEntry.java b/drools-core/src/main/java/org/drools/core/phreak/actions/AbstractPartitionedPropagationEntry.java new file mode 100644 index 00000000000..aa0adbc8d41 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/AbstractPartitionedPropagationEntry.java @@ -0,0 +1,15 @@ +package org.drools.core.phreak.actions; + +import org.drools.base.base.ValueResolver; + +public abstract class AbstractPartitionedPropagationEntry extends AbstractPropagationEntry { + protected final int partition; + + protected AbstractPartitionedPropagationEntry(int partition) { + this.partition = partition; + } + + protected boolean isMainPartition() { + return partition == 0; + } +} diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/Delete.java b/drools-core/src/main/java/org/drools/core/phreak/actions/Delete.java new file mode 100644 index 00000000000..916864573e7 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/Delete.java @@ -0,0 +1,45 @@ +package org.drools.core.phreak.actions; + +import org.drools.core.common.InternalFactHandle; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.phreak.PropagationEntry; +import org.drools.core.reteoo.EntryPointNode; +import org.drools.core.reteoo.ObjectTypeConf; + +public class Delete extends AbstractPropagationEntry { + private final EntryPointNode epn; + private final InternalFactHandle handle; + private final PropagationContext context; + private final ObjectTypeConf objectTypeConf; + + public Delete(EntryPointNode epn, InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf) { + this.epn = epn; + this.handle = handle; + this.context = context; + this.objectTypeConf = objectTypeConf; + } + + public void internalExecute(ReteEvaluator reteEvaluator) { + execute(reteEvaluator, epn, handle, context, objectTypeConf); + } + + public static void execute(ReteEvaluator reteEvaluator, EntryPointNode epn, InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf) { + epn.propagateRetract(handle, context, objectTypeConf, reteEvaluator); + } + + @Override + public boolean isPartitionSplittable() { + return true; + } + + @Override + public PropagationEntry getSplitForPartition(int partitionNr) { + return new PartitionedDelete(handle, context, objectTypeConf, partitionNr); + } + + @Override + public String toString() { + return "Delete of " + handle.getObject(); + } +} diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/ExecuteQuery.java b/drools-core/src/main/java/org/drools/core/phreak/actions/ExecuteQuery.java new file mode 100644 index 00000000000..4cd94934921 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/ExecuteQuery.java @@ -0,0 +1,71 @@ +package org.drools.core.phreak.actions; + +import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.core.base.DroolsQueryImpl; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.phreak.RuleAgendaItem; +import org.drools.core.phreak.RuntimeSegmentUtilities; +import org.drools.core.reteoo.LeftInputAdapterNode; +import org.drools.core.reteoo.LeftTupleSource; +import org.drools.core.reteoo.PathMemory; +import org.drools.core.reteoo.QueryTerminalNode; +import org.drools.core.reteoo.TerminalNode; + +public class ExecuteQuery extends PropagationEntryWithResult { + + private final String queryName; + private final DroolsQueryImpl queryObject; + private final InternalFactHandle handle; + private final PropagationContext pCtx; + private final boolean calledFromRHS; + + public ExecuteQuery(String queryName, DroolsQueryImpl queryObject, InternalFactHandle handle, PropagationContext pCtx, boolean calledFromRHS) { + this.queryName = queryName; + this.queryObject = queryObject; + this.handle = handle; + this.pCtx = pCtx; + this.calledFromRHS = calledFromRHS; + } + + @Override + public void internalExecute(ReteEvaluator reteEvaluator) { + QueryTerminalNode[] tnodes = reteEvaluator.getKnowledgeBase().getReteooBuilder().getTerminalNodesForQuery(queryName); + if (tnodes == null) { + throw new RuntimeException("Query '" + queryName + "' does not exist"); + } + + QueryTerminalNode tnode = tnodes[0]; + + if (queryObject.getElements().length != tnode.getQuery().getParameters().length) { + throw new RuntimeException("Query '" + queryName + "' has been invoked with a wrong number of arguments. Expected " + + tnode.getQuery().getParameters().length + ", actual " + queryObject.getElements().length); + } + + LeftTupleSource lts = tnode.getLeftTupleSource(); + while (!NodeTypeEnums.isLeftInputAdapterNode(lts)) { + lts = lts.getLeftTupleSource(); + } + LeftInputAdapterNode lian = (LeftInputAdapterNode) lts; + LeftInputAdapterNode.LiaNodeMemory lmem = reteEvaluator.getNodeMemory(lian); + if (lmem.getSegmentMemory() == null) { + RuntimeSegmentUtilities.getOrCreateSegmentMemory(lmem, lts, reteEvaluator); + } + + LeftInputAdapterNode.doInsertObject(handle, pCtx, lian, reteEvaluator, lmem, false, queryObject.isOpen()); + + for (PathMemory rm : lmem.getSegmentMemory().getPathMemories()) { + RuleAgendaItem evaluator = reteEvaluator.getActivationsManager().createRuleAgendaItem(Integer.MAX_VALUE, rm, (TerminalNode) rm.getPathEndNode()); + evaluator.getRuleExecutor().setDirty(true); + evaluator.getRuleExecutor().evaluateNetworkAndFire(reteEvaluator, null, 0, -1); + } + + done(tnodes); + } + + @Override + public boolean isCalledFromRHS() { + return calledFromRHS; + } +} diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/Insert.java b/drools-core/src/main/java/org/drools/core/phreak/actions/Insert.java new file mode 100644 index 00000000000..afccfcfc71f --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/Insert.java @@ -0,0 +1,131 @@ +package org.drools.core.phreak.actions; + +import org.drools.core.common.DefaultEventHandle; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.impl.WorkingMemoryReteExpireAction; +import org.drools.core.phreak.PropagationEntry; +import org.drools.core.reteoo.ClassObjectTypeConf; +import org.drools.core.reteoo.ObjectTypeConf; +import org.drools.core.reteoo.ObjectTypeNode; +import org.drools.base.time.JobContext; +import org.drools.core.time.impl.DefaultJobHandle; +import org.drools.core.time.impl.PointInTimeTrigger; +import org.kie.api.prototype.PrototypeEventInstance; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; + +import static org.drools.base.rule.TypeDeclaration.NEVER_EXPIRES; + +public class Insert extends AbstractPropagationEntry implements Externalizable { + private static final ObjectTypeNode.ExpireJob job = new ObjectTypeNode.ExpireJob(); + + private InternalFactHandle handle; + private PropagationContext context; + private ObjectTypeConf objectTypeConf; + + public Insert() {} + + public Insert(InternalFactHandle handle, PropagationContext context, ReteEvaluator reteEvaluator, ObjectTypeConf objectTypeConf) { + this.handle = handle; + this.context = context; + this.objectTypeConf = objectTypeConf; + + if (handle.isEvent()) { + scheduleExpiration(reteEvaluator, handle, context, objectTypeConf, reteEvaluator.getTimerService().getCurrentTime()); + } + } + + public static void execute(InternalFactHandle handle, PropagationContext context, ReteEvaluator reteEvaluator, ObjectTypeConf objectTypeConf) { + if (handle.isEvent()) { + scheduleExpiration(reteEvaluator, handle, context, objectTypeConf, reteEvaluator.getTimerService().getCurrentTime()); + } + propagate(handle, context, reteEvaluator, objectTypeConf); + } + + private static void propagate(InternalFactHandle handle, PropagationContext context, ReteEvaluator reteEvaluator, ObjectTypeConf objectTypeConf) { + if (objectTypeConf == null) { + // it can be null after deserialization + objectTypeConf = handle.getEntryPoint(reteEvaluator).getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(handle.getEntryPointId(), handle.getObject()); + } + for (ObjectTypeNode otn : objectTypeConf.getObjectTypeNodes()) { + otn.propagateAssert(handle, context, reteEvaluator); + } + if (isOrphanHandle(handle, reteEvaluator)) { + handle.setDisconnected(true); + handle.getEntryPoint(reteEvaluator).getObjectStore().removeHandle(handle); + } + } + + private static boolean isOrphanHandle(InternalFactHandle handle, ReteEvaluator reteEvaluator) { + return !handle.hasMatches() && !reteEvaluator.getKnowledgeBase().getKieBaseConfiguration().isMutabilityEnabled(); + } + + public void internalExecute(ReteEvaluator reteEvaluator) { + propagate(handle, context, reteEvaluator, objectTypeConf); + } + + private static void scheduleExpiration(ReteEvaluator reteEvaluator, InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf, long insertionTime) { + for (ObjectTypeNode otn : objectTypeConf.getObjectTypeNodes()) { + long expirationOffset = objectTypeConf.isPrototype() ? ((PrototypeEventInstance) handle.getObject()).getExpiration() : otn.getExpirationOffset(); + scheduleExpiration(reteEvaluator, handle, context, otn, insertionTime, expirationOffset); + } + if (objectTypeConf.getConcreteObjectTypeNode() == null) { + long expirationOffset = objectTypeConf.isPrototype() ? ((PrototypeEventInstance) handle.getObject()).getExpiration() : ((ClassObjectTypeConf) objectTypeConf).getExpirationOffset(); + scheduleExpiration(reteEvaluator, handle, context, null, insertionTime, expirationOffset); + } + } + + private static void scheduleExpiration(ReteEvaluator reteEvaluator, InternalFactHandle handle, PropagationContext context, ObjectTypeNode otn, long insertionTime, long expirationOffset) { + if (expirationOffset == NEVER_EXPIRES || expirationOffset == Long.MAX_VALUE || context.getReaderContext() != null) { + return; + } + + // DROOLS-455 the calculation of the effectiveEnd may overflow and become negative + DefaultEventHandle eventFactHandle = (DefaultEventHandle) handle; + long nextTimestamp = getNextTimestamp(insertionTime, expirationOffset, eventFactHandle); + + WorkingMemoryReteExpireAction action = new WorkingMemoryReteExpireAction((DefaultEventHandle) handle, otn); + if (nextTimestamp <= reteEvaluator.getTimerService().getCurrentTime()) { + reteEvaluator.addPropagation(action); + } else { + JobContext jobctx = new ObjectTypeNode.ExpireJobContext(action, reteEvaluator); + DefaultJobHandle jobHandle = (DefaultJobHandle) reteEvaluator.getTimerService() + .scheduleJob(job, jobctx, PointInTimeTrigger.createPointInTimeTrigger(nextTimestamp, null)); + jobctx.setJobHandle(jobHandle); + eventFactHandle.addJob(jobHandle); + } + } + + private static long getNextTimestamp(long insertionTime, long expirationOffset, DefaultEventHandle eventFactHandle) { + long effectiveEnd = eventFactHandle.getEndTimestamp() + expirationOffset; + return Math.max(insertionTime, effectiveEnd >= 0 ? effectiveEnd : Long.MAX_VALUE); + } + + @Override + public String toString() { + return "Insert of " + handle.getObject(); + } + + public InternalFactHandle getHandle() { + return handle; + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(next); + out.writeObject(handle); + out.writeObject(context); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + this.next = (PropagationEntry) in.readObject(); + this.handle = (InternalFactHandle) in.readObject(); + this.context = (PropagationContext) in.readObject(); + } +} diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/PartitionedDelete.java b/drools-core/src/main/java/org/drools/core/phreak/actions/PartitionedDelete.java new file mode 100644 index 00000000000..f138c4c8d66 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/PartitionedDelete.java @@ -0,0 +1,43 @@ +package org.drools.core.phreak.actions; + +import org.drools.core.common.DefaultEventHandle; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.reteoo.ObjectTypeConf; +import org.drools.core.reteoo.ObjectTypeNode; + +public class PartitionedDelete extends AbstractPartitionedPropagationEntry { + private final InternalFactHandle handle; + private final PropagationContext context; + private final ObjectTypeConf objectTypeConf; + + PartitionedDelete(InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf, int partition) { + super(partition); + this.handle = handle; + this.context = context; + this.objectTypeConf = objectTypeConf; + } + + public void internalExecute(ReteEvaluator reteEvaluator) { + ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes(); + + if (cachedNodes == null) { + // it is possible that there are no ObjectTypeNodes for an object being retracted + return; + } + + for (ObjectTypeNode cachedNode : cachedNodes) { + cachedNode.retractObject(handle, context, reteEvaluator, partition); + } + + if (handle.isEvent() && isMainPartition()) { + ((DefaultEventHandle) handle).unscheduleAllJobs(reteEvaluator); + } + } + + @Override + public String toString() { + return "Delete of " + handle.getObject() + " for partition " + partition; + } +} diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/PartitionedUpdate.java b/drools-core/src/main/java/org/drools/core/phreak/actions/PartitionedUpdate.java new file mode 100644 index 00000000000..86ef10fcab0 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/PartitionedUpdate.java @@ -0,0 +1,45 @@ +package org.drools.core.phreak.actions; + +import org.drools.core.common.InternalFactHandle; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.reteoo.CompositePartitionAwareObjectSinkAdapter; +import org.drools.core.reteoo.ModifyPreviousTuples; +import org.drools.core.reteoo.ObjectTypeConf; +import org.drools.core.reteoo.ObjectTypeNode; + +import static org.drools.core.reteoo.EntryPointNode.removeRightTuplesMatchingOTN; + +public class PartitionedUpdate extends AbstractPartitionedPropagationEntry { + private final InternalFactHandle handle; + private final PropagationContext context; + private final ObjectTypeConf objectTypeConf; + + PartitionedUpdate(InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf, int partition) { + super(partition); + this.handle = handle; + this.context = context; + this.objectTypeConf = objectTypeConf; + } + + public void internalExecute(ReteEvaluator reteEvaluator) { + ModifyPreviousTuples modifyPreviousTuples = new ModifyPreviousTuples(handle.detachLinkedTuplesForPartition(partition)); + ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes(); + for (int i = 0, length = cachedNodes.length; i < length; i++) { + ObjectTypeNode otn = cachedNodes[i]; + ((CompositePartitionAwareObjectSinkAdapter) otn.getObjectSinkPropagator()) + .propagateModifyObjectForPartition(handle, modifyPreviousTuples, + context.adaptModificationMaskForObjectType(otn.getObjectType(), reteEvaluator), + reteEvaluator, partition); + if (i < cachedNodes.length - 1) { + removeRightTuplesMatchingOTN(context, reteEvaluator, modifyPreviousTuples, otn, partition); + } + } + modifyPreviousTuples.retractTuples(context, reteEvaluator); + } + + @Override + public String toString() { + return "Update of " + handle.getObject() + " for partition " + partition; + } +} diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/PropagationEntryWithResult.java b/drools-core/src/main/java/org/drools/core/phreak/actions/PropagationEntryWithResult.java new file mode 100644 index 00000000000..62001d4ec64 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/PropagationEntryWithResult.java @@ -0,0 +1,30 @@ +package org.drools.core.phreak.actions; + +import org.drools.base.base.ValueResolver; + +import java.util.concurrent.CountDownLatch; + +public abstract class PropagationEntryWithResult extends AbstractPropagationEntry { + private final CountDownLatch done = new CountDownLatch(1); + + private R result; + + public final R getResult() { + try { + done.await(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return result; + } + + protected void done(R result) { + this.result = result; + done.countDown(); + } + + @Override + public boolean requiresImmediateFlushing() { + return true; + } +} diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/Update.java b/drools-core/src/main/java/org/drools/core/phreak/actions/Update.java new file mode 100644 index 00000000000..739e50bc0a0 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/Update.java @@ -0,0 +1,80 @@ +package org.drools.core.phreak.actions; + +import org.drools.core.common.InternalFactHandle; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.phreak.PropagationEntry; +import org.drools.core.reteoo.ModifyPreviousTuples; +import org.drools.core.reteoo.ObjectTypeConf; +import org.drools.core.reteoo.ObjectTypeNode; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; + +import static org.drools.core.reteoo.EntryPointNode.removeRightTuplesMatchingOTN; + +public class Update extends AbstractPropagationEntry implements Externalizable { + private InternalFactHandle handle; + private PropagationContext context; + private ObjectTypeConf objectTypeConf; + + public Update() {} + + public Update(InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf) { + this.handle = handle; + this.context = context; + this.objectTypeConf = objectTypeConf; + } + + public void internalExecute(ReteEvaluator reteEvaluator) { + execute(handle, context, objectTypeConf, reteEvaluator); + } + + public static void execute(InternalFactHandle handle, PropagationContext pctx, ObjectTypeConf objectTypeConf, ReteEvaluator reteEvaluator) { + if (objectTypeConf == null) { + // it can be null after deserialization + objectTypeConf = handle.getEntryPoint(reteEvaluator).getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(handle.getEntryPointId(), handle.getObject()); + } + // make a reference to the previous tuples, then null then on the handle + ModifyPreviousTuples modifyPreviousTuples = new ModifyPreviousTuples(handle.detachLinkedTuples()); + ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes(); + for (int i = 0, length = cachedNodes.length; i < length; i++) { + cachedNodes[i].modifyObject(handle, modifyPreviousTuples, pctx, reteEvaluator); + if (i < cachedNodes.length - 1) { + removeRightTuplesMatchingOTN(pctx, reteEvaluator, modifyPreviousTuples, cachedNodes[i], 0); + } + } + modifyPreviousTuples.retractTuples(pctx, reteEvaluator); + } + + @Override + public boolean isPartitionSplittable() { + return true; + } + + @Override + public PropagationEntry getSplitForPartition(int partitionNr) { + return new PartitionedUpdate(handle, context, objectTypeConf, partitionNr); + } + + @Override + public String toString() { + return "Update of " + handle.getObject(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(next); + out.writeObject(handle); + out.writeObject(context); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + this.next = (PropagationEntry) in.readObject(); + this.handle = (InternalFactHandle) in.readObject(); + this.context = (PropagationContext) in.readObject(); + } +} diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java b/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java index f2b78bdc5d6..baeab3c84a4 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java @@ -30,13 +30,11 @@ import org.drools.core.RuleBaseConfiguration; import org.drools.core.common.BetaConstraints; import org.drools.core.common.EmptyBetaConstraints; -import org.drools.core.common.InternalFactHandle; import org.drools.core.common.Memory; import org.drools.core.common.MemoryFactory; -import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; import org.drools.core.common.UpdateContext; -import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.builder.BuildContext; import org.drools.core.util.AbstractLinkedListNode; import org.drools.core.util.index.TupleList; @@ -112,7 +110,7 @@ public ObjectTypeConf getObjectTypeConf( ReteEvaluator reteEvaluator ) { return objectTypeConf; } - public static class AsyncReceiveAction extends PropagationEntry.AbstractPropagationEntry { + public static class AsyncReceiveAction extends AbstractPropagationEntry { private final AsyncReceiveNode asyncReceiveNode; private final Object object; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java b/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java index f4d49dd6b08..c8fdb54d5b8 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java @@ -35,7 +35,7 @@ import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; -import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.CompositeObjectSinkAdapter.FieldIndex; public class CompositePartitionAwareObjectSinkAdapter implements ObjectSinkPropagator { @@ -128,7 +128,7 @@ public void propagateAssertObject( InternalFactHandle factHandle, PropagationCon } } - public static class Insert extends PropagationEntry.AbstractPropagationEntry { + public static class Insert extends AbstractPropagationEntry { private final ObjectSinkPropagator propagator; private final InternalFactHandle factHandle; @@ -151,7 +151,7 @@ public String toString() { } } - public static class HashedInsert extends PropagationEntry.AbstractPropagationEntry { + public static class HashedInsert extends AbstractPropagationEntry { private final AlphaNode sink; private final InternalFactHandle factHandle; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/EntryPointNode.java b/drools-core/src/main/java/org/drools/core/reteoo/EntryPointNode.java index 91f4855fb8b..34b0a8792f6 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/EntryPointNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/EntryPointNode.java @@ -39,7 +39,9 @@ import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; import org.drools.core.impl.InternalRuleBase; -import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.Delete; +import org.drools.core.phreak.actions.Insert; +import org.drools.core.phreak.actions.Update; import org.drools.core.reteoo.builder.BuildContext; import org.drools.util.bitmask.BitMask; import org.slf4j.Logger; @@ -198,9 +200,9 @@ public void assertObject(final InternalFactHandle handle, // In case of parallel execution the CompositePartitionAwareObjectSinkAdapter // used by the OTNs will take care of enqueueing this insertion on the propagation queues // of the different agendas - PropagationEntry.Insert.execute( handle, context, reteEvaluator, objectTypeConf ); + Insert.execute(handle, context, reteEvaluator, objectTypeConf); } else { - reteEvaluator.addPropagation( new PropagationEntry.Insert( handle, context, reteEvaluator, objectTypeConf ) ); + reteEvaluator.addPropagation( new Insert(handle, context, reteEvaluator, objectTypeConf )); } } @@ -214,9 +216,9 @@ public void modifyObject(final InternalFactHandle handle, } if (reteEvaluator.isThreadSafe()) { - reteEvaluator.addPropagation( new PropagationEntry.Update( handle, pctx, objectTypeConf ) ); + reteEvaluator.addPropagation( new Update(handle, pctx, objectTypeConf )); } else { - PropagationEntry.Update.execute( handle, pctx, objectTypeConf, reteEvaluator ); + Update.execute(handle, pctx, objectTypeConf, reteEvaluator); } } @@ -298,7 +300,7 @@ public void retractObject(InternalFactHandle handle, PropagationContext context, log.trace( "Delete {}", handle.toString() ); } - reteEvaluator.addPropagation(new PropagationEntry.Delete(this, handle, context, objectTypeConf)); + reteEvaluator.addPropagation(new Delete(this, handle, context, objectTypeConf)); } public void immediateDeleteObject(InternalFactHandle handle, PropagationContext context, @@ -307,7 +309,7 @@ public void immediateDeleteObject(InternalFactHandle handle, PropagationContext log.trace( "Delete {}", handle.toString() ); } - PropagationEntry.Delete.execute(reteEvaluator, this, handle, context, objectTypeConf); + Delete.execute(reteEvaluator, this, handle, context, objectTypeConf); } public void propagateRetract(InternalFactHandle handle, PropagationContext context, ObjectTypeConf objectTypeConf, ReteEvaluator reteEvaluator) { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ObjectRouter.java b/drools-core/src/main/java/org/drools/core/reteoo/ObjectRouter.java new file mode 100644 index 00000000000..3fda077e05a --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/reteoo/ObjectRouter.java @@ -0,0 +1,214 @@ +package org.drools.core.reteoo; + +import org.drools.base.base.ObjectType; +import org.drools.base.common.RuleBasePartitionId; +import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.common.InternalWorkingMemory; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.reteoo.builder.BuildContext; +import org.drools.core.util.AbstractLinkedListNode; +import org.drools.core.util.LinkedList; +import org.drools.util.bitmask.BitMask; + +import java.util.List; + +public class ObjectRouter { + + private RouteAdapter[] adapters; + + private LinkedList[] activeFilters; + + public ObjectRouter() { + } + + public void setRouterAdapters(RouteAdapter[] adapters) { + this.adapters = adapters; + activeFilters = new LinkedList[adapters.length]; + for (int i = 0; i < activeFilters.length; i++) { + activeFilters[i] = new LinkedList<>(); + } + } + + public void addFilter(Filter filter, int index) { + activeFilters[index].add(filter); + } + +// public void received(InternalFactHandle factHandle, PropagationContext pctx, ReteEvaluator reteEvaluator, RouteAdapter adapter) { +// System.out.println(adapter.getObjectTypeNode() + " : " + adapter.adapterIndex); +// +// for (Filter filter = activeFilters[adapter.adapterIndex].getFirst(); filter != null; filter = filter.getNext()) { +// filter.assertObject(factHandle, pctx, reteEvaluator); +// } +// } + + public void assertObject(final InternalFactHandle factHandle, + final PropagationContext pctx, + final ReteEvaluator reteEvaluator) { +// System.out.println(adapter.getObjectTypeNode() + " : " + adapter.adapterIndex); +// +// for (Filter filter = activeFilters[adapter.adapterIndex].getFirst(); filter != null; filter = filter.getNext()) { +// filter.assertObject(factHandle, pctx, reteEvaluator); +// } + } + + public void modifyObject(InternalFactHandle factHandle, + ModifyPreviousTuples modifyPreviousTuples, + PropagationContext context, + ReteEvaluator reteEvaluator) { + + } + + public void retractRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + // for now assuming we don't have any deletes, but we could add this later. + } + + public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + // for now assuming we don't have any modifies, but we could add this later. + // typically just gets treated as another add, as the processor is not that stateful (for this use case) - to keep it fast. + } + + + public static class Filter extends AbstractLinkedListNode { + private AlphaNodeFieldConstraint constraint; + private SequenceNode node; + + + public Filter(AlphaNodeFieldConstraint constraint) { + this.constraint = constraint; + } + + public AlphaNodeFieldConstraint getConstraint() { + return constraint; + } + + public void assertObject(final InternalFactHandle factHandle, + final PropagationContext pctx, + final ReteEvaluator reteEvaluator) { + if (constraint.isAllowed(factHandle, reteEvaluator)) { + System.out.println("true : " + factHandle.getObject()); + //router.received(factHandle, pctx, reteEvaluator, this); + } + } + + public void modifyObject(InternalFactHandle factHandle, + ModifyPreviousTuples modifyPreviousTuples, + PropagationContext context, + ReteEvaluator reteEvaluator) { + + } + + public void retractRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + // for now assuming we don't have any deletes, but we could add this later. + } + + public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + // for now assuming we don't have any modifies, but we could add this later. + // typically just gets treated as another add, as the processor is not that stateful (for this use case) - to keep it fast. + } + } + + /** + * Used with the updateSink method, so that the parent ObjectSource + * can update the TupleSink + */ + public static class RouteAdapter extends ObjectSource + implements + ObjectSinkNode, + RightTupleSink { + + private ObjectRouter router; + private int adapterIndex; + + private ObjectTypeNodeId otnId; + + + public RouteAdapter(int id, ObjectSource source, RuleBasePartitionId partitionId, ObjectRouter router, int adapterIndex) { + super(id, source, partitionId); + this.router = router; + this.adapterIndex = adapterIndex; + } + + public void assertObject(final InternalFactHandle factHandle, + final PropagationContext pctx, + final ReteEvaluator reteEvaluator) { + //router.received(factHandle, pctx, reteEvaluator, this); + + } + + public void modifyObject(InternalFactHandle factHandle, + ModifyPreviousTuples modifyPreviousTuples, + PropagationContext context, + ReteEvaluator reteEvaluator) { + + } + + @Override + public void retractRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + // for now assuming we don't have any deletes, but we could add this later. + } + + @Override + public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + // for now assuming we don't have any modifies, but we could add this later. + // typically just gets treated as another add, as the processor is not that stateful (for this use case) - to keep it fast. + } + + public int getId() { + return 0; + } + + public void byPassModifyToBetaNode(InternalFactHandle factHandle, + ModifyPreviousTuples modifyPreviousTuples, + PropagationContext context, + ReteEvaluator reteEvaluator) { + throw new UnsupportedOperationException(); + } + + @Override + public ObjectSinkNode getNextObjectSinkNode() { + return null; + } + + @Override + public void setNextObjectSinkNode(ObjectSinkNode next) { + + } + + @Override + public ObjectSinkNode getPreviousObjectSinkNode() { + return null; + } + + @Override + public void setPreviousObjectSinkNode(ObjectSinkNode previous) { + + } + + @Override + public BitMask calculateDeclaredMask(ObjectType modifiedType, List settableProperties) { + return null; + } + + @Override + public void updateSink(ObjectSink sink, PropagationContext context, InternalWorkingMemory workingMemory) { + + } + + @Override + public ObjectTypeNodeId getInputOtnId() { + return otnId; + } + + public int getType() { + return NodeTypeEnums.SequenceNode; // need to update enums for multi input (mdp) + } + + public void doAttach(BuildContext context) { + super.doAttach(context); + this.source.addObjectSink(this); + } + } +} diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java b/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java index 39bb5b2e205..dab101d8115 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java @@ -30,6 +30,7 @@ import org.drools.base.InitialFact; import org.drools.base.base.ClassObjectType; import org.drools.base.base.ObjectType; +import org.drools.base.base.ValueResolver; import org.drools.base.common.NetworkNode; import org.drools.base.common.RuleBasePartitionId; import org.drools.base.reteoo.NodeTypeEnums; @@ -46,8 +47,8 @@ import org.drools.core.impl.InternalRuleBase; import org.drools.core.impl.WorkingMemoryReteExpireAction; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.core.time.impl.DefaultJobHandle; import org.drools.util.bitmask.BitMask; import org.drools.util.bitmask.EmptyBitMask; @@ -455,7 +456,7 @@ public static class ExpireJobContext JobContext, Externalizable { public WorkingMemoryReteExpireAction expireAction; - public transient ReteEvaluator reteEvaluator; + public transient ReteEvaluator reteEvaluator; public JobHandle handle; public ExpireJobContext() { @@ -482,14 +483,11 @@ public WorkingMemoryReteExpireAction getExpireAction() { return expireAction; } - public ReteEvaluator getReteEvaluator() { + @Override + public ValueResolver getValueResolver() { return reteEvaluator; } - public void setReteEvaluator(ReteEvaluator reteEvaluator) { - this.reteEvaluator = reteEvaluator; - } - public JobHandle getHandle() { return handle; } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java b/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java index 34ec420b68c..b2d4b344baa 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java @@ -34,6 +34,7 @@ import org.drools.core.phreak.RuntimeSegmentUtilities; import org.drools.core.reteoo.AsyncReceiveNode.AsyncReceiveMemory; import org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory; +import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; import org.drools.core.reteoo.TupleToObjectNode.SubnetworkPathMemory; import org.drools.core.reteoo.TimerNode.TimerNodeMemory; import org.drools.core.util.LinkedList; @@ -769,6 +770,19 @@ public void populateMemory(ReteEvaluator reteEvaluator, Memory mem) { } } + public static class SequenceMemoryPrototype extends MemoryPrototype { + + public SequenceMemoryPrototype(long nodePosMaskBit) { + this.nodePosMaskBit = nodePosMaskBit; + } + + @Override + public void populateMemory(ReteEvaluator reteEvaluator, Memory mem) { + SequenceNodeMemory seqmem = (SequenceNodeMemory) mem; + seqmem.setNodePosMaskBit(nodePosMaskBit); + } + } + public static class AsyncSendMemoryPrototype extends MemoryPrototype { public AsyncSendMemoryPrototype() { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/SequenceNode.java b/drools-core/src/main/java/org/drools/core/reteoo/SequenceNode.java new file mode 100644 index 00000000000..f18722143d0 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/reteoo/SequenceNode.java @@ -0,0 +1,507 @@ +/* + * Copyright 2005 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.drools.core.reteoo; + +import org.drools.base.base.ObjectType; +import org.drools.base.common.RuleBasePartitionId; +import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.core.RuleBaseConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.common.InternalWorkingMemory; +import org.drools.core.common.Memory; +import org.drools.core.common.MemoryFactory; +import org.drools.core.common.PropagationContext; +import org.drools.core.common.ReteEvaluator; +import org.drools.core.common.TupleSets; +import org.drools.core.common.UpdateContext; +import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; +import org.drools.core.reteoo.builder.BuildContext; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.SequencerMemoryImpl; +import org.drools.core.reteoo.sequencing.SequencerMemory; +import org.drools.core.util.AbstractLinkedListNode; +import org.drools.core.util.LinkedList; +import org.drools.core.util.index.TupleList; +import org.drools.util.bitmask.BitMask; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.List; + +public class SequenceNode extends LeftTupleSource + implements + LeftTupleSinkNode, + MemoryFactory { + + private static final long serialVersionUID = 510l; + + protected boolean tupleMemoryEnabled; + + private Sequencer sequencer; + + private AlphaAdapter[] alphaAdapters; + + private DynamicFilterProto[] dynamicFilters; + + private LeftTupleSinkNode previousTupleSinkNode; + + private LeftTupleSinkNode nextTupleSinkNode; + + public SequenceNode() { + + } + + public SequenceNode(final int id, + final LeftTupleSource tupleSource, + final BuildContext context) { + super(id, context); + setLeftTupleSource(tupleSource); + this.tupleMemoryEnabled = context.isTupleMemoryEnabled(); + + initMasks(context); // Is this still relevant? (mdp for multi input) + + hashcode = calculateHashCode(); + //this.processor = new AnyNotAllInputProcessor(this); // hard coded for now. Inject the processor here, conditional on the behaviour you want. + } + + public AlphaAdapter[] getAlphaAdapters() { + return alphaAdapters; + } + + public void setAlphaAdapters(AlphaAdapter[] adapters) { + this.alphaAdapters = adapters; + } + + public DynamicFilterProto[] getDynamicFilters() { + return dynamicFilters; + } + + public void setDynamicFilters(DynamicFilterProto[] dynamicFilters) { + this.dynamicFilters = dynamicFilters; + } + + public void doAttach(BuildContext context) { + super.doAttach(context); + this.leftInput.addTupleSink( this, context ); + } + + public void networkUpdated(UpdateContext updateContext) { + this.leftInput.networkUpdated(updateContext); + } + + + /** + * Produce a debug string. + * + * @return The debug string. + */ + public String toString() { + return "[MultiInputNode(" + this.id + ")]]"; + } + + private int calculateHashCode() { + return this.leftInput.hashCode(); + } + + @Override + public boolean equals(final Object object) { + if (this == object) { + return true; + } + + if ( object == null || !(object instanceof SequenceNode) || this.hashCode() != object.hashCode() ) { + return false; + } + + SequenceNode other = (SequenceNode)object; + return this.leftInput.getId() == other.leftInput.getId(); + } + + public SequenceNodeMemory createMemory(final RuleBaseConfiguration config, ReteEvaluator reteEvaluator) { + LinkedList[] filters = new LinkedList[alphaAdapters.length]; + SequenceNodeMemory memory = new SequenceNodeMemory(this, filters, new DynamicFilter[filters.length]); + return memory; + } + + public SequencerMemory createSequencerMemory(TupleImpl lt, LeftTupleSink sink, SequenceNodeMemory nodeMemory) { + SequencerMemory sequencerMemory = new SequencerMemoryImpl(sequencer, lt, sink, this, nodeMemory); + + return sequencerMemory; + } + + public Sequencer getSequencer() { + return sequencer; + } + + public void setSequencer(Sequencer sequencer) { + this.sequencer = sequencer; + } + + public boolean isLeftTupleMemoryEnabled() { + return tupleMemoryEnabled; + } + + public void setLeftTupleMemoryEnabled(boolean tupleMemoryEnabled) { + this.tupleMemoryEnabled = tupleMemoryEnabled; + } + + /** + * Returns the next node + * @return + * The next TupleSinkNode + */ + public LeftTupleSinkNode getNextLeftTupleSinkNode() { + return this.nextTupleSinkNode; + } + + /** + * Sets the next node + * @param next + * The next TupleSinkNode + */ + public void setNextLeftTupleSinkNode(final LeftTupleSinkNode next) { + this.nextTupleSinkNode = next; + } + + /** + * Returns the previous node + * @return + * The previous TupleSinkNode + */ + public LeftTupleSinkNode getPreviousLeftTupleSinkNode() { + return this.previousTupleSinkNode; + } + + /** + * Sets the previous node + * @param previous + * The previous TupleSinkNode + */ + public void setPreviousLeftTupleSinkNode(final LeftTupleSinkNode previous) { + this.previousTupleSinkNode = previous; + } + + public int getType() { + return NodeTypeEnums.SequenceNode; + } + + public static class SequenceNodeMemory extends AbstractLinkedListNode + implements + Externalizable, + Memory { + + private static final long serialVersionUID = 510l; + + private TupleMemory leftTupleMemory; + + private TupleList stagedChildTuples; + + private SegmentMemory memory; + + private LinkedList[] activeFilters; + + private DynamicFilter[] filters; + + private SequenceNode node; + + private long nodePosMaskBit; + + public SequenceNodeMemory(SequenceNode node, LinkedList[] activeFilters, DynamicFilter[] filters) { + this.node = node; + stagedChildTuples = new TupleList(); + leftTupleMemory = new TupleList(); + this.activeFilters = activeFilters; + this.filters = filters; + } + + public SequenceNode getNode() { + return node; + } + + public void addActiveFilter(DynamicFilter filter) { + if (this.activeFilters[filter.getActiveFilterIndex()] == null) { + this.activeFilters[filter.getActiveFilterIndex()] = new LinkedList<>(); + } + this.activeFilters[filter.getActiveFilterIndex()].add(filter); + } + + public void removeActiveFilter(DynamicFilter filter) { + this.activeFilters[filter.getActiveFilterIndex()].remove(filter); + } + + public LinkedList[] getActiveFilters() { + return this.activeFilters; + } + + public DynamicFilter[] getFilters() { + return filters; + } + + public void setFilters(DynamicFilter[] filters) { + this.filters = filters; + } + + public TupleMemory getLeftTupleMemory() { + return leftTupleMemory; + } + + public TupleList getStagedChildTuples() { + return stagedChildTuples; + } + + public SegmentMemory getMemory() { + return memory; + } + + public void readExternal(ObjectInput in) throws IOException, + ClassNotFoundException { + } + + public void writeExternal(ObjectOutput out) throws IOException { + + } + + public int getNodeType() { + return NodeTypeEnums.SequenceNode; + } + + public void setSegmentMemory(SegmentMemory smem) { + this.memory = smem; + } + + public SegmentMemory getSegmentMemory() { + return this.memory; + } + + public void reset() { } + + public DynamicFilter getActiveDynamicFilter(int filterIndex) { + DynamicFilter filter = filters[filterIndex]; + + if (filter == null) { + DynamicFilterProto proto = node.getDynamicFilters()[filterIndex]; + filter = new DynamicFilter(proto); + filters[filterIndex] = filter; + addActiveFilter(filter); + } else if (filter.getSignalAdapters().isEmpty()) { + // when it's empty, it's removed from the list of active filters, it must be readded. + addActiveFilter(filter); + } + + return filter; + } + + public void setNodePosMaskBit(long nodePosMaskBit) { + this.nodePosMaskBit = nodePosMaskBit; + } + + public long getNodePosMaskBit() { + return nodePosMaskBit; + } + } + + @Override + public ObjectTypeNode getObjectTypeNode() { + return leftInput.getObjectTypeNode(); + } + + protected boolean doRemove(final RuleRemovalContext context, + final ReteooBuilder builder) { + return true; + } + + + public static class AlphaAdapter extends ObjectSource + implements + ObjectSinkNode, + RightTupleSink { + private int adapterIndex; + + private ObjectTypeNodeId otnId; + + private SequenceNode node; + + + public AlphaAdapter(int id, ObjectSource source, RuleBasePartitionId partitionId, SequenceNode node, int adapterIndex) { + super(id, source, partitionId); + this.adapterIndex = adapterIndex; + this.node = node; + } + + public void assertObject(final InternalFactHandle factHandle, + final PropagationContext pctx, + final ReteEvaluator reteEvaluator) { + System.out.println(getClass().getSimpleName() + ":" + adapterIndex + ":" + factHandle.getObject()); + + SequenceNodeMemory memory = reteEvaluator.getNodeMemory(node); + + LinkedList filters = memory.getActiveFilters()[adapterIndex]; + if (filters != null) { + for (DynamicFilter f = filters.getFirst(); f != null; f = f.getNext()) { + f.assertObject(factHandle, reteEvaluator); + } + } + } + + public void propagate() { + + } + + public void modifyObject(InternalFactHandle factHandle, + ModifyPreviousTuples modifyPreviousTuples, + PropagationContext context, + ReteEvaluator reteEvaluator) { + + } + + @Override + public void retractRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + // for now assuming we don't have any deletes, but we could add this later. + } + + @Override + public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { + // for now assuming we don't have any modifies, but we could add this later. + // typically just gets treated as another add, as the processor is not that stateful (for this use case) - to keep it fast. + } + + public int getId() { + return 0; + } + + public void byPassModifyToBetaNode(InternalFactHandle factHandle, + ModifyPreviousTuples modifyPreviousTuples, + PropagationContext context, + ReteEvaluator reteEvaluator) { + throw new UnsupportedOperationException(); + } + + @Override + public ObjectSinkNode getNextObjectSinkNode() { + return null; + } + + @Override + public void setNextObjectSinkNode(ObjectSinkNode next) { + + } + + @Override + public ObjectSinkNode getPreviousObjectSinkNode() { + return null; + } + + @Override + public void setPreviousObjectSinkNode(ObjectSinkNode previous) { + + } + + @Override + public BitMask calculateDeclaredMask(ObjectType modifiedType, List settableProperties) { + return null; + } + + @Override + public void updateSink(ObjectSink sink, PropagationContext context, InternalWorkingMemory workingMemory) { + + } + + @Override + public ObjectTypeNodeId getInputOtnId() { + return otnId; + } + + public int getType() { + return NodeTypeEnums.SequenceNode; // need to update enums for multi input (mdp) + } + + public void doAttach(BuildContext context) { + super.doAttach(context); + this.source.addObjectSink(this); + } + } + + public static class PhreakSequenceNode { + public void doNode(SequenceNode node, + SequenceNodeMemory memory, + LeftTupleSink sink, + ReteEvaluator reteEvaluator, + TupleSets srcLeftTuples, + TupleSets trgLeftTuples, + TupleSets stagedLeftTuples) { + + if (srcLeftTuples.getDeleteFirst() != null) { + doLeftDeletes(node, srcLeftTuples, trgLeftTuples, stagedLeftTuples, reteEvaluator); + } + + if (srcLeftTuples.getUpdateFirst() != null) { + doLeftUpdates(node, srcLeftTuples, trgLeftTuples, stagedLeftTuples, reteEvaluator); + } + + if (srcLeftTuples.getInsertFirst() != null) { + doLeftInserts(node, memory, sink, srcLeftTuples, reteEvaluator); + } + + srcLeftTuples.resetAll(); + } + + private void doLeftUpdates(SequenceNode node, TupleSets srcLeftTuples, TupleSets trgLeftTuples, TupleSets stagedLeftTuples, ReteEvaluator reteEvaluator) {} + +// public void doNode(SequenceNode node, SequenceNodeMemory nodeMem, PathMemory pmem, SegmentMemory smem, LeftTupleSinkNode sink, ActivationsManager activationsManager, TupleSets srcTuples, TupleSets trgTuples, TupleSets stagedLeftTuples) { +// +// } + + private void doLeftDeletes(SequenceNode node, + TupleSets srcLeftTuples, TupleSets trgLeftTuples, TupleSets stagedLeftTuples, + ReteEvaluator evaluator) { + for (TupleImpl leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) { + TupleImpl next = leftTuple.getStagedNext(); + + SequencerMemory sequencerMemory = (SequencerMemory) leftTuple.getContextObject(); + node.getSequencer().stop(sequencerMemory, evaluator); + leftTuple.getMemory().remove(leftTuple); + leftTuple.setContextObject(null); + // TODO add code here to propagate deletion of child LT (mdp) + + leftTuple.clearStaged(); + leftTuple = next; + } + } + + private void doLeftInserts(SequenceNode node, + SequenceNodeMemory memory, + LeftTupleSink sink, + TupleSets srcLeftTuples, + ReteEvaluator evaluator) { + for (TupleImpl leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) { + TupleImpl next = leftTuple.getStagedNext(); + + memory.getLeftTupleMemory().add(leftTuple); + + SequencerMemory sequencerMemory = memory.node.createSequencerMemory(leftTuple, sink, memory); + leftTuple.setContextObject(sequencerMemory); + node.getSequencer().start(sequencerMemory, evaluator); + + leftTuple.clearStaged(); + leftTuple = next; + } + } + + } +} diff --git a/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java b/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java index e0bf8207fc4..0c71a06c80f 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java @@ -24,12 +24,10 @@ import org.drools.base.reteoo.NodeTypeEnums; import org.drools.base.rule.Declaration; import org.drools.base.rule.Pattern; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.RuleBaseConfiguration; -import org.drools.core.common.InternalFactHandle; import org.drools.core.common.Memory; import org.drools.core.common.MemoryFactory; -import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; import org.drools.core.common.UpdateContext; import org.drools.core.reteoo.builder.BuildContext; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java b/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java index fc4dc2c5f10..b544443bd44 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java @@ -40,6 +40,7 @@ public static TupleImpl createPeer(Sink n, TupleImpl original) { case NodeTypeEnums.ConditionalBranchNode: case NodeTypeEnums.EvalConditionNode: case NodeTypeEnums.TimerConditionNode: + case NodeTypeEnums.SequenceNode: peer = new EvalNodeLeftTuple(); break; case NodeTypeEnums.ReactiveFromNode: @@ -78,6 +79,7 @@ public static TupleImpl createLeftTuple(Sink s, case NodeTypeEnums.AsyncReceiveNode: case NodeTypeEnums.ConditionalBranchNode: case NodeTypeEnums.EvalConditionNode: + case NodeTypeEnums.SequenceNode: case NodeTypeEnums.TimerConditionNode: return new EvalNodeLeftTuple(factHandle, s, leftTupleMemoryEnabled); case NodeTypeEnums.ReactiveFromNode: @@ -109,6 +111,7 @@ public static TupleImpl createLeftTuple(final InternalFactHandle factHandle, case NodeTypeEnums.ConditionalBranchNode: case NodeTypeEnums.EvalConditionNode: case NodeTypeEnums.TimerConditionNode: + case NodeTypeEnums.SequenceNode: return new EvalNodeLeftTuple(factHandle, leftTuple, s); case NodeTypeEnums.ReactiveFromNode: return new ReactiveFromNodeLeftTuple(factHandle, leftTuple, s); @@ -140,6 +143,7 @@ public static TupleImpl createLeftTuple(TupleImpl leftTuple, case NodeTypeEnums.ConditionalBranchNode: case NodeTypeEnums.EvalConditionNode: case NodeTypeEnums.TimerConditionNode: + case NodeTypeEnums.SequenceNode: return new EvalNodeLeftTuple(leftTuple, s, pctx, leftTupleMemoryEnabled); case NodeTypeEnums.ReactiveFromNode: throw new IllegalStateException("ReactFromNode does not implement this constructor."); @@ -170,6 +174,7 @@ public static TupleImpl createLeftTuple(TupleImpl leftTuple, case NodeTypeEnums.ConditionalBranchNode: case NodeTypeEnums.EvalConditionNode: case NodeTypeEnums.TimerConditionNode: + case NodeTypeEnums.SequenceNode: return new EvalNodeLeftTuple(leftTuple, rightTuple, s); case NodeTypeEnums.ReactiveFromNode: throw new IllegalStateException("ReactFromNode does not implement this constructor."); @@ -203,6 +208,7 @@ public static TupleImpl createLeftTuple(TupleImpl leftTuple, case NodeTypeEnums.ConditionalBranchNode: case NodeTypeEnums.EvalConditionNode: case NodeTypeEnums.TimerConditionNode: + case NodeTypeEnums.SequenceNode: return new EvalNodeLeftTuple(leftTuple, rightTuple, currentLeftChild, currentRightChild, s, leftTupleMemoryEnabled); case NodeTypeEnums.ReactiveFromNode: return new ReactiveFromNodeLeftTuple(leftTuple, rightTuple, currentLeftChild, currentRightChild, s, leftTupleMemoryEnabled); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/NamedConsequenceBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/NamedConsequenceBuilder.java index 5c5a27f409a..2c52ba2db57 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/NamedConsequenceBuilder.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/NamedConsequenceBuilder.java @@ -21,7 +21,7 @@ import org.drools.base.rule.GroupElement; import org.drools.base.rule.NamedConsequence; import org.drools.base.rule.RuleConditionElement; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; public class NamedConsequenceBuilder implements ReteooComponentBuilder { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java index a5510919f6f..26c4e2a3d84 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java @@ -35,7 +35,7 @@ import org.drools.base.rule.QueryElement; import org.drools.base.rule.accessor.DataProvider; import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.common.BetaConstraints; import org.drools.core.reteoo.AccumulateNode; import org.drools.core.reteoo.AlphaNode; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/PatternBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/PatternBuilder.java index e15c1c3ea5e..de3f2a12ce8 100755 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/PatternBuilder.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/PatternBuilder.java @@ -41,7 +41,7 @@ import org.drools.base.rule.constraint.BetaConstraint; import org.drools.base.rule.constraint.Constraint; import org.drools.base.rule.constraint.XpathConstraint; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.ObjectTypeNode; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java index f266f51b359..b21305f2b40 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java @@ -36,7 +36,7 @@ import org.drools.base.rule.QueryElement; import org.drools.base.rule.accessor.DataProvider; import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.common.BetaConstraints; import org.drools.core.reteoo.AccumulateNode; import org.drools.core.reteoo.AccumulateRight; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java index bb3209edd41..5bd03f914b8 100755 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java @@ -43,7 +43,7 @@ import org.drools.base.rule.WindowDeclaration; import org.drools.base.rule.WindowReference; import org.drools.base.rule.constraint.XpathConstraint; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.ActivationListenerFactory; import org.drools.core.common.BaseNode; import org.drools.core.common.InternalWorkingMemory; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/TimerBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/TimerBuilder.java index 5e6f2570681..6a8cba88b0b 100755 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/TimerBuilder.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/TimerBuilder.java @@ -20,7 +20,7 @@ import org.drools.base.rule.Declaration; import org.drools.base.rule.RuleConditionElement; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.time.impl.BaseTimer; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemoryImpl.java b/drools-core/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemoryImpl.java new file mode 100644 index 00000000000..b6367947680 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemoryImpl.java @@ -0,0 +1,143 @@ +package org.drools.core.reteoo.sequencing; + +import org.drools.base.reteoo.BaseTuple; +import org.drools.core.reteoo.DynamicFilter; +import org.drools.core.reteoo.LeftTuple; +import org.drools.core.reteoo.LeftTupleNode; +import org.drools.core.reteoo.LeftTupleSink; +import org.drools.core.reteoo.LeftTupleSinkNode; +import org.drools.core.reteoo.SequenceNode; +import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; +import org.drools.core.reteoo.SignalAdapter; +import org.drools.core.reteoo.Sink; +import org.drools.core.reteoo.TupleImpl; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.util.CircularArrayList; +import org.kie.api.runtime.rule.FactHandle; + +import java.util.ArrayList; + +public class SequencerMemoryImpl implements SequencerMemory { + + private final TupleImpl lt; + + private final CircularArrayList events; + + private final SequenceMemory[] sequenceMemories; + + private final LeftTupleSink sink; + + private final ArrayList sequenceStack = new ArrayList<>(); + + private Sequencer sequencer; + + private SequenceNode node; + + private SequenceNodeMemory nodeMemory; + + public SequencerMemoryImpl(Sequencer sequencer, TupleImpl lt, LeftTupleSink sink, SequenceNode node, SequenceNodeMemory nodeMemory) { + this.sequencer = sequencer; + this.lt = lt; + this.events = new CircularArrayList<>(FactHandle.class, 100); + this.sink = sink; + this.sequenceMemories = new SequenceMemory[sequencer.getSequencences().length]; + this.node = node; + this.nodeMemory = nodeMemory; + } + + @Override + public TupleImpl getLeftTuple() { + return lt; + } + + @Override + public CircularArrayList getEvents() { + return events; + } + + @Override + public LeftTupleSink getSink() { + return sink; + } + + @Override + public Sequencer getSequencer() { + return sequencer; + } + + @Override + public SequenceMemory getCurrentSequence() { + if (!sequenceStack.isEmpty()) { + return sequenceStack.get(sequenceStack.size() - 1); + } + + return null; + } + + @Override + public SequenceMemory popSequence() { + return sequenceStack.remove(sequenceStack.size() - 1); + } + + @Override + public void pushSequence(SequenceMemory sequenceMemory) { + sequenceStack.add(sequenceMemory); + } + + @Override + public int getCurrentStep() { + SequenceMemory seq = getCurrentSequence(); + return seq != null ? seq.getStep() : -1; + } + + @Override + public ArrayList getSequenceStack() { + return sequenceStack; + } + + @Override + public SequenceMemory getSequenceMemory(Sequence sequence) { + SequenceMemory sequenceMemory = sequenceMemories[sequence.getSequenceIndex()]; + if (sequenceMemory == null) { + + int signalAdapters = 0; + int counters = 0; + + for (LogicGate gate : sequence.getGates()) { + counters = counters + gate.getInputSignalCounters().length; + if (gate.getOutput().getClass() == ConditionalSignalCounter.class) { + ++counters; + } + signalAdapters = signalAdapters + gate.getSignalAdapterIndexes().length; + } + + long[] gateMemory = new long[sequence.getGates().length]; + long[] counterMemory = new long[counters]; + + sequenceMemory = new SequenceMemory(this, sequence, new SignalAdapter[signalAdapters], new SignalAdapter[signalAdapters], + gateMemory, counterMemory); + sequenceMemories[sequence.getSequenceIndex()] = sequenceMemory; + } + + return sequenceMemory; + } + + + @Override + public void match() { + nodeMemory.getStagedChildTuples().add(new LeftTuple(lt, sink, + lt.getPropagationContext(), false)); + } + + @Override + public DynamicFilter getActiveDynamicFilter(int filterIndex) { + return nodeMemory.getActiveDynamicFilter(filterIndex); + } + + @Override + public void removeActiveFilter(DynamicFilter filter) { + nodeMemory.removeActiveFilter(filter); + } +} diff --git a/drools-core/src/main/java/org/drools/core/rule/SlidingTimeWindow.java b/drools-core/src/main/java/org/drools/core/rule/SlidingTimeWindow.java index f04ae01a1d1..083785aca0c 100644 --- a/drools-core/src/main/java/org/drools/core/rule/SlidingTimeWindow.java +++ b/drools-core/src/main/java/org/drools/core/rule/SlidingTimeWindow.java @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.PriorityQueue; +import org.drools.base.base.ValueResolver; import org.drools.base.time.JobHandle; import org.drools.core.common.DefaultEventHandle; import org.drools.core.common.InternalFactHandle; @@ -33,12 +34,12 @@ import org.drools.core.common.ReteEvaluator; import org.drools.core.common.WorkingMemoryAction; import org.drools.core.marshalling.MarshallerReaderContext; -import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.WindowNode; import org.drools.core.reteoo.WindowNode.WindowMemory; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.core.time.TimerService; import org.drools.core.time.impl.PointInTimeTrigger; import org.kie.api.runtime.rule.FactHandle; @@ -339,7 +340,7 @@ public void writeExternal(ObjectOutput out) throws IOException { } @Override - public ReteEvaluator getReteEvaluator() { + public ValueResolver getValueResolver() { return reteEvaluator; } } @@ -357,7 +358,7 @@ public void execute(JobContext ctx) { } public static class BehaviorExpireWMAction - extends PropagationEntry.AbstractPropagationEntry + extends AbstractPropagationEntry implements WorkingMemoryAction { protected BehaviorRuntime behavior; protected BehaviorContext context; diff --git a/drools-core/src/main/java/org/drools/core/time/EnqueuedSelfRemovalJobContext.java b/drools-core/src/main/java/org/drools/core/time/EnqueuedSelfRemovalJobContext.java index aa908a4367d..cbc8556704a 100644 --- a/drools-core/src/main/java/org/drools/core/time/EnqueuedSelfRemovalJobContext.java +++ b/drools-core/src/main/java/org/drools/core/time/EnqueuedSelfRemovalJobContext.java @@ -20,18 +20,20 @@ import java.util.Map; +import org.drools.base.time.JobContext; import org.drools.core.common.ReteEvaluator; -import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.time.impl.TimerJobInstance; public class EnqueuedSelfRemovalJobContext extends SelfRemovalJobContext { - public EnqueuedSelfRemovalJobContext( JobContext jobContext, Map timerInstances ) { + public EnqueuedSelfRemovalJobContext(JobContext jobContext, Map timerInstances) { super( jobContext, timerInstances ); } @Override public void remove() { - getReteEvaluator().addPropagation( new PropagationEntry.AbstractPropagationEntry() { + getValueResolver().as(ReteEvaluator.class) + .addPropagation( new AbstractPropagationEntry() { @Override public void internalExecute(ReteEvaluator reteEvaluator) { timerInstances.remove( jobContext.getJobHandle().getId() ); diff --git a/drools-core/src/main/java/org/drools/core/time/Scheduler.java b/drools-core/src/main/java/org/drools/core/time/Scheduler.java index 618ab80c5e7..f96efe8829b 100644 --- a/drools-core/src/main/java/org/drools/core/time/Scheduler.java +++ b/drools-core/src/main/java/org/drools/core/time/Scheduler.java @@ -18,6 +18,8 @@ */ package org.drools.core.time; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; diff --git a/drools-core/src/main/java/org/drools/core/time/SelfRemovalJob.java b/drools-core/src/main/java/org/drools/core/time/SelfRemovalJob.java index f580f5be1a5..0d80d9775f2 100644 --- a/drools-core/src/main/java/org/drools/core/time/SelfRemovalJob.java +++ b/drools-core/src/main/java/org/drools/core/time/SelfRemovalJob.java @@ -18,6 +18,9 @@ */ package org.drools.core.time; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; + import java.io.Serializable; public class SelfRemovalJob implements Job, Serializable { diff --git a/drools-core/src/main/java/org/drools/core/time/SelfRemovalJobContext.java b/drools-core/src/main/java/org/drools/core/time/SelfRemovalJobContext.java index 5ad5c0ed9f4..bccefa0e717 100644 --- a/drools-core/src/main/java/org/drools/core/time/SelfRemovalJobContext.java +++ b/drools-core/src/main/java/org/drools/core/time/SelfRemovalJobContext.java @@ -20,8 +20,9 @@ import java.util.Map; +import org.drools.base.base.ValueResolver; +import org.drools.base.time.JobContext; import org.drools.base.time.JobHandle; -import org.drools.core.common.ReteEvaluator; import org.drools.core.time.impl.TimerJobInstance; public class SelfRemovalJobContext implements JobContext { @@ -52,8 +53,8 @@ public JobHandle getJobHandle() { } @Override - public ReteEvaluator getReteEvaluator() { - return jobContext.getReteEvaluator(); + public ValueResolver getValueResolver() { + return jobContext.getValueResolver(); } public void remove() { diff --git a/drools-core/src/main/java/org/drools/core/time/impl/CompositeMaxDurationTimer.java b/drools-core/src/main/java/org/drools/core/time/impl/CompositeMaxDurationTimer.java index c5e2799f828..02e4e788f96 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/CompositeMaxDurationTimer.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/CompositeMaxDurationTimer.java @@ -32,7 +32,7 @@ import org.drools.base.rule.Declaration; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.common.InternalWorkingMemory; import org.drools.core.rule.consequence.InternalMatch; import org.kie.api.runtime.Calendars; diff --git a/drools-core/src/main/java/org/drools/core/time/impl/CronTimer.java b/drools-core/src/main/java/org/drools/core/time/impl/CronTimer.java index 2ff9e668edd..67aec0c46a3 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/CronTimer.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/CronTimer.java @@ -31,7 +31,7 @@ import org.drools.base.rule.Declaration; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.time.TimerExpression; import org.kie.api.runtime.Calendars; diff --git a/drools-core/src/main/java/org/drools/core/time/impl/DefaultJobHandle.java b/drools-core/src/main/java/org/drools/core/time/impl/DefaultJobHandle.java index e87fc731ed9..79e06f90f40 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/DefaultJobHandle.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/DefaultJobHandle.java @@ -20,7 +20,7 @@ import java.io.Serializable; -import org.drools.core.time.Job; +import org.drools.base.time.Job; /** * A default implementation for the JobHandle interface diff --git a/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobFactoryManager.java b/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobFactoryManager.java index 27fce5d4b48..694dd72783a 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobFactoryManager.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobFactoryManager.java @@ -23,9 +23,8 @@ import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.core.time.InternalSchedulerService; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; public class DefaultTimerJobFactoryManager implements diff --git a/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobInstance.java b/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobInstance.java index 0711af5fa4d..b599fe6668f 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobInstance.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobInstance.java @@ -24,9 +24,8 @@ import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.core.time.InternalSchedulerService; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +59,7 @@ public int compareTo(DefaultTimerJobInstance o) { public Void call() throws Exception { try { - this.trigger.initialize(this.getJobContext().getReteEvaluator()); + this.trigger.initialize(this.getJobContext().getValueResolver()); this.trigger.nextFireTime(); // need to pop if ( handle.isCancel() ) { return null; diff --git a/drools-core/src/main/java/org/drools/core/time/impl/DurationTimer.java b/drools-core/src/main/java/org/drools/core/time/impl/DurationTimer.java index 8b8fffd53a1..f27c25f5609 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/DurationTimer.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/DurationTimer.java @@ -33,7 +33,7 @@ import org.drools.base.rule.Declaration; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.common.DefaultEventHandle; import org.drools.core.common.InternalWorkingMemory; import org.drools.core.reteoo.Tuple; diff --git a/drools-core/src/main/java/org/drools/core/time/impl/ExpressionIntervalTimer.java b/drools-core/src/main/java/org/drools/core/time/impl/ExpressionIntervalTimer.java index 50e73232f75..8dddfb660ca 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/ExpressionIntervalTimer.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/ExpressionIntervalTimer.java @@ -31,7 +31,7 @@ import org.drools.base.rule.Declaration; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.time.TimerExpression; import org.kie.api.runtime.Calendars; diff --git a/drools-core/src/main/java/org/drools/core/time/impl/IntervalTimer.java b/drools-core/src/main/java/org/drools/core/time/impl/IntervalTimer.java index da1075a9a2b..7ce093d2d34 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/IntervalTimer.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/IntervalTimer.java @@ -31,7 +31,7 @@ import org.drools.base.rule.Declaration; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.time.TimerExpression; import org.kie.api.runtime.Calendars; diff --git a/drools-core/src/main/java/org/drools/core/time/impl/JDKTimerService.java b/drools-core/src/main/java/org/drools/core/time/impl/JDKTimerService.java index b1139347745..d51be750ec0 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/JDKTimerService.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/JDKTimerService.java @@ -28,9 +28,8 @@ import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.core.time.InternalSchedulerService; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.core.time.TimerService; import org.kie.api.time.SessionClock; diff --git a/drools-core/src/main/java/org/drools/core/time/impl/PseudoClockScheduler.java b/drools-core/src/main/java/org/drools/core/time/impl/PseudoClockScheduler.java index 5be7a8f171f..f8049e27e61 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/PseudoClockScheduler.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/PseudoClockScheduler.java @@ -32,9 +32,8 @@ import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.core.time.InternalSchedulerService; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.core.time.SessionPseudoClock; import org.drools.core.time.TimerService; import org.slf4j.Logger; @@ -86,6 +85,10 @@ public TimerJobFactoryManager getTimerJobFactoryManager() { return this.jobFactoryManager; } + public PriorityQueue getQueue() { + return queue; + } + @Override public long getCurrentTime() { return this.timer.get(); diff --git a/drools-core/src/main/java/org/drools/core/time/impl/ThreadSafeTrackableTimeJobFactoryManager.java b/drools-core/src/main/java/org/drools/core/time/impl/ThreadSafeTrackableTimeJobFactoryManager.java index 7f49953865d..9e437db7520 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/ThreadSafeTrackableTimeJobFactoryManager.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/ThreadSafeTrackableTimeJobFactoryManager.java @@ -20,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap; -import org.drools.core.time.JobContext; +import org.drools.base.time.JobContext; import org.drools.core.time.SelfRemovalJobContext; public class ThreadSafeTrackableTimeJobFactoryManager extends TrackableTimeJobFactoryManager { diff --git a/drools-core/src/main/java/org/drools/core/time/impl/TrackableTimeJobFactoryManager.java b/drools-core/src/main/java/org/drools/core/time/impl/TrackableTimeJobFactoryManager.java index 5a7dfc353e0..2c3098d8ec4 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/TrackableTimeJobFactoryManager.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/TrackableTimeJobFactoryManager.java @@ -25,9 +25,8 @@ import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; import org.drools.core.time.EnqueuedSelfRemovalJobContext; -import org.drools.core.time.InternalSchedulerService; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.core.time.SelfRemovalJob; import org.drools.core.time.SelfRemovalJobContext; diff --git a/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java b/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java index 66854a69c2a..7c121541f1a 100644 --- a/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java +++ b/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Stack; +import org.drools.base.base.ValueResolver; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; import org.drools.core.ClockType; @@ -37,8 +38,8 @@ import org.drools.core.common.ReteEvaluator; import org.drools.core.impl.RuleBaseFactory; import org.drools.core.phreak.PropagationEntry; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.core.time.TimerService; import org.junit.Test; @@ -143,7 +144,7 @@ public List getList() { } @Override - public ReteEvaluator getReteEvaluator() { + public ValueResolver getValueResolver() { return (ReteEvaluator) Proxy.newProxyInstance( InternalWorkingMemory.class.getClassLoader(), new Class[]{InternalWorkingMemory.class}, new InvocationHandler() { diff --git a/drools-core/src/test/java/org/drools/core/time/impl/PseudoClockSchedulerTest.java b/drools-core/src/test/java/org/drools/core/time/impl/PseudoClockSchedulerTest.java index 4295f434578..2375811030d 100644 --- a/drools-core/src/test/java/org/drools/core/time/impl/PseudoClockSchedulerTest.java +++ b/drools-core/src/test/java/org/drools/core/time/impl/PseudoClockSchedulerTest.java @@ -19,13 +19,12 @@ package org.drools.core.time.impl; import java.util.Date; -import java.util.Optional; import java.util.concurrent.TimeUnit; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -86,7 +85,7 @@ public class PseudoClockSchedulerTest { final Date triggerTime = new Date(1000); when( mockTrigger_1.hasNextFireTime() ).thenReturn(triggerTime, triggerTime, triggerTime, null); when( mockTrigger_1.nextFireTime() ).thenReturn(triggerTime); - when(mockContext_1.getInternalKnowledgeRuntime()).thenReturn(Optional.empty()); + //when(mockContext_1.getInternalKnowledgeRuntime()).thenReturn(Optional.empty()); Job job = new Job() { public void execute(JobContext ctx) { @@ -111,7 +110,7 @@ public void execute(JobContext ctx) { final Date triggerTime = new Date(1000); when( mockTrigger_1.hasNextFireTime() ).thenReturn(triggerTime, triggerTime, triggerTime, null); when( mockTrigger_1.nextFireTime() ).thenReturn(triggerTime); - when(mockContext_1.getInternalKnowledgeRuntime()).thenReturn(Optional.empty()); + //when(mockContext_1.getInternalKnowledgeRuntime()).thenReturn(Optional.empty()); Job job = new Job() { public void execute(JobContext ctx) { diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/agenda/DefaultAgenda.java b/drools-kiesession/src/main/java/org/drools/kiesession/agenda/DefaultAgenda.java index cd8978d3092..fea92b0b359 100644 --- a/drools-kiesession/src/main/java/org/drools/kiesession/agenda/DefaultAgenda.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/agenda/DefaultAgenda.java @@ -56,9 +56,11 @@ import org.drools.core.phreak.SynchronizedBypassPropagationList; import org.drools.core.phreak.SynchronizedPropagationList; import org.drools.core.phreak.ThreadUnsafePropagationList; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.AgendaComponentFactory; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.PathMemory; +import org.drools.core.reteoo.Rete; import org.drools.core.reteoo.RuleTerminalNodeLeftTuple; import org.drools.core.reteoo.TerminalNode; import org.drools.core.rule.consequence.ConsequenceExceptionHandler; @@ -752,7 +754,7 @@ public boolean tryDeactivate() { return executionStateMachine.tryDeactivate(); } - static class Halt extends PropagationEntry.AbstractPropagationEntry { + static class Halt extends AbstractPropagationEntry { private final ExecutionStateMachine executionStateMachine; @@ -772,7 +774,7 @@ public String toString() { } } - static class ImmediateHalt extends PropagationEntry.AbstractPropagationEntry { + static class ImmediateHalt extends AbstractPropagationEntry { private final ExecutionStateMachine executionStateMachine; private final PropagationList propagationList; diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/consequence/StatefulKnowledgeSessionForRHS.java b/drools-kiesession/src/main/java/org/drools/kiesession/consequence/StatefulKnowledgeSessionForRHS.java index 4d6c832b9e1..18fdf662a9d 100644 --- a/drools-kiesession/src/main/java/org/drools/kiesession/consequence/StatefulKnowledgeSessionForRHS.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/consequence/StatefulKnowledgeSessionForRHS.java @@ -67,6 +67,7 @@ import org.kie.api.runtime.Globals; import org.kie.api.runtime.KieRuntime; import org.kie.api.runtime.KieSession; +import org.kie.api.runtime.KieSessionConfiguration; import org.kie.api.runtime.ObjectFilter; import org.kie.api.runtime.process.ProcessInstance; import org.kie.api.runtime.process.WorkItemManager; @@ -570,6 +571,11 @@ public SessionConfiguration getSessionConfiguration() { return delegate.getSessionConfiguration(); } + @Override + public KieSessionConfiguration getKieSessionConfiguration() { + return delegate.getKieSessionConfiguration(); + } + public Collection getObjects() { return delegate.getObjects(); } diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/session/StatefulKnowledgeSessionImpl.java b/drools-kiesession/src/main/java/org/drools/kiesession/session/StatefulKnowledgeSessionImpl.java index 70f726a296e..f5915866102 100644 --- a/drools-kiesession/src/main/java/org/drools/kiesession/session/StatefulKnowledgeSessionImpl.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/session/StatefulKnowledgeSessionImpl.java @@ -39,7 +39,6 @@ import org.drools.core.base.QueryRowWithSubruleIndex; import org.drools.core.base.StandardQueryViewChangedEventListener; import org.drools.core.common.ActivationsManager; -import org.drools.core.common.BaseNode; import org.drools.core.common.ConcurrentNodeMemories; import org.drools.core.common.EndOperationListener; import org.drools.core.common.EventSupport; @@ -65,11 +64,13 @@ import org.drools.core.management.DroolsManagementAgent; import org.drools.core.marshalling.MarshallerReaderContext; import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.ExecuteQuery; +import org.drools.core.phreak.actions.PropagationEntryWithResult; import org.drools.core.phreak.RuleAgendaItem; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.AsyncReceiveNode; import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.LeftInputAdapterNode; -import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.QueryTerminalNode; @@ -713,7 +714,7 @@ public LiveQuery openLiveQuery(final String query, } private QueryTerminalNode[] evalQuery(final String queryName, final DroolsQueryImpl queryObject, final InternalFactHandle handle, final PropagationContext pCtx, final boolean isCalledFromRHS) { - PropagationEntry.ExecuteQuery executeQuery = new PropagationEntry.ExecuteQuery( queryName, queryObject, handle, pCtx, isCalledFromRHS); + ExecuteQuery executeQuery = new ExecuteQuery(queryName, queryObject, handle, pCtx, isCalledFromRHS); addPropagation( executeQuery ); return executeQuery.getResult(); } @@ -730,7 +731,7 @@ public void closeLiveQuery(final InternalFactHandle factHandle) { } } - private class ExecuteCloseLiveQuery extends PropagationEntry.PropagationEntryWithResult { + private class ExecuteCloseLiveQuery extends PropagationEntryWithResult { private final InternalFactHandle factHandle; @@ -833,6 +834,11 @@ public RuleSessionConfiguration getRuleSessionConfiguration() { return this.config.as(SessionConfiguration.KEY); } + @Override + public KieSessionConfiguration getKieSessionConfiguration() { + return config; + } + public void reset() { if (nodeMemories != null) { nodeMemories.resetAllMemories( this ); @@ -1234,7 +1240,7 @@ public FactHandle insert(final Object object, } public void submit(AtomicAction action) { - agenda.addPropagation( new PropagationEntry.AbstractPropagationEntry() { + agenda.addPropagation( new AbstractPropagationEntry() { @Override public void internalExecute(ReteEvaluator reteEvaluator ) { action.execute( (KieSession)reteEvaluator ); diff --git a/drools-kiesession/src/test/java/org/drools/kiesession/ReteooWorkingMemoryTest.java b/drools-kiesession/src/test/java/org/drools/kiesession/ReteooWorkingMemoryTest.java index c59f1f773ac..04b0d69228d 100644 --- a/drools-kiesession/src/test/java/org/drools/kiesession/ReteooWorkingMemoryTest.java +++ b/drools-kiesession/src/test/java/org/drools/kiesession/ReteooWorkingMemoryTest.java @@ -30,7 +30,7 @@ import org.drools.core.common.TruthMaintenanceSystem; import org.drools.core.common.TruthMaintenanceSystemFactory; import org.drools.core.common.WorkingMemoryAction; -import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.Rete; import org.drools.core.reteoo.builder.NodeFactory; @@ -201,7 +201,7 @@ public void testDifferentEntryPointsOnSameFact() { } private static class ReentrantAction - extends PropagationEntry.AbstractPropagationEntry + extends AbstractPropagationEntry implements WorkingMemoryAction { // I am using AtomicInteger just as an int wrapper... nothing to do with concurrency here public AtomicInteger counter = new AtomicInteger(0); diff --git a/drools-metric/src/main/java/org/drools/metric/phreak/MetricPhreakNetworkNodeFactoryImpl.java b/drools-metric/src/main/java/org/drools/metric/phreak/MetricPhreakNetworkNodeFactoryImpl.java index c71d6b9e837..1ff743ee81e 100644 --- a/drools-metric/src/main/java/org/drools/metric/phreak/MetricPhreakNetworkNodeFactoryImpl.java +++ b/drools-metric/src/main/java/org/drools/metric/phreak/MetricPhreakNetworkNodeFactoryImpl.java @@ -34,6 +34,7 @@ import org.drools.core.phreak.PhreakReactiveFromNode; import org.drools.core.phreak.PhreakRuleTerminalNode; import org.drools.core.phreak.PhreakTimerNode; +import org.drools.core.reteoo.SequenceNode.PhreakSequenceNode; import org.drools.metric.util.MetricLogUtils; public class MetricPhreakNetworkNodeFactoryImpl implements PhreakNetworkNodeFactory { @@ -137,6 +138,14 @@ public PhreakTimerNode createPhreakTimerNode() { } } + public PhreakSequenceNode createPhreakSequenceNode() { + if (MetricLogUtils.getInstance().isEnabled()) { + return new PhreakSequenceNodeMetric(); + } else { + return new PhreakSequenceNode(); + } + } + @Override public PhreakAsyncSendNode createPhreakAsyncSendNode() { if (MetricLogUtils.getInstance().isEnabled()) { diff --git a/drools-metric/src/main/java/org/drools/metric/phreak/PhreakSequenceNodeMetric.java b/drools-metric/src/main/java/org/drools/metric/phreak/PhreakSequenceNodeMetric.java new file mode 100644 index 00000000000..c0af0271e04 --- /dev/null +++ b/drools-metric/src/main/java/org/drools/metric/phreak/PhreakSequenceNodeMetric.java @@ -0,0 +1,34 @@ +package org.drools.metric.phreak; + +import org.drools.core.common.ReteEvaluator; +import org.drools.core.common.TupleSets; +import org.drools.core.reteoo.AsyncSendNode; +import org.drools.core.reteoo.AsyncSendNode.AsyncSendMemory; +import org.drools.core.reteoo.LeftTupleSink; +import org.drools.core.reteoo.SequenceNode; +import org.drools.core.reteoo.SequenceNode.PhreakSequenceNode; +import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; +import org.drools.metric.util.MetricLogUtils; + +public class PhreakSequenceNodeMetric extends PhreakSequenceNode { + @Override + public void doNode(SequenceNode node, + SequenceNodeMemory memory, + LeftTupleSink sink, + ReteEvaluator reteEvaluator, + TupleSets srcLeftTuples, + TupleSets trgLeftTuples, + TupleSets stagedLeftTuples) { + + try { + MetricLogUtils.getInstance().startMetrics(node); + + super.doNode(node, memory, + sink, reteEvaluator, + srcLeftTuples, trgLeftTuples, stagedLeftTuples); + + } finally { + MetricLogUtils.getInstance().logAndEndMetrics(); + } + } +} diff --git a/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/KiePackagesBuilder.java b/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/KiePackagesBuilder.java index 7c4a0af6e84..3aebe3e1cec 100644 --- a/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/KiePackagesBuilder.java +++ b/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/KiePackagesBuilder.java @@ -72,7 +72,7 @@ import org.drools.base.rule.accessor.ReadAccessor; import org.drools.base.rule.accessor.Salience; import org.drools.base.rule.constraint.QueryNameConstraint; -import org.drools.base.time.impl.Timer; +import org.drools.base.time.Timer; import org.drools.core.base.ClassFieldAccessorCache; import org.drools.core.base.DroolsQueryImpl; import org.drools.core.base.accumulators.CountAccumulateFunction; diff --git a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java index da779a80fbd..466fdde0dd8 100644 --- a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java +++ b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java @@ -23,9 +23,9 @@ import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; -import org.drools.core.time.InternalSchedulerService; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.core.time.impl.InternalSchedulerService; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.core.time.SelfRemovalJob; import org.drools.core.time.SelfRemovalJobContext; import org.drools.base.time.Trigger; diff --git a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java index d7b225cab9d..0e5ffddba7a 100644 --- a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java +++ b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java @@ -19,9 +19,9 @@ package org.drools.persistence.jpa; import org.kie.api.runtime.ExecutableRunner; -import org.drools.core.time.InternalSchedulerService; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.core.time.impl.InternalSchedulerService; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.base.time.JobHandle; import org.drools.core.time.SelfRemovalJob; import org.drools.base.time.Trigger; diff --git a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java index b25d76849ac..968c92220a2 100644 --- a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java +++ b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java @@ -19,9 +19,9 @@ package org.drools.persistence.jpa; import org.kie.api.runtime.ExecutableRunner; -import org.drools.core.time.InternalSchedulerService; -import org.drools.core.time.Job; -import org.drools.core.time.JobContext; +import org.drools.core.time.impl.InternalSchedulerService; +import org.drools.base.time.Job; +import org.drools.base.time.JobContext; import org.drools.base.time.JobHandle; import org.drools.core.time.TimerService; import org.drools.base.time.Trigger; diff --git a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableSessionInitializer.java b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableSessionInitializer.java index 049fd4f66b0..010a21c49dd 100644 --- a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableSessionInitializer.java +++ b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableSessionInitializer.java @@ -29,6 +29,7 @@ import org.drools.core.common.InternalWorkingMemoryEntryPoint; import org.drools.core.common.Storage; import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.Insert; import org.drools.reliability.core.util.ReliabilityUtils; import org.kie.api.event.rule.AfterMatchFiredEvent; import org.kie.api.event.rule.DefaultAgendaEventListener; @@ -85,8 +86,8 @@ public InternalWorkingMemory init(InternalWorkingMemory session, PersistedSessio } private void onWorkingMemoryAction(InternalWorkingMemory session, PropagationEntry entry) { - if (entry instanceof PropagationEntry.Insert) { - InternalFactHandle fh = ((PropagationEntry.Insert) entry).getHandle(); + if (entry instanceof Insert) { + InternalFactHandle fh = ((Insert) entry).getHandle(); if (fh.isValid()) { WorkingMemoryEntryPoint ep = fh.getEntryPoint(session); ((SimpleReliableObjectStore) ep.getObjectStore()).putIntoPersistedStorage(fh, true); diff --git a/drools-ruleunits/drools-ruleunits-impl/src/main/java/org/drools/ruleunits/impl/sessions/RuleUnitExecutorImpl.java b/drools-ruleunits/drools-ruleunits-impl/src/main/java/org/drools/ruleunits/impl/sessions/RuleUnitExecutorImpl.java index 40d59cda7e7..daf2e8d0b56 100644 --- a/drools-ruleunits/drools-ruleunits-impl/src/main/java/org/drools/ruleunits/impl/sessions/RuleUnitExecutorImpl.java +++ b/drools-ruleunits/drools-ruleunits-impl/src/main/java/org/drools/ruleunits/impl/sessions/RuleUnitExecutorImpl.java @@ -36,7 +36,6 @@ import org.drools.core.base.NonCloningQueryViewListener; import org.drools.core.base.QueryRowWithSubruleIndex; import org.drools.core.common.ActivationsManager; -import org.drools.core.common.BaseNode; import org.drools.core.common.ConcurrentNodeMemories; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.InternalWorkingMemoryEntryPoint; @@ -54,6 +53,7 @@ import org.drools.core.impl.ActivationsManagerImpl; import org.drools.core.impl.InternalRuleBase; import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.ExecuteQuery; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.RuntimeComponentFactory; import org.drools.core.reteoo.TerminalNode; @@ -72,6 +72,7 @@ import org.kie.api.runtime.Calendars; import org.kie.api.runtime.Channel; import org.kie.api.runtime.KieRuntime; +import org.kie.api.runtime.KieSessionConfiguration; import org.kie.api.runtime.rule.AgendaFilter; import org.kie.api.runtime.rule.EntryPoint; import org.kie.api.runtime.rule.FactHandle; @@ -230,6 +231,11 @@ public RuleSessionConfiguration getRuleSessionConfiguration() { return sessionConfiguration.as(RuleSessionConfiguration.KEY); } + @Override + public KieSessionConfiguration getKieSessionConfiguration() { + return sessionConfiguration; + } + @Override public RuleEventListenerSupport getRuleEventSupport() { return ruleEventListenerSupport; @@ -317,7 +323,7 @@ public QueryResults getQueryResults(String queryName, Object... arguments) { final PropagationContext pCtx = new PhreakPropagationContext(getNextPropagationIdCounter(), PropagationContext.Type.INSERTION, null, null, handle, getDefaultEntryPointId()); - PropagationEntry.ExecuteQuery executeQuery = new PropagationEntry.ExecuteQuery( queryName, queryObject, handle, pCtx, false); + ExecuteQuery executeQuery = new ExecuteQuery(queryName, queryObject, handle, pCtx, false); addPropagation( executeQuery ); TerminalNode[] terminalNodes = executeQuery.getResult(); diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/ProtobufOutputMarshaller.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/ProtobufOutputMarshaller.java index 9330b44bad2..37774be1bc0 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/ProtobufOutputMarshaller.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/ProtobufOutputMarshaller.java @@ -52,7 +52,7 @@ import org.drools.core.reteoo.Sink; import org.drools.core.reteoo.TerminalNode; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.time.JobContext; +import org.drools.base.time.JobContext; import org.drools.core.time.SelfRemovalJobContext; import org.drools.core.time.impl.CompositeMaxDurationTrigger; import org.drools.core.time.impl.CronTrigger; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/TimersOutputMarshaller.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/TimersOutputMarshaller.java index b54c87458b9..857bedbf459 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/TimersOutputMarshaller.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/TimersOutputMarshaller.java @@ -19,7 +19,7 @@ package org.drools.serialization.protobuf; import org.drools.core.marshalling.MarshallerWriteContext; -import org.drools.core.time.JobContext; +import org.drools.base.time.JobContext; public interface TimersOutputMarshaller { diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/WorkingMemoryReteAssertAction.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/WorkingMemoryReteAssertAction.java index b4754de80f2..59a513b27c5 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/WorkingMemoryReteAssertAction.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/WorkingMemoryReteAssertAction.java @@ -27,14 +27,14 @@ import org.drools.base.definitions.InternalKnowledgePackage; import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.core.marshalling.MarshallerReaderContext; -import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.RuntimeComponentFactory; import org.drools.core.common.PropagationContext; import org.drools.core.reteoo.TerminalNode; import org.drools.core.reteoo.Tuple; public class WorkingMemoryReteAssertAction - extends PropagationEntry.AbstractPropagationEntry + extends AbstractPropagationEntry implements WorkingMemoryAction { protected InternalFactHandle factHandle; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/actions/ProtobufWorkingMemoryReteAssertAction.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/actions/ProtobufWorkingMemoryReteAssertAction.java index 8dc59dbcda7..26a3c8d6937 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/actions/ProtobufWorkingMemoryReteAssertAction.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/actions/ProtobufWorkingMemoryReteAssertAction.java @@ -19,6 +19,7 @@ package org.drools.serialization.protobuf.actions; import org.drools.base.definitions.InternalKnowledgePackage; +import org.drools.core.common.ReteEvaluator; import org.drools.serialization.protobuf.WorkingMemoryReteAssertAction; import org.drools.core.marshalling.MarshallerReaderContext; import org.drools.core.marshalling.MarshallerWriteContext; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/BehaviorJobContextTimerOutputMarshaller.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/BehaviorJobContextTimerOutputMarshaller.java index 2249314d2aa..e73b794dc11 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/BehaviorJobContextTimerOutputMarshaller.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/BehaviorJobContextTimerOutputMarshaller.java @@ -25,7 +25,7 @@ import org.drools.serialization.protobuf.marshalling.PersisterEnums; import org.drools.core.rule.SlidingTimeWindow.BehaviorJobContext; import org.drools.core.rule.SlidingTimeWindow.SlidingTimeWindowContext; -import org.drools.core.time.JobContext; +import org.drools.base.time.JobContext; import org.drools.serialization.protobuf.ProtobufMessages; import org.drools.serialization.protobuf.TimersOutputMarshaller; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerInputMarshaller.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerInputMarshaller.java index 73f7378283b..4cd2959a38c 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerInputMarshaller.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerInputMarshaller.java @@ -24,7 +24,7 @@ import org.drools.core.marshalling.MarshallerReaderContext; import org.drools.core.reteoo.ObjectTypeNode.ExpireJob; import org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext; -import org.drools.core.time.JobContext; +import org.drools.base.time.JobContext; import org.drools.base.time.JobHandle; import org.drools.core.time.TimerService; import org.drools.core.time.impl.DefaultJobHandle; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerOutputMarshaller.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerOutputMarshaller.java index b24ab0a9210..c1794c3d833 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerOutputMarshaller.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerOutputMarshaller.java @@ -25,7 +25,7 @@ import org.drools.core.marshalling.MarshallerWriteContext; import org.drools.serialization.protobuf.marshalling.PersisterEnums; import org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext; -import org.drools.core.time.JobContext; +import org.drools.base.time.JobContext; import org.drools.core.time.impl.DefaultJobHandle; import org.drools.core.time.impl.PointInTimeTrigger; import org.drools.serialization.protobuf.ProtobufMessages; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/TimerNodeTimerOutputMarshaller.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/TimerNodeTimerOutputMarshaller.java index 500c8507032..16f8f1d3223 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/TimerNodeTimerOutputMarshaller.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/TimerNodeTimerOutputMarshaller.java @@ -20,7 +20,7 @@ import org.drools.core.marshalling.MarshallerWriteContext; import org.drools.core.phreak.PhreakTimerNode.TimerNodeJobContext; -import org.drools.core.time.JobContext; +import org.drools.base.time.JobContext; import org.drools.serialization.protobuf.PersisterHelper; import org.drools.serialization.protobuf.ProtobufMessages; import org.drools.serialization.protobuf.ProtobufOutputMarshaller; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/command/PropagationListTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/command/PropagationListTest.java index b98f83ab365..aaa9cafa8bb 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/command/PropagationListTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/command/PropagationListTest.java @@ -25,9 +25,9 @@ import java.util.concurrent.Executors; import org.drools.core.common.ReteEvaluator; -import org.drools.core.phreak.PropagationEntry; import org.drools.core.phreak.PropagationList; import org.drools.core.phreak.SynchronizedPropagationList; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.junit.Ignore; import org.junit.Test; @@ -125,7 +125,7 @@ public Boolean call() throws Exception { }; } - public static class TestEntry extends PropagationEntry.AbstractPropagationEntry { + public static class TestEntry extends AbstractPropagationEntry { final Checker checker; final int i; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/A.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/A.java index 3d93df01656..87e59b5bcc8 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/A.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/A.java @@ -18,13 +18,19 @@ */ package org.drools.mvel.integrationtests.phreak; +import org.kie.api.definition.type.Expires; import org.kie.api.definition.type.Position; +import org.kie.api.definition.type.Role; +import org.kie.api.definition.type.Role.Type; public class A { @Position(0) Integer object; + @Position(1) + String text; + public A(Integer object) { super(); this.object = object; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/B.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/B.java index e110ffeee58..077f0f01656 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/B.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/B.java @@ -18,18 +18,30 @@ */ package org.drools.mvel.integrationtests.phreak; +import org.kie.api.definition.type.Expires; import org.kie.api.definition.type.Position; +import org.kie.api.definition.type.Role; +import org.kie.api.definition.type.Role.Type; +@Expires(value = "5s") +@Role(value = Type.EVENT) public class B { @Position(0) Object object; + @Position(1) + String text; + public B(Object object) { - super(); this.object = object; } + public B(Object object, String text) { + this.object = object; + this.text = text; + } + public static B b(Object object) { return new B( object ); } @@ -51,6 +63,14 @@ public void setObject(Object object) { this.object = object; } + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + @Override public int hashCode() { final int prime = 31; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/C.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/C.java index aa5fb26edc0..afd7f84fee7 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/C.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/C.java @@ -18,18 +18,30 @@ */ package org.drools.mvel.integrationtests.phreak; +import org.kie.api.definition.type.Expires; import org.kie.api.definition.type.Position; +import org.kie.api.definition.type.Role; +import org.kie.api.definition.type.Role.Type; +@Expires(value = "5s") +@Role(value = Type.EVENT) public class C { @Position(0) Object object; + @Position(1) + String text; + public C(Object object) { - super(); this.object = object; } + public C(Object object, String text) { + this.object = object; + this.text = text; + } + public static C c(Object object) { return new C( object ); } @@ -51,6 +63,14 @@ public void setObject(Object object) { this.object = object; } + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + @Override public int hashCode() { final int prime = 31; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/D.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/D.java new file mode 100644 index 00000000000..a1709d2fcb5 --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/D.java @@ -0,0 +1,99 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak; + +import org.kie.api.definition.type.Expires; +import org.kie.api.definition.type.Position; +import org.kie.api.definition.type.Role; +import org.kie.api.definition.type.Role.Type; + +@Expires(value = "5s") +@Role(value = Type.EVENT) +public class D { + + @Position(0) + Object object; + + @Position(1) + String text; + + public D(Object object) { + this.object = object; + } + + public D(Object object, String text) { + this.object = object; + this.text = text; + } + + public static D c(Object object) { + return new D(object ); + } + + public static D[] c(Object... objects) { + D[] cs = new D[objects.length]; + int i = 0; + for ( Object object : objects ) { + cs[i++] = new D(object ); + } + return cs; + } + + public Object getObject() { + return object; + } + + public void setObject(Object object) { + this.object = object; + } + + public Object getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((object == null) ? 0 : object.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) return true; + if ( obj == null ) return false; + if ( getClass() != obj.getClass() ) return false; + D other = (D) obj; + if ( object == null ) { + if ( other.object != null ) return false; + } else if ( !object.equals( other.object ) ) return false; + return true; + } + + @Override + public String toString() { + return "D [" + object + "]"; + } + +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/E.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/E.java index 55e403e3c7b..3c99f88cff0 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/E.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/E.java @@ -25,11 +25,19 @@ public class E { @Position(0) Object object; + @Position(1) + String text; + public E(Object object) { super(); this.object = object; } + public E(Object object, String text) { + this.object = object; + this.text = text; + } + public static E e(Object object) { return new E( object ); } @@ -59,6 +67,14 @@ public int hashCode() { return result; } + public Object getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + @Override public boolean equals(Object obj) { if ( this == obj ) return true; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java new file mode 100644 index 00000000000..cfd77523bd0 --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java @@ -0,0 +1,83 @@ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.definitions.InternalKnowledgePackage; +import org.drools.base.definitions.rule.impl.RuleImpl; +import org.drools.core.ClockType; +import org.drools.core.SessionConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.impl.KnowledgeBaseImpl; +import org.drools.core.impl.RuleBaseFactory; +import org.drools.core.reteoo.CoreComponentFactory; +import org.drools.core.reteoo.LeftTuple; +import org.drools.core.reteoo.MockLeftTupleSink; +import org.drools.core.reteoo.SequenceNode; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; +import org.drools.core.reteoo.builder.BuildContext; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.SequencerMemory; +import org.drools.core.rule.JavaDialectRuntimeData; +import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; +import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; +import org.drools.mvel.integrationtests.phreak.A; +import org.kie.api.runtime.conf.ThreadSafeOption; +import org.kie.internal.conf.CompositeBaseConfiguration; + +import java.util.Collections; + +public class AbstractPhreakSequencerSubsequenceTest { + StatefulKnowledgeSessionImpl session; + SequenceNodeMemory nodeMemory; + SequencerMemory sequencerMemory; + BuildContext buildContext; + Sequence seq0; + Sequence seq1; + Sequence seq2; + SequenceNode mnode; + + DynamicFilterProto bfilter; + DynamicFilterProto cfilter; + DynamicFilterProto dfilter; + DynamicFilterProto efilter; + + public static BuildContext createContext() { + + CompositeBaseConfiguration conf = (CompositeBaseConfiguration) RuleBaseFactory.newKnowledgeBaseConfiguration(); + + KnowledgeBaseImpl rbase = new KnowledgeBaseImpl("ID", + conf ); + BuildContext buildContext = new BuildContext(rbase, Collections.emptyList() ); + + RuleImpl rule = new RuleImpl("rule1").setPackage("org.pkg1"); + InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("org.pkg1"); + pkg.getDialectRuntimeRegistry().setDialectData( "java", new JavaDialectRuntimeData()); + + pkg.addRule( rule ); + buildContext.setRule( rule ); + + return buildContext; + } + + void createSession() { + SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.NO); + sessionConf.setClockType(ClockType.PSEUDO_CLOCK); + + if (session != null) { + nodeMemory = null; + sequencerMemory = null; + session.dispose(); + session = null; + } + + session = (StatefulKnowledgeSessionImpl) kbase.newKieSession(sessionConf, null); + + InternalFactHandle fhA0 = (InternalFactHandle) session.insert(new A(0)); + nodeMemory = session.getNodeMemory(mnode); + LeftTuple lt = new LeftTuple(fhA0, mnode, true); + lt.setContextObject(mnode.createSequencerMemory(lt, new MockLeftTupleSink(buildContext.getNextNodeId(), buildContext), nodeMemory)); + nodeMemory.getLeftTupleMemory().add(lt); + sequencerMemory = (SequencerMemory) lt.getContextObject(); + } +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/CircularArrayListTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/CircularArrayListTest.java new file mode 100644 index 00000000000..ceae52e054c --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/CircularArrayListTest.java @@ -0,0 +1,60 @@ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.core.util.CircularArrayList; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class CircularArrayListTest { + + @Test + public void testAddingWithWrap() { + CircularArrayList list = new CircularArrayList<>(10); + + for (int i = 0; i < 15; i++) { + list.add(i); + } + + System.out.println(list); + assertThat(list.size()).isEqualTo(15); + assertThat(list.get(list.size()-1)).isEqualTo(14); + assertThat(list.get(14)).isEqualTo(14); + assertThat(list.getHead()).isEqualTo(14); + assertThat(list.getHeadMinus(3)).isEqualTo(11); + + assertThatThrownBy(() -> list.get(-1)).isInstanceOf(IndexOutOfBoundsException.class); + assertThatThrownBy(() -> list.get(0)).isInstanceOf(IndexOutOfBoundsException.class); + assertThatThrownBy(() -> list.get(4)).isInstanceOf(IndexOutOfBoundsException.class); + assertThat(list.get(5)).isEqualTo(5); + } + + @Test + public void testToArray() { + CircularArrayList list = new CircularArrayList<>(10); + assertThat(list.toArray().length).isEqualTo(0); + list.add(0); + assertThat(list.toArray()).isEqualTo(new Object[] {0}); + list.add(1); + assertThat(list.toArray()).isEqualTo(new Object[] {0, 1}); + list.add(2); + list.add(3); + list.add(4); + list.add(5); + list.add(6); + list.add(7); + list.add(8); + assertThat(list.toArray()).isEqualTo(new Object[] {0, 1, 2, 3, 4, 5, 6, 7, 8}); + list.add(9); + assertThat(list.toArray()).isEqualTo(new Object[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + list.add(10); + assertThat(list.toArray()).isEqualTo(new Object[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); + list.add(11); + list.add(12); + list.add(13); + list.add(14); + list.add(15); + assertThat(list.toArray()).isEqualTo(new Object[] {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}); + } + +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java new file mode 100644 index 00000000000..5c0238147a4 --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java @@ -0,0 +1,152 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ValueResolver; +import org.drools.base.common.RuleBasePartitionId; +import org.drools.base.reteoo.BaseTuple; +import org.drools.base.rule.Declaration; +import org.drools.base.rule.EntryPointId; +import org.drools.base.rule.MutableTypeConstraint; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.reteoo.CoreComponentFactory; +import org.drools.core.reteoo.EntryPointNode; +import org.drools.core.reteoo.LeftTupleSource; +import org.drools.core.reteoo.ObjectRouter; +import org.drools.core.reteoo.SequenceNode; +import org.drools.core.reteoo.SequenceNode.AlphaAdapter; +import org.drools.core.reteoo.ObjectSource; +import org.drools.core.reteoo.ObjectTypeNode; +import org.drools.core.reteoo.builder.BuildContext; +import org.drools.core.reteoo.builder.NodeFactory; +import org.kie.api.runtime.rule.FactHandle; + +public class MultiInputNodeBuilder { + BuildContext buildContext; + + public MultiInputNodeBuilder(BuildContext buildContext) { + this.buildContext = buildContext; + } + + public static MultiInputNodeBuilder create(BuildContext buildContext) { + return new MultiInputNodeBuilder(buildContext); + } + + public SequenceNode buildNode(Class leftType, Class[] rightTypes) { + NodeFactory nFactory = CoreComponentFactory.get().getNodeFactoryService(); + + EntryPointNode epn = buildContext.getRuleBase().getRete().getEntryPointNodes().get(EntryPointId.DEFAULT); + + buildContext.setCurrentEntryPoint(epn.getEntryPoint()); + buildContext.setTupleMemoryEnabled(true); + buildContext.setPartitionId(RuleBasePartitionId.MAIN_PARTITION); + + ObjectTypeNode otn = nFactory.buildObjectTypeNode(buildContext.getNextNodeId(), + epn, + new ClassObjectType(leftType), + buildContext); + LeftTupleSource leftTs = nFactory.buildLeftInputAdapterNode(buildContext.getNextNodeId(), otn, + buildContext, false); + + ObjectSource[] otns = new ObjectSource[rightTypes.length]; + for ( int i = 0; i < rightTypes.length; i++ ) { + otns[i] = nFactory.buildObjectTypeNode(buildContext.getNextNodeId(), epn, + new ClassObjectType(rightTypes[i]), + buildContext); + + otns[i].attach(buildContext); + } + + + SequenceNode mn = new SequenceNode(buildContext.getNextNodeId(), + leftTs, buildContext); + + AlphaAdapter[] adapters = new AlphaAdapter[rightTypes.length]; + for ( int i = 0; i < rightTypes.length; i++ ) { + adapters[i] = new AlphaAdapter(buildContext.getNextNodeId(), otns[i], + buildContext.getPartitionId(), mn, i); + + adapters[i].attach(buildContext); + } + + mn.setAlphaAdapters(adapters); + + mn.attach(buildContext); + + return mn; + } + + public AlphaNodeFieldConstraint buildConstraint(Predicate1 predicate1) { + return new AlphaConstraint(predicate1); + } + + public static class AlphaConstraint extends MutableTypeConstraint { + private Predicate1 predicate1; + + public AlphaConstraint(Predicate1 predicate1) { + this.predicate1 = predicate1; + } + + @Override + public Declaration[] getRequiredDeclarations() { + return new Declaration[0]; + } + + @Override + public void replaceDeclaration(Declaration oldDecl, Declaration newDecl) { + + } + + @Override + public MutableTypeConstraint clone() { + return null; + } + + @Override + public boolean isTemporal() { + return false; + } + + @Override + public boolean isAllowed(FactHandle handle, ValueResolver valueResolver) { + return predicate1.test(handle.getObject()); + } + + @Override + public boolean isAllowedCachedLeft(Object context, FactHandle handle) { + return false; + } + + @Override + public boolean isAllowedCachedRight(BaseTuple tuple, Object context) { + return false; + } + + @Override + public Object createContext() { + return null; + } + } + + interface Predicate1 { + boolean test(A a); + } + +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java new file mode 100644 index 00000000000..1bd07d6619a --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java @@ -0,0 +1,149 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.SessionConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.core.util.CircularArrayList; +import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; +import org.kie.api.runtime.conf.ThreadSafeOption; +import org.kie.api.runtime.rule.FactHandle; + +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerActionTest extends AbstractPhreakSequencerSubsequenceTest { + + private List recorder = new ArrayList<>(); + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + recorder.clear(); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); + + DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + + LogicCircuit circuit1 = getLogicCircuit(); + + LogicCircuit circuit2 = getLogicCircuit(); + + seq0 = new Sequence(0, + Step.of(circuit1), + Step.of( m -> recorder.add(((FactHandle)m.getSequencerMemory().getEvents().getHead()).getObject())), + Step.of(circuit2), + Step.of( m -> recorder.add("spacer")), + Step.of( m -> recorder.add(((FactHandle)m.getSequencerMemory().getEvents().getHead()).getObject()))); + mnode.setSequencer(new Sequencer(seq0)); + mnode.setDynamicFilters(new DynamicFilterProto[] {bfilter}); + + SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.NO); + + createSession(); + } + + private LogicCircuit getLogicCircuit() { + LogicGate gate1 = get1InputLogicGate(); + gate1.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit1 = new LogicCircuit(gate1); + return circuit1; + } + + private static LogicGate get1InputLogicGate() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask), 0, + new int[]{0}, // B + new int[]{0}, // + 0); + return gate1; + } + + @Test + public void testAction() { + ArrayList stack = sequencerMemory.getSequenceStack(); + assertThat(stack.size()).isEqualTo(0); + + mnode.getSequencer().start(sequencerMemory, session); + + CircularArrayList events = sequencerMemory.getEvents(); + assertThat(events.size()).isEqualTo(0); + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(b(0)); + InternalFactHandle fhB1 = (InternalFactHandle) session.insert(b(1)); + assertThat(recorder).containsExactly(b(0), "spacer", b(1)); + } + + public B b(int i) { + return new B(i, "b"); + } + + public B[] b(int... nums) { + B[] bs = new B[nums.length]; + for (int i = 0; i < nums.length; i++) { + bs[i] = new B(nums[i], "b"); + } + + return bs; + } + + public Object[] to(CircularArrayList events) { + FactHandle[] facts = events.toArray(); + Object[] objs = new Object[facts.length]; + for(int i = 0; i < facts.length; i++) { + objs[i] = ((B)facts[i].getObject()).getObject(); + } + + return objs; + } + +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java new file mode 100644 index 00000000000..d210008e7c8 --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java @@ -0,0 +1,213 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.SessionConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.DynamicFilter; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.SignalAdapter; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.core.util.LinkedList; +import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.C; +import org.drools.mvel.integrationtests.phreak.D; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; +import org.kie.api.runtime.conf.ThreadSafeOption; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerActivateDeactivateStepTest extends AbstractPhreakSequencerSubsequenceTest { + + private SequenceMemory sequenceMemory; + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + final ObjectType cObjectType = new ClassObjectType(C.class); + final ObjectType dObjectType = new ClassObjectType(D.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); + + final Pattern cpattern = new Pattern(0, + cObjectType, + "c" ); + cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); + + final Pattern dpattern = new Pattern(0, + dObjectType, + "d" ); + dpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("d"))); + + DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + DynamicFilterProto cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); + DynamicFilterProto dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); + + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0, 1}, // B and C + new int[] {0, 1}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + gate1.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + LogicGate gate2 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),1, + new int[] {1, 2}, // C and D, C Filter is re-used + new int[] {2, 3}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + gate2.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit2 = new LogicCircuit(gate2); + + seq0 = new Sequence(0, Step.of(circuit1), Step.of(circuit2)); + mnode.setSequencer(new Sequencer(seq0)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter, dfilter}); + + SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.YES); + + createSession(); + + sequenceMemory = sequencerMemory.getSequenceMemory(seq0); + } + + @Test + public void testInitialisedMemories() { + // make sure these are empty + assertThat(nodeMemory.getFilters()).usingRecursiveComparison().isEqualTo(new DynamicFilter[3]); + assertThat(nodeMemory.getActiveFilters()).usingRecursiveComparison().isEqualTo(new LinkedList[3]); + assertThat(nodeMemory.getActiveFilters()).usingRecursiveComparison().isEqualTo(new LinkedList[3]); + assertThat(sequenceMemory.getActiveSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[4]); + assertThat(sequenceMemory.getSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[4]); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // sequence not yet started + } + + @Test + public void testActivateAfterFirstCircuitStep() { + // activate LogicCircuit1 and check filters are adapters are created and made active + mnode.getSequencer().start(sequencerMemory, session); + + DynamicFilter filter0 = nodeMemory.getFilters()[0]; // B + DynamicFilter filter1 = nodeMemory.getFilters()[1]; // C + // [2] D is null + + // DynamicFilters are created on demand from Protos + assertThat(nodeMemory.getFilters()).usingRecursiveComparison().isEqualTo(new DynamicFilter[] {filter0, filter1, null }); + + // Check correct activation of DynamicFilters + assertThat(nodeMemory.getActiveFilters()[0].size()).isEqualTo(1); // B is active + assertThat(nodeMemory.getActiveFilters()[0].getFirst()).isSameAs(filter0); + assertThat(nodeMemory.getActiveFilters()[1].size()).isEqualTo(1); // C is active + assertThat(nodeMemory.getActiveFilters()[1].getFirst()).isSameAs(filter1); + assertThat(nodeMemory.getActiveFilters()[2]).isNull(); // D is not yet active + + // Check correct activation of SignalAdapters + SignalAdapter signal0 = sequenceMemory.getSignalAdapters()[0]; + SignalAdapter signal1 = sequenceMemory.getSignalAdapters()[1]; + assertThat(sequenceMemory.getSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[] {signal0, signal1, null, null }); + assertThat(sequenceMemory.getActiveSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[] {signal0, signal1, null, null }); + } + + @Test + public void testDeactivateAndActivateAfterSecondCircuitStep() { + mnode.getSequencer().start(sequencerMemory, session); + + DynamicFilter filter0 = nodeMemory.getFilters()[0]; // B + DynamicFilter filter1 = nodeMemory.getFilters()[1]; // C + + SignalAdapter signal0 = sequenceMemory.getSignalAdapters()[0]; + SignalAdapter signal1 = sequenceMemory.getSignalAdapters()[1]; + + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // still step 0 + + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + // Next step, check everything was for LogicCircuit was de-activated and LogicCircuit1 was activated; + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(1); // Now step 1 + + DynamicFilter filter2 = nodeMemory.getFilters()[2]; // D was created from its Proto + + assertThat(nodeMemory.getFilters()).usingRecursiveComparison().isEqualTo(new DynamicFilter[] {filter0, filter1, filter2 }); // all three now created + + // Check correct activation of DynamicFilters + assertThat(nodeMemory.getActiveFilters()[0].size()).isEqualTo(0); // B is deactived and now empty + assertThat(nodeMemory.getActiveFilters()[1].size()).isEqualTo(1); // C remains active + assertThat(nodeMemory.getActiveFilters()[1].getFirst()).isSameAs(filter1); + assertThat(nodeMemory.getActiveFilters()[2].size()).isEqualTo(1); // D is now active + assertThat(nodeMemory.getActiveFilters()[2].getFirst()).isSameAs(filter2); + + // Check correct activation of SignalAdapters + SignalAdapter signal2 = sequenceMemory.getSignalAdapters()[2]; + SignalAdapter signal3 = sequenceMemory.getSignalAdapters()[3]; + + assertThat(sequenceMemory.getSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[] {signal0, signal1, signal2, signal3 }); + assertThat(sequenceMemory.getActiveSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[] {null, null, signal2, signal3 }); // 0 and 1 are no longer active + + // @formatter:on + } + + @Test + public void testDeactivateAfterEndStep() { + mnode.getSequencer().start(sequencerMemory, session); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(1); // step 1 + InternalFactHandle fhC1 = (InternalFactHandle) session.insert(new C(0, "c")); + InternalFactHandle fhD0 = (InternalFactHandle) session.insert(new D(0, "d")); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // Now step -1, which means it's finished. + + // make sure there are no active SignalAapters or active Filters. + assertThat(sequenceMemory.getActiveSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[] {null, null, null, null }); // 0 and 1 are no longer active + assertThat(nodeMemory.getActiveFilters()[0].size()).isEqualTo(0); + assertThat(nodeMemory.getActiveFilters()[1].size()).isEqualTo(0); + assertThat(nodeMemory.getActiveFilters()[2].size()).isEqualTo(0); + } +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java new file mode 100644 index 00000000000..31e13a3652c --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java @@ -0,0 +1,189 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.SessionConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.LoopController; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.core.util.CircularArrayList; +import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; +import org.kie.api.runtime.conf.ThreadSafeOption; +import org.kie.api.runtime.rule.FactHandle; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerAggregatorTest extends AbstractPhreakSequencerSubsequenceTest { + + private List recorder = new ArrayList<>(); + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + recorder.clear(); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); + + DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + + LogicCircuit circuit1 = getLogicCircuit(); + LogicCircuit circuit2 = getLogicCircuit(); + LogicCircuit circuit3 = getLogicCircuit(); + LogicCircuit circuit4 = getLogicCircuit(); + + seq1 = new Sequence(1, Step.of(circuit2), Step.of(circuit3)); + seq1.setController(new LoopController(m -> m.getCount() < 2)); + + Consumer aggregator = memory -> { + CircularArrayList events = memory.getSequencerMemory().getEvents(); + int eventsStartPosition = memory.getEventsStartPosition(); + + List r = (List) events.get(eventsStartPosition-1); + if (r == null) { + events.set(eventsStartPosition-1, recorder); + r = (List) events.get(eventsStartPosition-1); + } + + int end = events.size(); + for (int i = eventsStartPosition; i < end; i++) { + r.add(((FactHandle)(events.get(i))).getObject()); + } + }; + + seq1.setOutputSize(1); + seq0 = new Sequence(0, Step.of(circuit1), Step.of(seq1, aggregator), Step.of(circuit4)); + mnode.setSequencer(new Sequencer(seq0)); + mnode.setDynamicFilters(new DynamicFilterProto[] {bfilter}); + + SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.YES); + + createSession(); + } + + private LogicCircuit getLogicCircuit() { + LogicGate gate1 = get1InputLogicGate(); + gate1.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit1 = new LogicCircuit(gate1); + return circuit1; + } + + private static LogicGate get1InputLogicGate() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask), 0, + new int[]{0}, // B + new int[]{0}, // + 0); + return gate1; + } + + @Test + public void testSequenceEventsMemory() { + ArrayList stack = sequencerMemory.getSequenceStack(); + assertThat(stack.size()).isEqualTo(0); + + mnode.getSequencer().start(sequencerMemory, session); + + CircularArrayList events = sequencerMemory.getEvents(); + assertThat(events.size()).isEqualTo(0); + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(b(0)); + assertThat(recorder.isEmpty()).isTrue(); + InternalFactHandle fhB1 = (InternalFactHandle) session.insert(b(1)); + assertThat(recorder.isEmpty()).isTrue(); + InternalFactHandle fhB2 = (InternalFactHandle) session.insert(b(2)); + assertThat(recorder).containsExactly(b(1, 2)); + InternalFactHandle fhB3 = (InternalFactHandle) session.insert(b(3)); + assertThat(recorder).containsExactly(b(1, 2)); + InternalFactHandle fhB4 = (InternalFactHandle) session.insert(b(4)); + assertThat(recorder).containsExactly(b(1, 2, 3, 4)); + InternalFactHandle fhB5 = (InternalFactHandle) session.insert(b(5)); + assertThat(recorder).containsExactly(b(1, 2, 3, 4)); + InternalFactHandle fhB6 = (InternalFactHandle) session.insert(b(6)); + assertThat(recorder).containsExactly(b(1, 2, 3, 4, 5, 6)); + InternalFactHandle fhB7 = (InternalFactHandle) session.insert(b(7)); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + assertThat(recorder).containsExactly(b(1, 2, 3, 4, 5, 6)); + InternalFactHandle fhB8 = (InternalFactHandle) session.insert(b(8)); + assertThat(recorder).containsExactly(b(1, 2, 3, 4, 5, 6)); + + assertThat(events.size()).isEqualTo(3); + assertThat(((FactHandle)events.get(0)).getObject()).isEqualTo(b(0)); + assertThat(events.get(1)).isSameAs(recorder); + assertThat(((FactHandle)events.get(2)).getObject()).isEqualTo(b(7)); + } + + public B b(int i) { + return new B(i, "b"); + } + + public B[] b(int... nums) { + B[] bs = new B[nums.length]; + for (int i = 0; i < nums.length; i++) { + bs[i] = new B(nums[i], "b"); + } + + return bs; + } + + public Object[] to(CircularArrayList events) { + FactHandle[] facts = events.toArray(); + Object[] objs = new Object[facts.length]; + for(int i = 0; i < facts.length; i++) { + objs[i] = ((B)facts[i].getObject()).getObject(); + } + + return objs; + } + +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java new file mode 100644 index 00000000000..b6d6d26d68b --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java @@ -0,0 +1,156 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.SessionConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.core.util.CircularArrayList; +import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; +import org.kie.api.runtime.conf.ThreadSafeOption; +import org.kie.api.runtime.rule.FactHandle; + +import java.util.ArrayList; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerEventsMemoryTest extends AbstractPhreakSequencerSubsequenceTest { + + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); + + DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + + LogicCircuit circuit1 = getLogicCircuit(); + LogicCircuit circuit2 = getLogicCircuit(); + LogicCircuit circuit3 = getLogicCircuit(); + LogicCircuit circuit4 = getLogicCircuit(); + LogicCircuit circuit5 = getLogicCircuit(); + LogicCircuit circuit6 = getLogicCircuit(); + + seq1 = new Sequence(1, Step.of(circuit2)); + seq2 = new Sequence(2, Step.of(circuit4), Step.of(circuit5)); + + seq0 = new Sequence(0, Step.of(circuit1), Step.of(seq1), Step.of(circuit3), Step.of(seq2), Step.of(circuit6)); + mnode.setSequencer(new Sequencer(seq0)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); + + SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.YES); + + createSession(); + } + + private LogicCircuit getLogicCircuit() { + LogicGate gate1 = get1InputLogicGate(); + gate1.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit1 = new LogicCircuit(gate1); + return circuit1; + } + + private static LogicGate get1InputLogicGate() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask), 0, + new int[]{0}, // B + new int[]{0}, // + 0); + return gate1; + } + + @Test + public void testSequenceEventsMemory() { + ArrayList stack = sequencerMemory.getSequenceStack(); + assertThat(stack.size()).isEqualTo(0); + + mnode.getSequencer().start(sequencerMemory, session); + + CircularArrayList events = sequencerMemory.getEvents(); + assertThat(events.size()).isEqualTo(0); + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(to(events)).isEqualTo(new Object[] {0}); + + InternalFactHandle fhB1 = (InternalFactHandle) session.insert(new B(1, "b")); + assertThat(to(events)).isEqualTo(new Object[] {0}); // It's 0, because the subsequence of 1 input finished and it rewound. + + InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); + assertThat(to(events)).isEqualTo(new Object[] {0, 2}); + + InternalFactHandle fhB3 = (InternalFactHandle) session.insert(new B(3, "b")); + assertThat(to(events)).isEqualTo(new Object[] {0, 2, 3}); // This subsequence has two inputs, so its still in the subsequence. + + InternalFactHandle fhB4 = (InternalFactHandle) session.insert(new B(4, "b")); + assertThat(to(events)).isEqualTo(new Object[] {0, 2}); // The subsequence has finished and it's rewound. + + InternalFactHandle fhB5 = (InternalFactHandle) session.insert(new B(5, "b")); + assertThat(to(events)).isEqualTo(new Object[] {0, 2, 5}); // everything has finished and it's added the last input + + InternalFactHandle fhB6 = (InternalFactHandle) session.insert(new B(6, "b")); + assertThat(to(events)).isEqualTo(new Object[] {0, 2, 5}); // nothing is added as the sequence is finished. + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + } + + public Object[] to(CircularArrayList events) { + Object[] facts = events.toArray(); + Object[] objs = new Object[facts.length]; + for(int i = 0; i < facts.length; i++) { + if (facts[i] == null) { + continue; // there are null entries sub sequence steps + } + objs[i] = ((B)((FactHandle)facts[i]).getObject()).getObject(); + } + + return objs; + } + +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java new file mode 100644 index 00000000000..e43c6a48c42 --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java @@ -0,0 +1,210 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGateOutputSignalProcessor; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.signalprocessors.SignalIndex; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.C; +import org.drools.mvel.integrationtests.phreak.D; +import org.drools.mvel.integrationtests.phreak.E; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerLogicGateTest extends AbstractPhreakSequencerSubsequenceTest { + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + final ObjectType cObjectType = new ClassObjectType(C.class); + final ObjectType dObjectType = new ClassObjectType(D.class); + final ObjectType eObjectType = new ClassObjectType(E.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); + + final Pattern cpattern = new Pattern(0, + cObjectType, + "c" ); + cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); + + final Pattern dpattern = new Pattern(0, + dObjectType, + "d" ); + dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); + + final Pattern epattern = new Pattern(0, + eObjectType, + "e" ); + epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); + + bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); + dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); + efilter = new DynamicFilterProto((AlphaNodeFieldConstraint) epattern.getConstraints().get(0), 3); + } + + @Test + public void testAnd() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0, 1}, // B and C + new int[] {0, 1}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + + gate1.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + + createSession(); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + + // reverse B and C + createSession(); + mnode.getSequencer().start(sequencerMemory, session); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + } + + @Test + public void testOr() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.or(inputMask, sourceMask),0, + new int[] {0, 1}, // B and C + new int[] {0, 1}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + + gate1.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + + createSession(); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + + // reverse B and C + createSession(); + mnode.getSequencer().start(sequencerMemory, session); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + } + + + @Test + public void testComposite() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0, 1}, // B and C + new int[] {0, 1}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + + LogicGate gate2 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),1, + new int[] {2}, // D + new int[] {2}, // D + 1); + + gate1.setOutput(new LogicGateOutputSignalProcessor(SignalIndex.of(gate2, 2))); // gate bits must come after signals + gate2.setOutput(TerminatingSignalProcessor.get()); + gate2.setInputGates(gate1); + + LogicCircuit circuit1 = new LogicCircuit(gate1, gate2); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter, dfilter}); + + // D last + createSession(); + mnode.getSequencer().start(sequencerMemory, session); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + + // now it'll transition + InternalFactHandle fhD0 = (InternalFactHandle) session.insert(new D(0, "d")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + + // change order, D first + createSession(); + mnode.getSequencer().start(sequencerMemory, session); + fhD0 = (InternalFactHandle) session.insert(new D(0, "d")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + + // now it'll transition + fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + } + +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java new file mode 100644 index 00000000000..df765d48059 --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java @@ -0,0 +1,139 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.SessionConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.LoopController; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.C; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; +import org.kie.api.runtime.conf.ThreadSafeOption; + +import java.util.ArrayList; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerSequenceLoopTest extends AbstractPhreakSequencerSubsequenceTest { + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class, C.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + final ObjectType cObjectType = new ClassObjectType(C.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); + + final Pattern cpattern = new Pattern(0, + cObjectType, + "c" ); + cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); + + DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + DynamicFilterProto cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); + + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {0}, // + 0); + gate1.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit1 = new LogicCircuit(gate1); + + LogicGate gate2 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),1, + new int[] {1}, // C + new int[] {1}, // + 0); + gate2.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit2 = new LogicCircuit(gate2); + + seq0 = new Sequence(0, Step.of(circuit1), Step.of(circuit2)); + mnode.setSequencer(new Sequencer(seq0)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + + SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.YES); + + createSession(); + } + + @Test + public void testSequenceLoopConstraint() { + seq0.setController(new LoopController(m -> m.getCount() < 2)); + + ArrayList stack = sequencerMemory.getSequenceStack(); + assertThat(stack.size()).isEqualTo(0); + + mnode.getSequencer().start(sequencerMemory, session); + + assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(0); + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(0); + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(1); + + InternalFactHandle fhB1 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(1); + InternalFactHandle fhC1 = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(2); + + InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(2); + InternalFactHandle fhC2 = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(3); + + // Sequence is ended, so this does nothing + InternalFactHandle fhB4 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhC4 = (InternalFactHandle) session.insert(new C(0, "c")); + + assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(3); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + } + +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java new file mode 100644 index 00000000000..4a9f60001de --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java @@ -0,0 +1,136 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.Sequence.TimoutController; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.core.time.impl.DurationTimer; +import org.drools.core.time.impl.PseudoClockScheduler; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.C; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; + +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerSequenceTimerTest extends AbstractPhreakSequencerSubsequenceTest { + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class, C.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + final ObjectType cObjectType = new ClassObjectType(C.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b"); + bpattern.addConstraint(new AlphaConstraint((Predicate1) b -> b.getText().equals("b"))); + + final Pattern cpattern = new Pattern(0, + cObjectType, + "c"); + cpattern.addConstraint(new AlphaConstraint((Predicate1) c -> c.getText().equals("c"))); + + DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + DynamicFilterProto cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); + + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask), 0, + new int[]{0}, // B + new int[]{0}, // + 0); + gate1.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit1 = new LogicCircuit(gate1); + + LogicGate gate2 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask), 1, + new int[]{1}, // C + new int[]{1}, // + 0); + gate2.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit2 = new LogicCircuit(gate2); + + seq0 = new Sequence(0, Step.of(circuit1), Step.of(circuit2)); + mnode.setSequencer(new Sequencer(seq0)); + mnode.setDynamicFilters(new DynamicFilterProto[]{bfilter, cfilter}); + } + + @Test + public void testSequenceTimeout() { + seq0.setController(new TimoutController(new DurationTimer(1000))); + createSession(); + + ArrayList stack = sequencerMemory.getSequenceStack(); + assertThat(stack.size()).isEqualTo(0); + + mnode.getSequencer().start(sequencerMemory, session); + + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); + pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); + + session.fireAllRules(); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + } + + @Test + public void testSequenceComplete() { + seq0.setController(new TimoutController(new DurationTimer(1000))); + createSession(); + + ArrayList stack = sequencerMemory.getSequenceStack(); + assertThat(stack.size()).isEqualTo(0); + + mnode.getSequencer().start(sequencerMemory, session); + + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); + pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); + + session.fireAllRules(); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + } +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java new file mode 100644 index 00000000000..e7910d2fd40 --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java @@ -0,0 +1,316 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGateOutputSignalProcessor; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.signalprocessors.SignalIndex; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.C; +import org.drools.mvel.integrationtests.phreak.D; +import org.drools.mvel.integrationtests.phreak.E; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerSignalProcessorCounterTest extends AbstractPhreakSequencerSubsequenceTest { + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + final ObjectType cObjectType = new ClassObjectType(C.class); + final ObjectType dObjectType = new ClassObjectType(D.class); + final ObjectType eObjectType = new ClassObjectType(E.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); + + final Pattern cpattern = new Pattern(0, + cObjectType, + "c" ); + cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); + + final Pattern dpattern = new Pattern(0, + dObjectType, + "d" ); + dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); + + final Pattern epattern = new Pattern(0, + eObjectType, + "e" ); + epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); + + bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); + dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); + efilter = new DynamicFilterProto((AlphaNodeFieldConstraint) epattern.getConstraints().get(0), 3); + } + + @Test + public void testEventCountEqual() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {0}, + 0); + + gate1.setOutput(TerminatingSignalProcessor.get()); + + ConditionalSignalCounter counter = new ConditionalSignalCounter(0, 0, c -> c == 3); + counter.setOutput(gate1); + gate1.setInputSignalCounters(new ConditionalSignalCounter[] {counter}); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + + createSession(); + + mnode.getSequencer().start(sequencerMemory, session); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + + InternalFactHandle fhB1 = (InternalFactHandle) session.insert(new B(1, "b")); + + InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); + } + + @Test + public void testEventCountLessThan() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0, 1}, // B, C + new int[] {0, 1}, + 0); + + gate1.setOutput(TerminatingSignalProcessor.get()); + + ConditionalSignalCounter counter = new ConditionalSignalCounter(0, 0, c -> c < 3); + counter.setOutput(gate1); + gate1.setInputSignalCounters(new ConditionalSignalCounter[] {counter }); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + + createSession(); // pass + mnode.getSequencer().start(sequencerMemory, session); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + + InternalFactHandle fhB1 = (InternalFactHandle) session.insert(new B(1, "b")); + + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + + InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); + + createSession(); // fail + mnode.getSequencer().start(sequencerMemory, session); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + + fhB1 = (InternalFactHandle) session.insert(new B(1, "b")); + + fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); + } + + + @Test + public void testEventCountBetween() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0, 1}, // B, C + new int[] {0, 1}, + 0); + + gate1.setOutput(TerminatingSignalProcessor.get()); + + ConditionalSignalCounter counter = new ConditionalSignalCounter(0, 0, c -> c > 1 && c < 3); + counter.setOutput(gate1); + gate1.setInputSignalCounters(new ConditionalSignalCounter[] {counter }); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + + createSession(); // pass + mnode.getSequencer().start(sequencerMemory, session); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + + InternalFactHandle fhB1 = (InternalFactHandle) session.insert(new B(1, "b")); + + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + + InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); + + createSession(); // fail + mnode.getSequencer().start(sequencerMemory, session); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + + fhB1 = (InternalFactHandle) session.insert(new B(1, "b")); + + fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); + } + + @Test + public void testSingleOutputCounter() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0, 1}, // B, C + new int[] {0, 1}, + 0); + + ConditionalSignalCounter counter = new ConditionalSignalCounter(0, 0, c -> c == 3); + counter.setOutput(TerminatingSignalProcessor.get()); + gate1.setOutput(counter); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + + createSession(); // pass + mnode.getSequencer().start(sequencerMemory, session); + SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + assertThat(sequenceMemory.getCounterMemories()[counter.getCounterIndex()]).isEqualTo(0); + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhB1 = (InternalFactHandle) session.insert(new B(1, "b")); + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + assertThat(sequenceMemory.getCounterMemories()[counter.getCounterIndex()]).isEqualTo(1); + InternalFactHandle fhC1 = (InternalFactHandle) session.insert(new C(0, "c")); + InternalFactHandle fhC2 = (InternalFactHandle) session.insert(new C(0, "c")); + InternalFactHandle fhB3 = (InternalFactHandle) session.insert(new B(1, "b")); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + assertThat(sequenceMemory.getCounterMemories()[counter.getCounterIndex()]).isEqualTo(2); + InternalFactHandle fhB4 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhB5 = (InternalFactHandle) session.insert(new B(1, "b")); + InternalFactHandle fhC3 = (InternalFactHandle) session.insert(new C(0, "c")); + + // now attempts next step, which is finished + assertThat(sequenceMemory.getCounterMemories()[counter.getCounterIndex()]).isEqualTo(3); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + } + + @Test + public void testCompositeInputAndOutputCounters() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0, 1}, // B and C + new int[] {0, 1}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + + LogicGate gate2 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),1, + new int[] {2}, // D + new int[] {2}, // D + 1); + + ConditionalSignalCounter counter1 = new ConditionalSignalCounter(0, 0, c -> c == 2); + counter1.setOutput(new LogicGateOutputSignalProcessor(SignalIndex.of(gate2, 2))); + gate1.setOutput(counter1); + gate2.setInputGates(gate1); + + ConditionalSignalCounter counter2 = new ConditionalSignalCounter(0, 1, c -> c == 2); + counter2.setOutput(TerminatingSignalProcessor.get()); + gate2.setOutput(counter2); + + LogicCircuit circuit1 = new LogicCircuit(gate1, gate2); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter, dfilter}); + + // D First + createSession(); + mnode.getSequencer().start(sequencerMemory, session); + SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq); + + InternalFactHandle fhD0 = (InternalFactHandle) session.insert(new D(0, "d")); + assertThat(sequenceMemory.getCounterMemories()[counter1.getCounterIndex()]).isEqualTo(0); + + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(sequenceMemory.getCounterMemories()[counter1.getCounterIndex()]).isEqualTo(1); + assertThat(sequenceMemory.getCounterMemories()[counter2.getCounterIndex()]).isEqualTo(0); + + InternalFactHandle fhB1 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhC1 = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(sequenceMemory.getCounterMemories()[counter1.getCounterIndex()]).isEqualTo(0); + assertThat(sequenceMemory.getCounterMemories()[counter2.getCounterIndex()]).isEqualTo(1); + + InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhC2 = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(sequenceMemory.getCounterMemories()[counter1.getCounterIndex()]).isEqualTo(1); + assertThat(sequenceMemory.getCounterMemories()[counter2.getCounterIndex()]).isEqualTo(1); + + InternalFactHandle fhB3 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhC = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(sequenceMemory.getCounterMemories()[counter1.getCounterIndex()]).isEqualTo(2); + assertThat(sequenceMemory.getCounterMemories()[counter2.getCounterIndex()]).isEqualTo(1); + + // Needs a final D to terminate + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhD1 = (InternalFactHandle) session.insert(new D(0, "d")); + assertThat(sequenceMemory.getCounterMemories()[counter1.getCounterIndex()]).isEqualTo(0); + assertThat(sequenceMemory.getCounterMemories()[counter2.getCounterIndex()]).isEqualTo(2); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + } +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java new file mode 100644 index 00000000000..ec1e354020a --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java @@ -0,0 +1,262 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate.DelayFromActivatedTimer; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate.DelayFromMatchTimer; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate.TimeoutTimer; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.core.time.impl.DurationTimer; +import org.drools.core.time.impl.PseudoClockScheduler; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.C; +import org.drools.mvel.integrationtests.phreak.D; +import org.drools.mvel.integrationtests.phreak.E; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; + +import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerSignalProcessorTimerTest extends AbstractPhreakSequencerSubsequenceTest { + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + final ObjectType cObjectType = new ClassObjectType(C.class); + final ObjectType dObjectType = new ClassObjectType(D.class); + final ObjectType eObjectType = new ClassObjectType(E.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); + + final Pattern cpattern = new Pattern(0, + cObjectType, + "c" ); + cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); + + final Pattern dpattern = new Pattern(0, + dObjectType, + "d" ); + dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); + + final Pattern epattern = new Pattern(0, + eObjectType, + "e" ); + epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); + + bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); + dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); + efilter = new DynamicFilterProto((AlphaNodeFieldConstraint) epattern.getConstraints().get(0), 3); + } + + @Test + public void testTimeout() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0, 1}, // B and C + new int[] {0, 1}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + + gate1.setPropagationTimer(new TimeoutTimer(gate1, new DurationTimer(1000))); + + gate1.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + + createSession(); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); + assertThat(pseudo.getQueue().size()).isEqualTo(1); + pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); + session.fireAllRules(); // if the rest of the system is immediate, why isn't this? + assertThat(pseudo.getQueue().size()).isEqualTo(0); + createSession(); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + pseudo = (PseudoClockScheduler) session.getTimerService(); + assertThat(pseudo.getQueue().size()).isEqualTo(1); + + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + pseudo = (PseudoClockScheduler) session.getTimerService(); + assertThat(pseudo.getQueue().peek().isCanceled()).isTrue(); // cancelled timers, stay on the queue until they fire (where they noop) + pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); + session.fireAllRules(); // if the rest of the system is immediate, why isn't this? + } + + @Test + public void testTimeoutWithCountFailure() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {0}, + 0); + + ConditionalSignalCounter counter = new ConditionalSignalCounter(0, 0, c -> c <= 2); + counter.setOutput(gate1); + gate1.setInputSignalCounters(new ConditionalSignalCounter[] {counter}); + + //gate1.setPropagationTimer(new TimeoutTimer(gate1, new DurationTimer(1000))); + gate1.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); + + createSession(); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhB1 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(0, "b")); + PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); +// assertThat(pseudo.getQueue().size()).isEqualTo(1); +// pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); + session.fireAllRules(); // if the rest of the system is immediate, why isn't this? +// assertThat(pseudo.getQueue().size()).isEqualTo(0); +// +// mnode.getSequencer().start(sequencerMemory, session); +// assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 +// fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); +// pseudo = (PseudoClockScheduler) session.getTimerService(); +// assertThat(pseudo.getQueue().size()).isEqualTo(1); +// +// InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); +// pseudo = (PseudoClockScheduler) session.getTimerService(); +// assertThat(pseudo.getQueue().peek().isCanceled()).isTrue(); // cancelled timers, stay on the queue until they fire (where they noop) +// pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); +// session.fireAllRules(); // if the rest of the system is immediate, why isn't this? + } + + + @Test + public void testDelayFromActivation() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0, 1}, // B and C + new int[] {0, 1}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + + gate1.setPropagationTimer(new DelayFromActivatedTimer(gate1, new DurationTimer(1000))); + + gate1.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + + createSession(); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); + assertThat(pseudo.getQueue().size()).isEqualTo(1); + pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); + session.fireAllRules(); // if the rest of the system is immediate, why isn't this? + assertThat(pseudo.getQueue().size()).isEqualTo(0); + + createSession(); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + pseudo = (PseudoClockScheduler) session.getTimerService(); + assertThat(pseudo.getQueue().size()).isEqualTo(1); + pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); + session.fireAllRules(); // if the rest of the system is immediate, why isn't this? + assertThat(pseudo.getQueue().size()).isEqualTo(0); + } + + @Test + public void testDelayFromMatch() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0, 1}, // B and C + new int[] {0, 1}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + + gate1.setPropagationTimer(new DelayFromMatchTimer(gate1, new DurationTimer(1000))); + + gate1.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + Sequence seq = new Sequence(0, Step.of(circuit1)); + mnode.setSequencer(new Sequencer(seq)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + + createSession(); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); + assertThat(pseudo.getQueue().size()).isEqualTo(0); // not created activation, only on match + InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); + assertThat(pseudo.getQueue().size()).isEqualTo(1); + pseudo.advanceTime(500, TimeUnit.MILLISECONDS); + session.fireAllRules(); // if the rest of the system is immediate, why isn't this? + assertThat(pseudo.getQueue().size()).isEqualTo(1); // still 1 + pseudo.advanceTime(1000, TimeUnit.MILLISECONDS); + session.fireAllRules(); + assertThat(pseudo.getQueue().size()).isEqualTo(0); + } + +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java new file mode 100644 index 00000000000..2f5c9383d8b --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java @@ -0,0 +1,192 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.SessionConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.LeftTuple; +import org.drools.core.reteoo.MockLeftTupleSink; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.sequencing.SequencerMemory; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.LoopController; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; +import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; +import org.kie.api.runtime.conf.ThreadSafeOption; + +import java.util.ArrayList; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerSubsequenceLoopTest extends AbstractPhreakSequencerSubsequenceTest { + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); + + DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {0}, // + 0); + gate1.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit1 = new LogicCircuit(gate1); + + LogicGate gate2 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {0}, // + 0); + gate2.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit2 = new LogicCircuit(gate2); + + LogicGate gate3 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {0}, // + 0); + gate3.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit3 = new LogicCircuit(gate3); + + LogicGate gate4 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {1}, // + 0); + gate4.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit4 = new LogicCircuit(gate4); + + seq1 = new Sequence(1, Step.of(circuit1), Step.of(circuit2)); + seq2 = new Sequence(2, Step.of(circuit3), Step.of(circuit4)); + + seq0 = new Sequence(0, Step.of(seq1), Step.of(seq2)); + mnode.setSequencer(new Sequencer(seq0)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); + + SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.NO); + + session = (StatefulKnowledgeSessionImpl) kbase.newKieSession(sessionConf, null); + + InternalFactHandle fhA0 = (InternalFactHandle) session.insert(new A(0)); + nodeMemory = session.getNodeMemory(mnode); + LeftTuple lt = new LeftTuple(fhA0, mnode, true); + lt.setContextObject(mnode.createSequencerMemory(lt, new MockLeftTupleSink(buildContext.getNextNodeId(), buildContext), nodeMemory)); + nodeMemory.getLeftTupleMemory().add(lt); + sequencerMemory = (SequencerMemory) lt.getContextObject(); + } + + @Test + public void testSubSequence() { + seq1.setController(new LoopController(m -> m.getCount() < 2)); + seq2.setController(new LoopController(m -> m.getCount() < 2)); + + ArrayList stack = sequencerMemory.getSequenceStack(); + assertThat(stack.size()).isEqualTo(0); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(stack.size()).isEqualTo(2); + + assertThat(stack.get(0).getSequence()).isSameAs(seq0); + assertThat(stack.get(1).getSequence()).isSameAs(seq1); + assertThat(sequencerMemory.getCurrentSequence().getSequence()).isSameAs(seq1); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB10 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(1); + InternalFactHandle fhB11 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // looped back to first step, but still seq1 + assertThat(sequencerMemory.getSequenceMemory(seq1).getCount()).isEqualTo(1); // first loop + assertThat(stack.get(1).getSequence()).isSameAs(seq1); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB12 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(1); + InternalFactHandle fhB13 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // looped back to first step, but still seq1 + assertThat(sequencerMemory.getSequenceMemory(seq1).getCount()).isEqualTo(2); // second loop + assertThat(stack.get(1).getSequence()).isSameAs(seq1); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB14 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(1); + InternalFactHandle fhB15 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // looped back to first step, but now seq2 + assertThat(sequencerMemory.getSequenceMemory(seq1).getCount()).isEqualTo(3); + + assertThat(stack.get(0).getSequence()).isSameAs(seq0); + assertThat(stack.get(1).getSequence()).isSameAs(seq2); // now on subsequence seq2 + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB20 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(1); + InternalFactHandle fhB21 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // looped back to first step, but still seq1 + assertThat(sequencerMemory.getSequenceMemory(seq2).getCount()).isEqualTo(1); // second loop + assertThat(stack.get(1).getSequence()).isSameAs(seq2); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB22 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(1); + InternalFactHandle fhB23 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // looped back to first step, but still seq1 + assertThat(sequencerMemory.getSequenceMemory(seq2).getCount()).isEqualTo(2); // second loop + assertThat(stack.get(1).getSequence()).isSameAs(seq2); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB24 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(1); + InternalFactHandle fhB25 = (InternalFactHandle) session.insert(new B(0, "b")); // it finishes after this + + // check its all finished + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); + assertThat(stack.isEmpty()).isTrue(); + } + +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java new file mode 100644 index 00000000000..7ca0333a5fc --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java @@ -0,0 +1,145 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.SessionConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; +import org.kie.api.runtime.conf.ThreadSafeOption; + +import java.util.ArrayList; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerSubsequenceTest extends AbstractPhreakSequencerSubsequenceTest { + + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); + + DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + + LogicGate gate1 = get1InputLogicGate(); + gate1.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit1 = new LogicCircuit(gate1); + + LogicGate gate2 = get1InputLogicGate(); + gate2.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit2 = new LogicCircuit(gate2); + + LogicGate gate3 = get1InputLogicGate(); + gate3.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit3 = new LogicCircuit(gate3); + + LogicGate gate4 = get1InputLogicGate(); + gate4.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit4 = new LogicCircuit(gate4); + + seq1 = new Sequence(1, Step.of(circuit1), Step.of(circuit2)); + seq2 = new Sequence(2, Step.of(circuit3), Step.of(circuit4)); + + seq0 = new Sequence(0, Step.of(seq1), Step.of(seq2)); + mnode.setSequencer(new Sequencer(seq0)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); + + SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.YES); + + createSession(); + } + + private static LogicGate get1InputLogicGate() { + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {0}, // + 0); + return gate1; + } + + @Test + public void testSubSequence() { + ArrayList stack = sequencerMemory.getSequenceStack(); + assertThat(stack.size()).isEqualTo(0); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(stack.size()).isEqualTo(2); + + assertThat(stack.get(0).getSequence()).isSameAs(seq0); + assertThat(stack.get(1).getSequence()).isSameAs(seq1); + assertThat(sequencerMemory.getCurrentSequence().getSequence()).isSameAs(seq1); + assertThat(sequencerMemory.getCurrentStep()).isSameAs(0); + + InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentStep()).isSameAs(1); + + // After this B it should transition to the next step, which is a subsequence + InternalFactHandle fhB1 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(stack.get(0).getSequence()).isSameAs(seq0); + assertThat(stack.get(1).getSequence()).isSameAs(seq2); + assertThat(sequencerMemory.getCurrentSequence().getSequence()).isSameAs(seq2); + assertThat(sequencerMemory.getCurrentStep()).isSameAs(0); + + InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(stack.get(0).getSequence()).isSameAs(seq0); + assertThat(stack.get(1).getSequence()).isSameAs(seq2); + assertThat(sequencerMemory.getCurrentSequence().getSequence()).isSameAs(seq2); + assertThat(sequencerMemory.getCurrentStep()).isSameAs(1); + + InternalFactHandle fhB3 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(stack.isEmpty()).isTrue(); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated + } + +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java new file mode 100644 index 00000000000..47673cafb0e --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java @@ -0,0 +1,207 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.base.time.JobHandle; +import org.drools.core.SessionConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.core.reteoo.sequencing.signalprocessors.Gates; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.core.reteoo.sequencing.Sequence; +import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.core.reteoo.sequencing.Sequence.TimoutController; +import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.core.reteoo.sequencing.steps.Step; +import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.core.time.impl.DurationTimer; +import org.drools.core.time.impl.PseudoClockScheduler; +import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; +import org.kie.api.runtime.conf.ThreadSafeOption; + +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PhreakSequencerSubsequenceTimerTest extends AbstractPhreakSequencerSubsequenceTest { + + @Before + public void setup() { + buildContext = createContext(); + buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + + MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); + + mnode = builder.buildNode(A.class, new Class[]{B.class}); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); + + DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {0}, // + 0); + gate1.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit1 = new LogicCircuit(gate1); + + LogicGate gate2 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {0}, // + 0); + gate2.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit2 = new LogicCircuit(gate2); + + LogicGate gate3 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {0}, // + 0); + gate3.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit3 = new LogicCircuit(gate3); + + LogicGate gate4 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, + new int[] {0}, // B + new int[] {1}, // + 0); + gate4.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit4 = new LogicCircuit(gate4); + + seq1 = new Sequence(1, Step.of(circuit1), Step.of(circuit2)); + seq2 = new Sequence(2, Step.of(circuit3), Step.of(circuit4)); + + seq0 = new Sequence(0, Step.of(seq1), Step.of(seq2)); + mnode.setSequencer(new Sequencer(seq0)); + mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); + + SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.NO); + } + + @Test + public void testSubSequenceFailSeq1() { + seq1.setController(new TimoutController(new DurationTimer(1000))); + createSession(); + + ArrayList stack = sequencerMemory.getSequenceStack(); + assertThat(stack.size()).isEqualTo(0); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(stack.size()).isEqualTo(2); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB10 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentSequence().getSequence()).isEqualTo(seq1); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(1); + PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); + pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); + session.fireAllRules(); + + // check it's all finished + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); + assertThat(stack.isEmpty()).isTrue(); + } + + @Test + public void testSubSequenceFailSeq2() { + seq1.setController(new TimoutController(new DurationTimer(1000))); + seq2.setController(new TimoutController(new DurationTimer(1000))); + createSession(); + + ArrayList stack = sequencerMemory.getSequenceStack(); + assertThat(stack.size()).isEqualTo(0); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(stack.size()).isEqualTo(2); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB10 = (InternalFactHandle) session.insert(new B(0, "b")); + SequenceMemory seq1Memory = sequencerMemory.getSequenceMemory(seq1); + JobHandle jh1 = seq1Memory.getJobHandle(); + assertThat(jh1).isNotNull(); + assertThat(jh1.isCancel()).isFalse(); + InternalFactHandle fhB20 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhB30 = (InternalFactHandle) session.insert(new B(0, "b")); + assertThat(sequencerMemory.getCurrentSequence().getSequence()).isEqualTo(seq2); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(1); + assertThat(seq1Memory.getJobHandle()).isNull(); + assertThat(jh1.isCancel()).isTrue(); + + PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); + pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); + session.fireAllRules(); + + // check its all finished + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); + assertThat(stack.isEmpty()).isTrue(); + } + + @Test + public void testSubSequenceComplete() { + seq1.setController(new TimoutController(new DurationTimer(1000))); + seq2.setController(new TimoutController(new DurationTimer(1000))); + createSession(); + + ArrayList stack = sequencerMemory.getSequenceStack(); + assertThat(stack.size()).isEqualTo(0); + + mnode.getSequencer().start(sequencerMemory, session); + assertThat(stack.size()).isEqualTo(2); + + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); + InternalFactHandle fhB10 = (InternalFactHandle) session.insert(new B(0, "b")); + SequenceMemory seq1Memory = sequencerMemory.getSequenceMemory(seq1); + JobHandle jh1 = seq1Memory.getJobHandle(); + InternalFactHandle fhB20 = (InternalFactHandle) session.insert(new B(0, "b")); + InternalFactHandle fhB30 = (InternalFactHandle) session.insert(new B(0, "b")); + SequenceMemory seq2Memory = sequencerMemory.getSequenceMemory(seq2); + JobHandle jh2 = seq2Memory.getJobHandle(); + InternalFactHandle fhB40 = (InternalFactHandle) session.insert(new B(0, "b")); + + assertThat(seq1Memory.getJobHandle()).isNull(); + assertThat(jh1.isCancel()).isTrue(); + + assertThat(seq2Memory.getJobHandle()).isNull(); + assertThat(jh2.isCancel()).isTrue(); + + // check its all finished + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); + assertThat(stack.isEmpty()).isTrue(); + } + +} diff --git a/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/BeliefSystemLogicalCallback.java b/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/BeliefSystemLogicalCallback.java index 1d70edd40a5..c85866688b2 100644 --- a/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/BeliefSystemLogicalCallback.java +++ b/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/BeliefSystemLogicalCallback.java @@ -18,14 +18,13 @@ */ package org.drools.tms.beliefsystem.simple; -import org.drools.core.common.BaseNode; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; import org.drools.core.common.SuperCacheFixer; import org.drools.core.common.WorkingMemoryAction; import org.drools.core.marshalling.MarshallerReaderContext; -import org.drools.core.phreak.PropagationEntry; +import org.drools.core.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.ObjectTypeConf; import org.drools.core.rule.consequence.InternalMatch; import org.drools.kiesession.entrypoints.NamedEntryPoint; @@ -36,7 +35,7 @@ import static org.drools.base.reteoo.PropertySpecificUtil.allSetButTraitBitMask; -public class BeliefSystemLogicalCallback extends PropagationEntry.AbstractPropagationEntry implements WorkingMemoryAction { +public class BeliefSystemLogicalCallback extends AbstractPropagationEntry implements WorkingMemoryAction { protected InternalFactHandle handle; protected PropagationContext context; diff --git a/kie-api/src/main/java/org/kie/api/runtime/rule/PropagationContext.java b/kie-api/src/main/java/org/kie/api/runtime/rule/PropagationContext.java deleted file mode 100644 index 0b50df364e9..00000000000 --- a/kie-api/src/main/java/org/kie/api/runtime/rule/PropagationContext.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.kie.api.runtime.rule; - -import org.kie.api.definition.rule.Rule; - -public interface PropagationContext { - public static final int INSERTION = 0; - public static final int DELETION = 1; - public static final int MODIFICATION = 2; - public static final int RULE_ADDITION = 3; - public static final int RULE_REMOVAL = 4; - public static final int EXPIRATION = 5; - - public static final String[] typeDescr = new String[] { - "INSERTION", - "DELETION", - "MODIFICATION", - "RULE_ADDITION", - "RULE_REMOVAL", - "EXPIRATION" - }; - - long getPropagationNumber(); - - /** - * The rule that caused the working memory action that created this PropagationContext. - * - * If this working memory action was done from java this is null. - * - * @return rule that caused the working memory action - */ - Rule getRule(); - - /** - * @return fact handle that was inserted, updated or retracted that created the PropagationContext - */ - FactHandle getFactHandle(); - - /** - * The PropagationContextType, numbers may change between Drools versions. Or we may eventually switch this to an enum. - * INSERTION = 0; - * DELETION = 1; - * MODIFICATION = 2; - * RULE_ADDITION = 3; - * RULE_REMOVAL = 4; - * EXPIRATION = 5; - * - * @return type of the propagation context - */ - int getType(); -} From 539d93a9d19e92f1e028cc8ba64cac3547740c53 Mon Sep 17 00:00:00 2001 From: Mark Proctor Date: Thu, 15 Aug 2024 00:49:23 +0100 Subject: [PATCH 3/5] refactored some packaging --- .../ancompiler/AbstractCompilerHandler.java | 2 +- .../org/drools/ancompiler/AssertHandler.java | 2 +- .../ancompiler/DeclarationsHandler.java | 2 +- .../InlineFieldReferenceInitHandler.java | 2 +- .../org/drools/ancompiler/ModifyHandler.java | 2 +- .../ancompiler/PropagatorCompilerHandler.java | 2 +- .../ancompiler/SetNodeReferenceHandler.java | 2 +- .../org/drools/base/base/ValueResolver.java | 4 +- .../base/definitions/rule/impl/RuleImpl.java | 6 + .../phreak/PropagationEntry.java | 2 +- .../actions/AbstractPropagationEntry.java | 4 +- .../{core => base}/reteoo/DynamicFilter.java | 6 +- .../reteoo/DynamicFilterProto.java | 2 +- .../reteoo/ObjectTypeNodeId.java | 2 +- .../{core => base}/reteoo/SignalAdapter.java | 10 +- .../drools/{core => base}/reteoo/Sink.java | 2 +- .../reteoo/sequencing/DynamicFilters.java | 4 +- .../reteoo/sequencing/Sequence.java | 32 ++- .../reteoo/sequencing/Sequencer.java | 11 +- .../reteoo/sequencing/SequencerMemory.java | 10 +- .../ConditionalSignalCounter.java | 4 +- .../sequencing/signalprocessors/Gates.java | 2 +- .../signalprocessors/LogicCircuit.java | 2 +- .../signalprocessors/LogicGate.java | 8 +- .../LogicGateOutputSignalProcessor.java | 4 +- .../signalprocessors/SignalIndex.java | 2 +- .../signalprocessors/SignalProcessor.java | 4 +- .../signalprocessors/SignalStatus.java | 2 +- .../TerminatingSignalProcessor.java | 4 +- .../reteoo/sequencing/steps/AbstractStep.java | 8 +- .../reteoo/sequencing/steps/ActionStep.java | 6 +- .../sequencing/steps/AggregatorStep.java | 6 +- .../sequencing/steps/LogicCircuitStep.java | 10 +- .../reteoo/sequencing/steps/SequenceStep.java | 8 +- .../reteoo/sequencing/steps/Step.java | 8 +- .../{core => base}/time/SchedulerService.java | 2 +- .../{core => base}/time/TimerService.java | 6 +- .../time/impl/InternalSchedulerService.java | 2 +- .../time/impl/TimerJobFactoryManager.java | 2 +- .../time/impl/TimerJobInstance.java | 2 +- .../util/AbstractLinkedListNode.java | 2 +- .../util/CircularArrayList.java | 2 +- .../util/DoubleLinkedEntry.java | 2 +- .../{core => base}/util/FastIterator.java | 2 +- .../drools/{core => base}/util/Iterator.java | 2 +- .../{core => base}/util/LinkedList.java | 2 +- .../{core => base}/util/LinkedListEntry.java | 2 +- .../util/SingleLinkedEntry.java | 2 +- .../beliefs/bayes/BayesHardEvidence.java | 2 +- .../beliefs/bayes/NonConflictingModeSet.java | 2 +- .../main/java/org/drools/core/ClockType.java | 2 +- .../org/drools/core/SessionConfiguration.java | 4 +- .../org/drools/core/TimerJobFactoryType.java | 2 +- .../core/common/ActivationGroupImpl.java | 2 +- .../core/common/ActivationGroupNode.java | 2 +- .../drools/core/common/ActivationNode.java | 2 +- .../core/common/ActivationsManager.java | 2 +- .../core/common/AgendaGroupQueueImpl.java | 2 +- .../java/org/drools/core/common/BaseNode.java | 2 +- .../core/common/DefaultEventHandle.java | 4 +- .../drools/core/common/DefaultFactHandle.java | 4 +- .../org/drools/core/common/EqualityKey.java | 2 +- .../core/common/InternalActivationGroup.java | 2 +- .../drools/core/common/InternalAgenda.java | 2 +- .../core/common/InternalFactHandle.java | 2 +- .../core/common/InternalKnowledgeRuntime.java | 2 +- .../core/common/InternalWorkingMemory.java | 2 +- .../java/org/drools/core/common/Memory.java | 2 +- .../org/drools/core/common/ReteEvaluator.java | 7 +- .../drools/core/common/SuperCacheFixer.java | 9 +- .../core/common/WorkingMemoryAction.java | 2 +- .../core/impl/ActivationsManagerImpl.java | 5 +- .../impl/WorkingMemoryReteExpireAction.java | 4 +- .../core/phreak/EagerPhreakBuilder.java | 3 +- .../drools/core/phreak/LazyPhreakBuilder.java | 2 +- .../core/phreak/PhreakAccumulateNode.java | 2 +- .../drools/core/phreak/PhreakExistsNode.java | 2 +- .../drools/core/phreak/PhreakFromNode.java | 4 +- .../drools/core/phreak/PhreakJoinNode.java | 2 +- .../org/drools/core/phreak/PhreakNotNode.java | 2 +- .../core/phreak/PhreakQueryTerminalNode.java | 3 +- .../drools/core/phreak/PhreakTimerNode.java | 6 +- .../drools/core/phreak/PropagationList.java | 2 + .../core/phreak/ReactiveObjectUtil.java | 2 +- .../drools/core/phreak/RuleAgendaItem.java | 4 +- .../org/drools/core/phreak/RuleExecutor.java | 2 +- .../core/phreak/RuleNetworkEvaluator.java | 4 +- .../org/drools/core/phreak/StackEntry.java | 2 +- .../SynchronizedBypassPropagationList.java | 1 + .../phreak/SynchronizedPropagationList.java | 1 + .../phreak/ThreadUnsafePropagationList.java | 3 +- .../core/phreak/TupleEvaluationUtil.java | 2 +- .../AbstractPartitionedPropagationEntry.java | 1 + .../drools/core/phreak/actions/Delete.java | 3 +- .../drools/core/phreak/actions/Insert.java | 3 +- .../actions/PropagationEntryWithResult.java | 1 + .../drools/core/phreak/actions/Update.java | 3 +- .../drools/core/reteoo/AccumulateNode.java | 2 +- .../core/reteoo/AgendaComponentFactory.java | 1 + .../drools/core/reteoo/AlphaTerminalNode.java | 1 + .../drools/core/reteoo/AsyncReceiveNode.java | 4 +- .../org/drools/core/reteoo/AsyncSendNode.java | 2 +- .../org/drools/core/reteoo/BetaMemory.java | 2 +- .../java/org/drools/core/reteoo/BetaNode.java | 7 +- ...positePartitionAwareObjectSinkAdapter.java | 2 +- .../core/reteoo/ConditionalBranchNode.java | 4 +- .../drools/core/reteoo/EntryPointNode.java | 1 + .../drools/core/reteoo/EvalConditionNode.java | 2 +- .../drools/core/reteoo/EvalNodeLeftTuple.java | 1 + .../java/org/drools/core/reteoo/FromNode.java | 2 +- .../core/reteoo/LeftInputAdapterNode.java | 3 +- .../org/drools/core/reteoo/LeftTuple.java | 4 +- .../org/drools/core/reteoo/LeftTupleSink.java | 2 + .../drools/core/reteoo/LeftTupleSource.java | 1 + .../drools/core/reteoo/NotNodeLeftTuple.java | 3 +- .../org/drools/core/reteoo/ObjectRouter.java | 214 ------------------ .../org/drools/core/reteoo/ObjectSink.java | 1 + .../drools/core/reteoo/ObjectTypeNode.java | 1 + .../org/drools/core/reteoo/PathMemory.java | 2 +- .../drools/core/reteoo/QueryElementNode.java | 2 +- .../drools/core/reteoo/QueryTerminalNode.java | 1 + .../reteoo/ReactiveFromNodeLeftTuple.java | 1 + .../core/reteoo/RightInputAdapterNode.java | 5 +- .../org/drools/core/reteoo/RightTuple.java | 2 + .../drools/core/reteoo/RightTupleSink.java | 2 + .../drools/core/reteoo/RuleTerminalNode.java | 1 + .../reteoo/RuleTerminalNodeLeftTuple.java | 1 + .../core/reteoo/RuntimeComponentFactory.java | 2 +- .../org/drools/core/reteoo/SegmentMemory.java | 4 +- .../org/drools/core/reteoo/SequenceNode.java | 19 +- .../drools/core/reteoo/SubnetworkTuple.java | 1 + .../org/drools/core/reteoo/TerminalNode.java | 3 +- .../org/drools/core/reteoo/TimerNode.java | 2 +- .../java/org/drools/core/reteoo/Tuple.java | 5 +- .../org/drools/core/reteoo/TupleFactory.java | 1 + .../org/drools/core/reteoo/TupleImpl.java | 2 + .../org/drools/core/reteoo/TupleMemory.java | 2 +- .../drools/core/reteoo/TupleToObjectNode.java | 1 + .../org/drools/core/reteoo/WindowNode.java | 1 + .../core/reteoo/builder/NodeFactory.java | 7 + .../reteoo/builder/PhreakNodeFactory.java | 61 +++++ .../reteoo/builder/ReteooRuleBuilder.java | 3 + .../core/reteoo/builder/SequenceBuilder.java | 56 +++++ .../sequencing/SequencerMemoryImpl.java | 19 +- .../drools/core/rule/SlidingTimeWindow.java | 4 +- .../time/EnqueuedSelfRemovalJobContext.java | 4 +- .../core/time/SelfRemovalJobContext.java | 2 +- .../core/time/impl/AbstractJobHandle.java | 4 +- .../CommandServiceTimerJobFactoryManager.java | 1 + .../core/time/impl/DefaultJobHandle.java | 3 +- .../impl/DefaultTimerJobFactoryManager.java | 3 + .../time/impl/DefaultTimerJobInstance.java | 4 +- .../core/time/impl/JDKTimerService.java | 15 +- .../core/time/impl/PseudoClockScheduler.java | 5 +- .../impl/TrackableTimeJobFactoryManager.java | 3 + .../drools/core/util/AbstractHashTable.java | 2 +- .../drools/core/util/HashTableIterator.java | 3 + .../org/drools/core/util/TupleRBTree.java | 2 +- .../core/util/index/TupleIndexHashTable.java | 6 +- .../core/util/index/TupleIndexRBTree.java | 4 +- .../org/drools/core/util/index/TupleList.java | 6 +- .../core/util/index/TupleListWithContext.java | 7 - .../core/time/impl/JDKTimerServiceTest.java | 4 +- .../drools/core/util/LeftTupleRBTreeTest.java | 5 +- .../org/drools/core/util/LinkedListTest.java | 3 + .../fastutil/FastUtilHashTupleMemory.java | 6 +- .../drools/fastutil/FastUtilTreeMemory.java | 4 +- .../fastutil/FastUtilTreeMemoryTest.java | 3 +- .../agenda/CompositeDefaultAgenda.java | 2 +- .../kiesession/agenda/DefaultAgenda.java | 8 +- .../StatefulKnowledgeSessionForRHS.java | 4 +- .../debug/AccumulateNodeVisitor.java | 2 +- .../kiesession/debug/FromNodeVisitor.java | 3 +- .../factory/RuntimeComponentFactoryImpl.java | 2 +- .../session/StatefulKnowledgeSessionImpl.java | 6 +- .../drools/kiesession/MockInternalMatch.java | 3 +- .../kiesession/ReteooWorkingMemoryTest.java | 2 +- .../phreak/PhreakQueryTerminalNodeMetric.java | 3 +- .../model/codegen/execmodel/ReteDumper.java | 2 +- .../drools/persistence/PersistableRunner.java | 2 +- .../persistence/jpa/JpaJDKTimerService.java | 4 +- .../jpa/JpaTimeJobFactoryManager.java | 4 +- .../persistence/jpa/JpaTimerJobInstance.java | 4 +- .../core/ReliablePropagationList.java | 2 +- .../core/ReliablePseudoClockScheduler.java | 2 +- .../ReliableRuntimeComponentFactoryImpl.java | 2 +- .../core/ReliableSessionInitializer.java | 2 +- .../org/drools/retediagram/ReteDiagram.java | 2 +- .../impl/sessions/RuleUnitExecutorImpl.java | 4 +- .../protobuf/ProtobufOutputMarshaller.java | 20 +- .../WorkingMemoryReteAssertAction.java | 2 +- .../iterators/ActivationIterator.java | 3 +- .../protobuf/iterators/LeftTupleIterator.java | 5 +- .../iterators/PhreakActivationIterator.java | 6 +- .../iterators/TerminalNodeIterator.java | 2 +- .../protobuf/marshalling/RightTupleKey.java | 2 +- .../ExpireJobContextTimerInputMarshaller.java | 2 +- .../integrationtests/IndexingTest.java | 2 +- .../integrationtests/operators/NotTest.java | 2 +- ...stractTupleIndexHashTableIteratorTest.java | 2 +- .../drools/mvel/BaseBetaConstraintsTest.java | 4 +- .../LeftTupleIndexHashTableIteratorTest.java | 2 +- .../RightTupleIndexHashTableIteratorTest.java | 2 +- .../compiler/command/PropagationListTest.java | 2 +- .../common/InternalMatchIteratorTest.java | 2 +- .../common/TerminalNodeIteratorTest.java | 3 +- .../compiler/oopath/OOPathReactiveTest.java | 4 +- .../compiler/reteoo/MockLeftTupleSink.java | 6 - .../mvel/integrationtests/Misc2Test.java | 6 +- .../integrationtests/phreak/Scenario.java | 2 +- ...bstractPhreakSequencerSubsequenceTest.java | 6 +- .../sequencing/CircularArrayListTest.java | 2 +- .../sequencing/MultiInputNodeBuilder.java | 1 - .../sequencing/PhreakSequencerActionTest.java | 20 +- ...akSequencerActivateDeactivateStepTest.java | 24 +- .../PhreakSequencerAggregatorTest.java | 22 +- .../PhreakSequencerEventsMemoryTest.java | 20 +- .../PhreakSequencerLogicGateTest.java | 20 +- .../PhreakSequencerSequenceLoopTest.java | 20 +- .../PhreakSequencerSequenceTimerTest.java | 20 +- ...akSequencerSignalProcessorCounterTest.java | 24 +- ...reakSequencerSignalProcessorTimerTest.java | 24 +- .../PhreakSequencerSubsequenceLoopTest.java | 22 +- .../PhreakSequencerSubsequenceTest.java | 18 +- .../PhreakSequencerSubsequenceTimerTest.java | 20 +- .../phreak/sequencing/SequenceInRuleTest.java | 126 +++++++++++ .../util/RightTupleIndexHashTableTest.java | 2 +- .../org/drools/tms/LogicalDependency.java | 2 +- .../main/java/org/drools/tms/SimpleMode.java | 2 +- ...intenanceSystemAgendaComponentFactory.java | 2 +- .../tms/TruthMaintenanceSystemImpl.java | 2 +- ...TruthMaintenanceSystemKnowledgeHelper.java | 4 +- .../TruthMaintenanceSystemInternalMatch.java | 2 +- ...enanceSystemRuleTerminalNodeLeftTuple.java | 4 +- .../drools/tms/beliefsystem/BeliefSet.java | 2 +- .../tms/beliefsystem/ModedAssertion.java | 2 +- .../defeasible/DefeasibleBeliefSet.java | 4 +- .../beliefsystem/jtms/JTMSBeliefSetImpl.java | 2 +- .../tms/beliefsystem/jtms/JTMSMode.java | 2 +- .../simple/BeliefSystemLogicalCallback.java | 2 +- .../beliefsystem/simple/SimpleBeliefSet.java | 4 +- .../simple/SimpleLogicalDependency.java | 2 +- .../org/drools/tms/TMSMockInternalMatch.java | 2 +- .../drools/traits/core/factmodel/Triple.java | 2 +- .../traits/core/factmodel/TripleImpl.java | 2 +- .../traits/core/factmodel/TripleStore.java | 2 +- 246 files changed, 796 insertions(+), 706 deletions(-) rename drools-base/src/main/java/org/drools/{core => base}/phreak/PropagationEntry.java (97%) rename drools-base/src/main/java/org/drools/{core => base}/phreak/actions/AbstractPropagationEntry.java (90%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/DynamicFilter.java (92%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/DynamicFilterProto.java (94%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/ObjectTypeNodeId.java (98%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/SignalAdapter.java (73%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/Sink.java (96%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/DynamicFilters.java (62%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/Sequence.java (96%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/Sequencer.java (85%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/SequencerMemory.java (73%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/signalprocessors/ConditionalSignalCounter.java (96%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/signalprocessors/Gates.java (89%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/signalprocessors/LogicCircuit.java (83%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/signalprocessors/LogicGate.java (98%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/signalprocessors/LogicGateOutputSignalProcessor.java (94%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/signalprocessors/SignalIndex.java (88%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/signalprocessors/SignalProcessor.java (77%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/signalprocessors/SignalStatus.java (83%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/signalprocessors/TerminatingSignalProcessor.java (86%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/steps/AbstractStep.java (86%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/steps/ActionStep.java (81%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/steps/AggregatorStep.java (66%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/steps/LogicCircuitStep.java (74%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/steps/SequenceStep.java (88%) rename drools-base/src/main/java/org/drools/{core => base}/reteoo/sequencing/steps/Step.java (93%) rename drools-base/src/main/java/org/drools/{core => base}/time/SchedulerService.java (97%) rename drools-base/src/main/java/org/drools/{core => base}/time/TimerService.java (93%) rename drools-base/src/main/java/org/drools/{core => base}/time/impl/InternalSchedulerService.java (96%) rename drools-base/src/main/java/org/drools/{core => base}/time/impl/TimerJobFactoryManager.java (97%) rename drools-base/src/main/java/org/drools/{core => base}/time/impl/TimerJobInstance.java (97%) rename drools-base/src/main/java/org/drools/{core => base}/util/AbstractLinkedListNode.java (98%) rename drools-base/src/main/java/org/drools/{core => base}/util/CircularArrayList.java (98%) rename drools-base/src/main/java/org/drools/{core => base}/util/DoubleLinkedEntry.java (97%) rename drools-base/src/main/java/org/drools/{core => base}/util/FastIterator.java (98%) rename drools-base/src/main/java/org/drools/{core => base}/util/Iterator.java (96%) rename drools-base/src/main/java/org/drools/{core => base}/util/LinkedList.java (99%) rename drools-base/src/main/java/org/drools/{core => base}/util/LinkedListEntry.java (98%) rename drools-base/src/main/java/org/drools/{core => base}/util/SingleLinkedEntry.java (96%) delete mode 100644 drools-core/src/main/java/org/drools/core/reteoo/ObjectRouter.java create mode 100755 drools-core/src/main/java/org/drools/core/reteoo/builder/SequenceBuilder.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java diff --git a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AbstractCompilerHandler.java b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AbstractCompilerHandler.java index 27bd0912931..4b07f07e740 100644 --- a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AbstractCompilerHandler.java +++ b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AbstractCompilerHandler.java @@ -22,7 +22,7 @@ import org.drools.base.common.NetworkNode; import org.drools.core.reteoo.AlphaNode; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import org.drools.base.rule.ContextEntry; import org.drools.core.util.index.AlphaRangeIndex; diff --git a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AssertHandler.java b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AssertHandler.java index b7a112ac586..b1b162d5e0a 100644 --- a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AssertHandler.java +++ b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/AssertHandler.java @@ -24,7 +24,7 @@ import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.stmt.Statement; import org.drools.base.reteoo.NodeTypeEnums; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import static com.github.javaparser.StaticJavaParser.parseStatement; import static com.github.javaparser.ast.NodeList.nodeList; diff --git a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/DeclarationsHandler.java b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/DeclarationsHandler.java index 395bb1abd09..2f52b184a72 100644 --- a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/DeclarationsHandler.java +++ b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/DeclarationsHandler.java @@ -29,7 +29,7 @@ import org.drools.core.reteoo.AlphaNode; import org.drools.core.reteoo.BetaNode; import org.drools.core.reteoo.LeftInputAdapterNode; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import org.drools.core.reteoo.WindowNode; import org.drools.base.rule.ContextEntry; import org.drools.base.rule.IndexableConstraint; diff --git a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/InlineFieldReferenceInitHandler.java b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/InlineFieldReferenceInitHandler.java index 2db3a780410..c93cefe6e2f 100644 --- a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/InlineFieldReferenceInitHandler.java +++ b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/InlineFieldReferenceInitHandler.java @@ -43,7 +43,7 @@ import com.github.javaparser.ast.type.VoidType; import org.drools.base.common.NetworkNode; import org.drools.core.reteoo.AlphaNode; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import static com.github.javaparser.StaticJavaParser.parseStatement; import static com.github.javaparser.ast.NodeList.nodeList; diff --git a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ModifyHandler.java b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ModifyHandler.java index b4518fb0924..49ea075e85a 100644 --- a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ModifyHandler.java +++ b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/ModifyHandler.java @@ -24,7 +24,7 @@ import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.stmt.Statement; import org.drools.base.reteoo.NodeTypeEnums; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import static com.github.javaparser.StaticJavaParser.parseStatement; import static com.github.javaparser.ast.NodeList.nodeList; diff --git a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/PropagatorCompilerHandler.java b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/PropagatorCompilerHandler.java index cb8220aa404..6a19ba333d7 100644 --- a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/PropagatorCompilerHandler.java +++ b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/PropagatorCompilerHandler.java @@ -61,7 +61,7 @@ import org.drools.core.reteoo.LeftInputAdapterNode; import org.drools.core.reteoo.ModifyPreviousTuples; import org.drools.core.reteoo.ObjectTypeNode; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import org.drools.core.reteoo.WindowNode; import org.drools.base.rule.IndexableConstraint; import org.drools.core.common.PropagationContext; diff --git a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/SetNodeReferenceHandler.java b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/SetNodeReferenceHandler.java index cd801e1d237..a550cad1c93 100644 --- a/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/SetNodeReferenceHandler.java +++ b/drools-alphanetwork-compiler/src/main/java/org/drools/ancompiler/SetNodeReferenceHandler.java @@ -39,7 +39,7 @@ import com.github.javaparser.ast.type.VoidType; import org.drools.base.common.NetworkNode; import org.drools.core.reteoo.AlphaNode; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import static com.github.javaparser.StaticJavaParser.parseExpression; import static com.github.javaparser.StaticJavaParser.parseStatement; diff --git a/drools-base/src/main/java/org/drools/base/base/ValueResolver.java b/drools-base/src/main/java/org/drools/base/base/ValueResolver.java index f2aa60acae6..a3bfe4b183d 100644 --- a/drools-base/src/main/java/org/drools/base/base/ValueResolver.java +++ b/drools-base/src/main/java/org/drools/base/base/ValueResolver.java @@ -20,8 +20,8 @@ import org.drools.base.RuleBase; import org.drools.base.rule.accessor.GlobalResolver; -import org.drools.core.phreak.PropagationEntry; -import org.drools.core.time.TimerService; +import org.drools.base.phreak.PropagationEntry; +import org.drools.base.time.TimerService; import org.kie.api.runtime.KieSessionConfiguration; import java.util.function.Consumer; diff --git a/drools-base/src/main/java/org/drools/base/definitions/rule/impl/RuleImpl.java b/drools-base/src/main/java/org/drools/base/definitions/rule/impl/RuleImpl.java index e9f7f02535d..2c85170ed33 100644 --- a/drools-base/src/main/java/org/drools/base/definitions/rule/impl/RuleImpl.java +++ b/drools-base/src/main/java/org/drools/base/definitions/rule/impl/RuleImpl.java @@ -37,6 +37,7 @@ import org.drools.base.base.SalienceInteger; import org.drools.base.base.ValueResolver; import org.drools.base.reteoo.BaseTuple; +import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.rule.ConsequenceMetaData; import org.drools.base.rule.Declaration; import org.drools.base.rule.Dialectable; @@ -545,6 +546,11 @@ public void addPattern(final RuleConditionElement element) { this.lhsRoot.addChild( element ); } + public void addSequence(final Sequence element) { + this.dirty = true; + this.lhsRoot.addChild( element ); + } + /** * Retrieve the List of Conditions for this * rule. diff --git a/drools-base/src/main/java/org/drools/core/phreak/PropagationEntry.java b/drools-base/src/main/java/org/drools/base/phreak/PropagationEntry.java similarity index 97% rename from drools-base/src/main/java/org/drools/core/phreak/PropagationEntry.java rename to drools-base/src/main/java/org/drools/base/phreak/PropagationEntry.java index 97aafe8aa34..42b5b14b3e8 100644 --- a/drools-base/src/main/java/org/drools/core/phreak/PropagationEntry.java +++ b/drools-base/src/main/java/org/drools/base/phreak/PropagationEntry.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.phreak; +package org.drools.base.phreak; import org.drools.base.base.ValueResolver; diff --git a/drools-base/src/main/java/org/drools/core/phreak/actions/AbstractPropagationEntry.java b/drools-base/src/main/java/org/drools/base/phreak/actions/AbstractPropagationEntry.java similarity index 90% rename from drools-base/src/main/java/org/drools/core/phreak/actions/AbstractPropagationEntry.java rename to drools-base/src/main/java/org/drools/base/phreak/actions/AbstractPropagationEntry.java index d9867249b87..ae2e1eaa3bd 100644 --- a/drools-base/src/main/java/org/drools/core/phreak/actions/AbstractPropagationEntry.java +++ b/drools-base/src/main/java/org/drools/base/phreak/actions/AbstractPropagationEntry.java @@ -1,7 +1,7 @@ -package org.drools.core.phreak.actions; +package org.drools.base.phreak.actions; import org.drools.base.base.ValueResolver; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; public abstract class AbstractPropagationEntry implements PropagationEntry { protected PropagationEntry next; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/DynamicFilter.java b/drools-base/src/main/java/org/drools/base/reteoo/DynamicFilter.java similarity index 92% rename from drools-base/src/main/java/org/drools/core/reteoo/DynamicFilter.java rename to drools-base/src/main/java/org/drools/base/reteoo/DynamicFilter.java index 6863ba9956b..d1fc387dff1 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/DynamicFilter.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/DynamicFilter.java @@ -1,9 +1,9 @@ -package org.drools.core.reteoo; +package org.drools.base.reteoo; import org.drools.base.base.ValueResolver; import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.util.AbstractLinkedListNode; -import org.drools.core.util.LinkedList; +import org.drools.base.util.AbstractLinkedListNode; +import org.drools.base.util.LinkedList; import org.kie.api.runtime.rule.FactHandle; public class DynamicFilter extends AbstractLinkedListNode { diff --git a/drools-base/src/main/java/org/drools/core/reteoo/DynamicFilterProto.java b/drools-base/src/main/java/org/drools/base/reteoo/DynamicFilterProto.java similarity index 94% rename from drools-base/src/main/java/org/drools/core/reteoo/DynamicFilterProto.java rename to drools-base/src/main/java/org/drools/base/reteoo/DynamicFilterProto.java index 68f8a86a86b..b3a13a3e78d 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/DynamicFilterProto.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/DynamicFilterProto.java @@ -1,4 +1,4 @@ -package org.drools.core.reteoo; +package org.drools.base.reteoo; import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/ObjectTypeNodeId.java b/drools-base/src/main/java/org/drools/base/reteoo/ObjectTypeNodeId.java similarity index 98% rename from drools-base/src/main/java/org/drools/core/reteoo/ObjectTypeNodeId.java rename to drools-base/src/main/java/org/drools/base/reteoo/ObjectTypeNodeId.java index 38c72e0bb9f..7e93e91bd55 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/ObjectTypeNodeId.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/ObjectTypeNodeId.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.reteoo; +package org.drools.base.reteoo; public class ObjectTypeNodeId { diff --git a/drools-base/src/main/java/org/drools/core/reteoo/SignalAdapter.java b/drools-base/src/main/java/org/drools/base/reteoo/SignalAdapter.java similarity index 73% rename from drools-base/src/main/java/org/drools/core/reteoo/SignalAdapter.java rename to drools-base/src/main/java/org/drools/base/reteoo/SignalAdapter.java index 85e4f1a5ba8..05c4292a5c2 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/SignalAdapter.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/SignalAdapter.java @@ -1,10 +1,10 @@ -package org.drools.core.reteoo; +package org.drools.base.reteoo; import org.drools.base.base.ValueResolver; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.signalprocessors.SignalProcessor; -import org.drools.core.reteoo.sequencing.signalprocessors.SignalStatus; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.signalprocessors.SignalProcessor; +import org.drools.base.reteoo.sequencing.signalprocessors.SignalStatus; +import org.drools.base.util.AbstractLinkedListNode; import org.kie.api.runtime.rule.FactHandle; public class SignalAdapter extends AbstractLinkedListNode { diff --git a/drools-base/src/main/java/org/drools/core/reteoo/Sink.java b/drools-base/src/main/java/org/drools/base/reteoo/Sink.java similarity index 96% rename from drools-base/src/main/java/org/drools/core/reteoo/Sink.java rename to drools-base/src/main/java/org/drools/base/reteoo/Sink.java index c51ba28c799..3cf64fb4608 100755 --- a/drools-base/src/main/java/org/drools/core/reteoo/Sink.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/Sink.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.reteoo; +package org.drools.base.reteoo; import org.drools.base.common.NetworkNode; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/DynamicFilters.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/DynamicFilters.java similarity index 62% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/DynamicFilters.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/DynamicFilters.java index 82461680573..c8d71618228 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/DynamicFilters.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/DynamicFilters.java @@ -1,6 +1,6 @@ -package org.drools.core.reteoo.sequencing; +package org.drools.base.reteoo.sequencing; -import org.drools.core.reteoo.DynamicFilter; +import org.drools.base.reteoo.DynamicFilter; public interface DynamicFilters { DynamicFilter getActiveDynamicFilter(int filterIndex); diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequence.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/Sequence.java similarity index 96% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequence.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/Sequence.java index 554938a3595..67d96033eef 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequence.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/Sequence.java @@ -1,20 +1,22 @@ -package org.drools.core.reteoo.sequencing; +package org.drools.base.reteoo.sequencing; import org.drools.base.base.ValueResolver; +import org.drools.base.phreak.actions.AbstractPropagationEntry; +import org.drools.base.reteoo.DynamicFilter; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.signalprocessors.SignalStatus; +import org.drools.base.reteoo.sequencing.steps.LogicCircuitStep; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.steps.Step.StepFactory; import org.drools.base.rule.Declaration; +import org.drools.base.rule.Pattern; import org.drools.base.rule.RuleConditionElement; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; import org.drools.base.time.Timer; -import org.drools.core.phreak.actions.AbstractPropagationEntry; -import org.drools.core.reteoo.DynamicFilter; -import org.drools.core.reteoo.SignalAdapter; -import org.drools.core.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.signalprocessors.SignalStatus; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.steps.LogicCircuitStep; -import org.drools.core.reteoo.sequencing.steps.Step.StepFactory; +import org.drools.base.reteoo.SignalAdapter; import org.drools.base.time.Job; import org.drools.base.time.JobContext; @@ -31,6 +33,8 @@ public class Sequence implements RuleConditionElement { private final int sequenceIndex; + private Pattern[] filters; + private Step[] steps; private LogicGate[] gates; @@ -52,6 +56,14 @@ public Sequence(int sequenceIndex, StepFactory... stepFactories) { controller = new DefaultController(); } + public Pattern[] getFilters() { + return filters; + } + + public void setFilters(Pattern[] filters) { + this.filters = filters; + } + public int getOutputSize() { return outputSize; } diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequencer.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/Sequencer.java similarity index 85% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequencer.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/Sequencer.java index 9ec79416b35..beb3f00c09f 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/Sequencer.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/Sequencer.java @@ -1,10 +1,9 @@ -package org.drools.core.reteoo.sequencing; +package org.drools.base.reteoo.sequencing; import org.drools.base.base.ValueResolver; -import org.drools.base.reteoo.BaseTuple; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.steps.SequenceStep; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.steps.SequenceStep; +import org.drools.base.reteoo.sequencing.steps.Step; import java.util.ArrayList; import java.util.List; @@ -41,7 +40,7 @@ public void start(SequencerMemory memory, ValueResolver valueResolver) { public void stop(SequencerMemory memory, ValueResolver valueResolver) { // deactive each active sequence on the stack. - ArrayList stack = memory.getSequenceStack(); + ArrayList stack = memory.getSequenceStack(); for (int i = stack.size()-1; i >= 0; i--) { SequenceMemory sequenceMemory = stack.get(i); sequenceMemory.getSequence().getSteps()[sequenceMemory.getStep()].deactivate(sequenceMemory, valueResolver); diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemory.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/SequencerMemory.java similarity index 73% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemory.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/SequencerMemory.java index 1b5c7225eca..eed9c4582e3 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemory.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/SequencerMemory.java @@ -1,10 +1,10 @@ -package org.drools.core.reteoo.sequencing; +package org.drools.base.reteoo.sequencing; import org.drools.base.reteoo.BaseTuple; -import org.drools.core.reteoo.DynamicFilter; -import org.drools.core.reteoo.Sink; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.util.CircularArrayList; +import org.drools.base.reteoo.DynamicFilter; +import org.drools.base.reteoo.Sink; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.util.CircularArrayList; import java.util.ArrayList; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/ConditionalSignalCounter.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/ConditionalSignalCounter.java similarity index 96% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/ConditionalSignalCounter.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/ConditionalSignalCounter.java index 70d9ed1ca6f..3a6dc248303 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/ConditionalSignalCounter.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/ConditionalSignalCounter.java @@ -1,8 +1,8 @@ -package org.drools.core.reteoo.sequencing.signalprocessors; +package org.drools.base.reteoo.sequencing.signalprocessors; import org.drools.base.base.ValueResolver; import org.drools.base.util.index.ConstraintTypeOperator; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import java.util.function.Consumer; import java.util.function.LongPredicate; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/Gates.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/Gates.java similarity index 89% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/Gates.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/Gates.java index 3480b69f33b..7543ed62120 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/Gates.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/Gates.java @@ -1,4 +1,4 @@ -package org.drools.core.reteoo.sequencing.signalprocessors; +package org.drools.base.reteoo.sequencing.signalprocessors; public class Gates { public static boolean and(long a, long b) {return a == b;} diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicCircuit.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/LogicCircuit.java similarity index 83% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicCircuit.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/LogicCircuit.java index 4862c9d72d2..3a2d899619f 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicCircuit.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/LogicCircuit.java @@ -1,4 +1,4 @@ -package org.drools.core.reteoo.sequencing.signalprocessors; +package org.drools.base.reteoo.sequencing.signalprocessors; public class LogicCircuit { diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGate.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/LogicGate.java similarity index 98% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGate.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/LogicGate.java index b55f4c1b76d..ee02752cac3 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGate.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/LogicGate.java @@ -1,12 +1,12 @@ -package org.drools.core.reteoo.sequencing.signalprocessors; +package org.drools.base.reteoo.sequencing.signalprocessors; import org.drools.base.base.ValueResolver; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; import org.drools.base.time.Timer; -import org.drools.core.phreak.actions.AbstractPropagationEntry; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit.LongBiPredicate; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit.LongBiPredicate; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import org.drools.base.time.Job; import org.drools.base.time.JobContext; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGateOutputSignalProcessor.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/LogicGateOutputSignalProcessor.java similarity index 94% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGateOutputSignalProcessor.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/LogicGateOutputSignalProcessor.java index 44a925179c7..942e40f2b30 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/LogicGateOutputSignalProcessor.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/LogicGateOutputSignalProcessor.java @@ -1,7 +1,7 @@ -package org.drools.core.reteoo.sequencing.signalprocessors; +package org.drools.base.reteoo.sequencing.signalprocessors; import org.drools.base.base.ValueResolver; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; public class LogicGateOutputSignalProcessor extends SignalProcessor { private final SignalIndex[] gates; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalIndex.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/SignalIndex.java similarity index 88% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalIndex.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/SignalIndex.java index 7ab07dfc405..9b7ad8b4600 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalIndex.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/SignalIndex.java @@ -1,4 +1,4 @@ -package org.drools.core.reteoo.sequencing.signalprocessors; +package org.drools.base.reteoo.sequencing.signalprocessors; public class SignalIndex { private final LogicGate gate; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalProcessor.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/SignalProcessor.java similarity index 77% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalProcessor.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/SignalProcessor.java index 682f8c5fc07..3b051fdbc0b 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalProcessor.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/SignalProcessor.java @@ -1,7 +1,7 @@ -package org.drools.core.reteoo.sequencing.signalprocessors; +package org.drools.base.reteoo.sequencing.signalprocessors; import org.drools.base.base.ValueResolver; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; public abstract class SignalProcessor { diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalStatus.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/SignalStatus.java similarity index 83% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalStatus.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/SignalStatus.java index f276996ea40..2f856963429 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/SignalStatus.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/SignalStatus.java @@ -1,4 +1,4 @@ -package org.drools.core.reteoo.sequencing.signalprocessors; +package org.drools.base.reteoo.sequencing.signalprocessors; public enum SignalStatus { MATCHED(0), diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/TerminatingSignalProcessor.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/TerminatingSignalProcessor.java similarity index 86% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/TerminatingSignalProcessor.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/TerminatingSignalProcessor.java index d23836a36e8..766cc12feab 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/signalprocessors/TerminatingSignalProcessor.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/signalprocessors/TerminatingSignalProcessor.java @@ -1,7 +1,7 @@ -package org.drools.core.reteoo.sequencing.signalprocessors; +package org.drools.base.reteoo.sequencing.signalprocessors; import org.drools.base.base.ValueResolver; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; public class TerminatingSignalProcessor extends SignalProcessor { private static final TerminatingSignalProcessor INSTANCE = new TerminatingSignalProcessor(); diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AbstractStep.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/AbstractStep.java similarity index 86% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AbstractStep.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/AbstractStep.java index 1e1308d99ee..00ed5537fb6 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AbstractStep.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/AbstractStep.java @@ -1,9 +1,9 @@ -package org.drools.core.reteoo.sequencing.steps; +package org.drools.base.reteoo.sequencing.steps; import org.drools.base.base.ValueResolver; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.SequencerMemory; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.SequencerMemory; public abstract class AbstractStep implements Step { diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/ActionStep.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/ActionStep.java similarity index 81% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/ActionStep.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/ActionStep.java index 4d4c76721a2..9113b6df330 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/ActionStep.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/ActionStep.java @@ -1,8 +1,8 @@ -package org.drools.core.reteoo.sequencing.steps; +package org.drools.base.reteoo.sequencing.steps; import org.drools.base.base.ValueResolver; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import java.util.function.Consumer; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AggregatorStep.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/AggregatorStep.java similarity index 66% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AggregatorStep.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/AggregatorStep.java index 1261ef55103..e0a1676432b 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/AggregatorStep.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/AggregatorStep.java @@ -1,7 +1,7 @@ -package org.drools.core.reteoo.sequencing.steps; +package org.drools.base.reteoo.sequencing.steps; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import java.util.function.Consumer; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/LogicCircuitStep.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/LogicCircuitStep.java similarity index 74% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/LogicCircuitStep.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/LogicCircuitStep.java index 3b7327529fa..b47bdc9a818 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/LogicCircuitStep.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/LogicCircuitStep.java @@ -1,10 +1,10 @@ -package org.drools.core.reteoo.sequencing.steps; +package org.drools.base.reteoo.sequencing.steps; import org.drools.base.base.ValueResolver; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; public class LogicCircuitStep extends AbstractStep implements Step { private final LogicCircuit circuit; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/SequenceStep.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/SequenceStep.java similarity index 88% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/SequenceStep.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/SequenceStep.java index 04c3c084ac0..76741b04090 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/SequenceStep.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/SequenceStep.java @@ -1,9 +1,9 @@ -package org.drools.core.reteoo.sequencing.steps; +package org.drools.base.reteoo.sequencing.steps; import org.drools.base.base.ValueResolver; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.util.CircularArrayList; +import org.drools.base.util.CircularArrayList; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; public class SequenceStep extends AbstractStep implements Step { protected Sequence sequence; diff --git a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/Step.java b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/Step.java similarity index 93% rename from drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/Step.java rename to drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/Step.java index b5c4e78be20..251f20342df 100644 --- a/drools-base/src/main/java/org/drools/core/reteoo/sequencing/steps/Step.java +++ b/drools-base/src/main/java/org/drools/base/reteoo/sequencing/steps/Step.java @@ -1,9 +1,9 @@ -package org.drools.core.reteoo.sequencing.steps; +package org.drools.base.reteoo.sequencing.steps; import org.drools.base.base.ValueResolver; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import java.util.function.Consumer; diff --git a/drools-base/src/main/java/org/drools/core/time/SchedulerService.java b/drools-base/src/main/java/org/drools/base/time/SchedulerService.java similarity index 97% rename from drools-base/src/main/java/org/drools/core/time/SchedulerService.java rename to drools-base/src/main/java/org/drools/base/time/SchedulerService.java index e9fbc37c274..a8644c2a516 100644 --- a/drools-base/src/main/java/org/drools/core/time/SchedulerService.java +++ b/drools-base/src/main/java/org/drools/base/time/SchedulerService.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.time; +package org.drools.base.time; import org.drools.base.time.Job; import org.drools.base.time.JobContext; diff --git a/drools-base/src/main/java/org/drools/core/time/TimerService.java b/drools-base/src/main/java/org/drools/base/time/TimerService.java similarity index 93% rename from drools-base/src/main/java/org/drools/core/time/TimerService.java rename to drools-base/src/main/java/org/drools/base/time/TimerService.java index 97d82b683ee..554fa2acc7d 100644 --- a/drools-base/src/main/java/org/drools/core/time/TimerService.java +++ b/drools-base/src/main/java/org/drools/base/time/TimerService.java @@ -16,12 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.time; +package org.drools.base.time; import java.util.Collection; -import org.drools.core.time.impl.TimerJobFactoryManager; -import org.drools.core.time.impl.TimerJobInstance; +import org.drools.base.time.impl.TimerJobInstance; +import org.drools.base.time.impl.TimerJobFactoryManager; /** * An interface for all timer service implementations used in a drools session. diff --git a/drools-base/src/main/java/org/drools/core/time/impl/InternalSchedulerService.java b/drools-base/src/main/java/org/drools/base/time/impl/InternalSchedulerService.java similarity index 96% rename from drools-base/src/main/java/org/drools/core/time/impl/InternalSchedulerService.java rename to drools-base/src/main/java/org/drools/base/time/impl/InternalSchedulerService.java index a89cb4a65ab..2459a8d8b83 100644 --- a/drools-base/src/main/java/org/drools/core/time/impl/InternalSchedulerService.java +++ b/drools-base/src/main/java/org/drools/base/time/impl/InternalSchedulerService.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.time.impl; +package org.drools.base.time.impl; public interface InternalSchedulerService { public void internalSchedule(TimerJobInstance timerJobInstance); diff --git a/drools-base/src/main/java/org/drools/core/time/impl/TimerJobFactoryManager.java b/drools-base/src/main/java/org/drools/base/time/impl/TimerJobFactoryManager.java similarity index 97% rename from drools-base/src/main/java/org/drools/core/time/impl/TimerJobFactoryManager.java rename to drools-base/src/main/java/org/drools/base/time/impl/TimerJobFactoryManager.java index 9df535340a2..3d55ec58bc6 100644 --- a/drools-base/src/main/java/org/drools/core/time/impl/TimerJobFactoryManager.java +++ b/drools-base/src/main/java/org/drools/base/time/impl/TimerJobFactoryManager.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.time.impl; +package org.drools.base.time.impl; import java.util.Collection; diff --git a/drools-base/src/main/java/org/drools/core/time/impl/TimerJobInstance.java b/drools-base/src/main/java/org/drools/base/time/impl/TimerJobInstance.java similarity index 97% rename from drools-base/src/main/java/org/drools/core/time/impl/TimerJobInstance.java rename to drools-base/src/main/java/org/drools/base/time/impl/TimerJobInstance.java index e469c6e6cce..2463560eb30 100644 --- a/drools-base/src/main/java/org/drools/core/time/impl/TimerJobInstance.java +++ b/drools-base/src/main/java/org/drools/base/time/impl/TimerJobInstance.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.time.impl; +package org.drools.base.time.impl; import org.drools.base.time.JobHandle; import org.drools.base.time.Trigger; diff --git a/drools-base/src/main/java/org/drools/core/util/AbstractLinkedListNode.java b/drools-base/src/main/java/org/drools/base/util/AbstractLinkedListNode.java similarity index 98% rename from drools-base/src/main/java/org/drools/core/util/AbstractLinkedListNode.java rename to drools-base/src/main/java/org/drools/base/util/AbstractLinkedListNode.java index cdd1925f55a..e68bf437c11 100644 --- a/drools-base/src/main/java/org/drools/core/util/AbstractLinkedListNode.java +++ b/drools-base/src/main/java/org/drools/base/util/AbstractLinkedListNode.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.util; +package org.drools.base.util; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; diff --git a/drools-base/src/main/java/org/drools/core/util/CircularArrayList.java b/drools-base/src/main/java/org/drools/base/util/CircularArrayList.java similarity index 98% rename from drools-base/src/main/java/org/drools/core/util/CircularArrayList.java rename to drools-base/src/main/java/org/drools/base/util/CircularArrayList.java index 5b2610fbb1d..d787d674d90 100644 --- a/drools-base/src/main/java/org/drools/core/util/CircularArrayList.java +++ b/drools-base/src/main/java/org/drools/base/util/CircularArrayList.java @@ -1,4 +1,4 @@ -package org.drools.core.util; +package org.drools.base.util; import java.lang.reflect.Array; import java.util.Arrays; diff --git a/drools-base/src/main/java/org/drools/core/util/DoubleLinkedEntry.java b/drools-base/src/main/java/org/drools/base/util/DoubleLinkedEntry.java similarity index 97% rename from drools-base/src/main/java/org/drools/core/util/DoubleLinkedEntry.java rename to drools-base/src/main/java/org/drools/base/util/DoubleLinkedEntry.java index 5039ed15675..20a8ac067ec 100644 --- a/drools-base/src/main/java/org/drools/core/util/DoubleLinkedEntry.java +++ b/drools-base/src/main/java/org/drools/base/util/DoubleLinkedEntry.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.util; +package org.drools.base.util; /** * Items placed in a LinkedList must implement this interface . diff --git a/drools-base/src/main/java/org/drools/core/util/FastIterator.java b/drools-base/src/main/java/org/drools/base/util/FastIterator.java similarity index 98% rename from drools-base/src/main/java/org/drools/core/util/FastIterator.java rename to drools-base/src/main/java/org/drools/base/util/FastIterator.java index 826b8605261..8b67967bb19 100644 --- a/drools-base/src/main/java/org/drools/core/util/FastIterator.java +++ b/drools-base/src/main/java/org/drools/base/util/FastIterator.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.util; +package org.drools.base.util; public interface FastIterator { public class NullFastIterator implements FastIterator { diff --git a/drools-base/src/main/java/org/drools/core/util/Iterator.java b/drools-base/src/main/java/org/drools/base/util/Iterator.java similarity index 96% rename from drools-base/src/main/java/org/drools/core/util/Iterator.java rename to drools-base/src/main/java/org/drools/base/util/Iterator.java index 6ca24347c1c..3655a466dc2 100644 --- a/drools-base/src/main/java/org/drools/core/util/Iterator.java +++ b/drools-base/src/main/java/org/drools/base/util/Iterator.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.util; +package org.drools.base.util; import java.io.Serializable; diff --git a/drools-base/src/main/java/org/drools/core/util/LinkedList.java b/drools-base/src/main/java/org/drools/base/util/LinkedList.java similarity index 99% rename from drools-base/src/main/java/org/drools/core/util/LinkedList.java rename to drools-base/src/main/java/org/drools/base/util/LinkedList.java index 64ddbd2294a..17d19726eb9 100644 --- a/drools-base/src/main/java/org/drools/core/util/LinkedList.java +++ b/drools-base/src/main/java/org/drools/base/util/LinkedList.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.util; +package org.drools.base.util; import java.io.Externalizable; import java.io.IOException; diff --git a/drools-base/src/main/java/org/drools/core/util/LinkedListEntry.java b/drools-base/src/main/java/org/drools/base/util/LinkedListEntry.java similarity index 98% rename from drools-base/src/main/java/org/drools/core/util/LinkedListEntry.java rename to drools-base/src/main/java/org/drools/base/util/LinkedListEntry.java index f52cb623192..768e74528a3 100644 --- a/drools-base/src/main/java/org/drools/core/util/LinkedListEntry.java +++ b/drools-base/src/main/java/org/drools/base/util/LinkedListEntry.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.util; +package org.drools.base.util; import java.io.Externalizable; import java.io.IOException; diff --git a/drools-base/src/main/java/org/drools/core/util/SingleLinkedEntry.java b/drools-base/src/main/java/org/drools/base/util/SingleLinkedEntry.java similarity index 96% rename from drools-base/src/main/java/org/drools/core/util/SingleLinkedEntry.java rename to drools-base/src/main/java/org/drools/base/util/SingleLinkedEntry.java index d080e5a56cb..fa186137f9e 100644 --- a/drools-base/src/main/java/org/drools/core/util/SingleLinkedEntry.java +++ b/drools-base/src/main/java/org/drools/base/util/SingleLinkedEntry.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.drools.core.util; +package org.drools.base.util; public interface SingleLinkedEntry>{ diff --git a/drools-beliefs/src/main/java/org/drools/beliefs/bayes/BayesHardEvidence.java b/drools-beliefs/src/main/java/org/drools/beliefs/bayes/BayesHardEvidence.java index 7a45cf1aef3..e6b03660f3e 100644 --- a/drools-beliefs/src/main/java/org/drools/beliefs/bayes/BayesHardEvidence.java +++ b/drools-beliefs/src/main/java/org/drools/beliefs/bayes/BayesHardEvidence.java @@ -23,7 +23,7 @@ import org.drools.tms.beliefsystem.BeliefSystem; import org.drools.tms.beliefsystem.ModedAssertion; import org.drools.tms.LogicalDependency; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.drools.base.beliefsystem.Mode; public class BayesHardEvidence> extends AbstractLinkedListNode implements ModedAssertion { diff --git a/drools-beliefs/src/main/java/org/drools/beliefs/bayes/NonConflictingModeSet.java b/drools-beliefs/src/main/java/org/drools/beliefs/bayes/NonConflictingModeSet.java index fdf17dc5377..72993313be4 100644 --- a/drools-beliefs/src/main/java/org/drools/beliefs/bayes/NonConflictingModeSet.java +++ b/drools-beliefs/src/main/java/org/drools/beliefs/bayes/NonConflictingModeSet.java @@ -24,7 +24,7 @@ import org.drools.core.common.InternalFactHandle; import org.drools.core.common.WorkingMemoryAction; import org.drools.core.common.PropagationContext; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; public class NonConflictingModeSet> extends LinkedList implements BeliefSet { BayesBeliefSystem beliefSystem; diff --git a/drools-core/src/main/java/org/drools/core/ClockType.java b/drools-core/src/main/java/org/drools/core/ClockType.java index d3aaa608a1e..88b410a40ad 100644 --- a/drools-core/src/main/java/org/drools/core/ClockType.java +++ b/drools-core/src/main/java/org/drools/core/ClockType.java @@ -18,7 +18,7 @@ */ package org.drools.core; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.drools.core.time.impl.JDKTimerService; import org.drools.core.time.impl.PseudoClockScheduler; diff --git a/drools-core/src/main/java/org/drools/core/SessionConfiguration.java b/drools-core/src/main/java/org/drools/core/SessionConfiguration.java index 38f5ce77346..136b075860b 100644 --- a/drools-core/src/main/java/org/drools/core/SessionConfiguration.java +++ b/drools-core/src/main/java/org/drools/core/SessionConfiguration.java @@ -26,8 +26,8 @@ import java.util.Properties; import java.util.Set; -import org.drools.core.time.TimerService; -import org.drools.core.time.impl.TimerJobFactoryManager; +import org.drools.base.time.TimerService; +import org.drools.base.time.impl.TimerJobFactoryManager; import org.drools.util.StringUtils; import org.kie.api.KieBase; import org.kie.api.conf.ConfigurationKey; diff --git a/drools-core/src/main/java/org/drools/core/TimerJobFactoryType.java b/drools-core/src/main/java/org/drools/core/TimerJobFactoryType.java index 0ff7a94061c..89e10522738 100644 --- a/drools-core/src/main/java/org/drools/core/TimerJobFactoryType.java +++ b/drools-core/src/main/java/org/drools/core/TimerJobFactoryType.java @@ -24,7 +24,7 @@ import org.drools.core.time.impl.DefaultTimerJobFactoryManager; import org.drools.core.time.impl.ThreadSafeTrackableTimeJobFactoryManager; -import org.drools.core.time.impl.TimerJobFactoryManager; +import org.drools.base.time.impl.TimerJobFactoryManager; import org.drools.core.time.impl.TrackableTimeJobFactoryManager; public abstract class TimerJobFactoryType implements Serializable { diff --git a/drools-core/src/main/java/org/drools/core/common/ActivationGroupImpl.java b/drools-core/src/main/java/org/drools/core/common/ActivationGroupImpl.java index 45b34d96eed..81513720682 100644 --- a/drools-core/src/main/java/org/drools/core/common/ActivationGroupImpl.java +++ b/drools-core/src/main/java/org/drools/core/common/ActivationGroupImpl.java @@ -19,7 +19,7 @@ package org.drools.core.common; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; public class ActivationGroupImpl implements diff --git a/drools-core/src/main/java/org/drools/core/common/ActivationGroupNode.java b/drools-core/src/main/java/org/drools/core/common/ActivationGroupNode.java index 232efa6f4df..0841cb53649 100644 --- a/drools-core/src/main/java/org/drools/core/common/ActivationGroupNode.java +++ b/drools-core/src/main/java/org/drools/core/common/ActivationGroupNode.java @@ -19,7 +19,7 @@ package org.drools.core.common; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; public class ActivationGroupNode extends AbstractLinkedListNode { diff --git a/drools-core/src/main/java/org/drools/core/common/ActivationNode.java b/drools-core/src/main/java/org/drools/core/common/ActivationNode.java index 85d236a90c4..ec866f1f801 100644 --- a/drools-core/src/main/java/org/drools/core/common/ActivationNode.java +++ b/drools-core/src/main/java/org/drools/core/common/ActivationNode.java @@ -19,7 +19,7 @@ package org.drools.core.common; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; public class ActivationNode extends AbstractLinkedListNode { diff --git a/drools-core/src/main/java/org/drools/core/common/ActivationsManager.java b/drools-core/src/main/java/org/drools/core/common/ActivationsManager.java index 2ad3ba7ae01..7a642e20d46 100644 --- a/drools-core/src/main/java/org/drools/core/common/ActivationsManager.java +++ b/drools-core/src/main/java/org/drools/core/common/ActivationsManager.java @@ -21,7 +21,7 @@ import org.drools.base.common.NetworkNode; import org.drools.core.event.AgendaEventSupport; import org.drools.core.phreak.ExecutableEntry; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.phreak.RuleAgendaItem; import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.RuleTerminalNodeLeftTuple; diff --git a/drools-core/src/main/java/org/drools/core/common/AgendaGroupQueueImpl.java b/drools-core/src/main/java/org/drools/core/common/AgendaGroupQueueImpl.java index c0ccc66a919..780a5a847de 100644 --- a/drools-core/src/main/java/org/drools/core/common/AgendaGroupQueueImpl.java +++ b/drools-core/src/main/java/org/drools/core/common/AgendaGroupQueueImpl.java @@ -28,7 +28,7 @@ import org.drools.core.impl.InternalRuleBase; import org.drools.core.marshalling.MarshallerReaderContext; import org.drools.core.phreak.RuleAgendaItem; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.util.ArrayQueue; import org.drools.core.util.Queue; import org.drools.core.util.QueueFactory; diff --git a/drools-core/src/main/java/org/drools/core/common/BaseNode.java b/drools-core/src/main/java/org/drools/core/common/BaseNode.java index fd151c12918..c4465db7038 100644 --- a/drools-core/src/main/java/org/drools/core/common/BaseNode.java +++ b/drools-core/src/main/java/org/drools/core/common/BaseNode.java @@ -33,7 +33,7 @@ import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.ReteooBuilder; import org.drools.core.reteoo.RuleRemovalContext; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import org.drools.core.reteoo.TerminalNode; import org.drools.core.reteoo.builder.BuildContext; import org.drools.util.bitmask.BitMask; diff --git a/drools-core/src/main/java/org/drools/core/common/DefaultEventHandle.java b/drools-core/src/main/java/org/drools/core/common/DefaultEventHandle.java index a905894d59c..70accb8b742 100644 --- a/drools-core/src/main/java/org/drools/core/common/DefaultEventHandle.java +++ b/drools-core/src/main/java/org/drools/core/common/DefaultEventHandle.java @@ -21,9 +21,9 @@ import org.drools.base.rule.EntryPointId; import org.drools.base.time.JobHandle; import org.drools.core.WorkingMemoryEntryPoint; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.drools.core.time.impl.DefaultJobHandle; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; import org.kie.api.runtime.rule.EventHandle; public class DefaultEventHandle extends DefaultFactHandle implements EventHandle, Comparable { diff --git a/drools-core/src/main/java/org/drools/core/common/DefaultFactHandle.java b/drools-core/src/main/java/org/drools/core/common/DefaultFactHandle.java index 51365d30d7c..59ef0ff6a97 100644 --- a/drools-core/src/main/java/org/drools/core/common/DefaultFactHandle.java +++ b/drools-core/src/main/java/org/drools/core/common/DefaultFactHandle.java @@ -34,11 +34,11 @@ import org.drools.core.WorkingMemoryEntryPoint; import org.drools.core.impl.InternalRuleBase; import org.drools.core.reteoo.LeftTuple; -import org.drools.core.reteoo.ObjectTypeNodeId; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.core.reteoo.RightTuple; import org.drools.core.reteoo.Tuple; import org.drools.core.reteoo.TupleImpl; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.drools.util.StringUtils; import org.kie.api.runtime.rule.FactHandle; diff --git a/drools-core/src/main/java/org/drools/core/common/EqualityKey.java b/drools-core/src/main/java/org/drools/core/common/EqualityKey.java index 68b69ab4936..5fffa9e9a43 100644 --- a/drools-core/src/main/java/org/drools/core/common/EqualityKey.java +++ b/drools-core/src/main/java/org/drools/core/common/EqualityKey.java @@ -23,7 +23,7 @@ import java.io.ObjectInput; import java.io.ObjectOutput; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; /** * Upon instantiation the EqualityKey caches the first Object's hashCode diff --git a/drools-core/src/main/java/org/drools/core/common/InternalActivationGroup.java b/drools-core/src/main/java/org/drools/core/common/InternalActivationGroup.java index 7e65ffb19a9..de837e9e15e 100644 --- a/drools-core/src/main/java/org/drools/core/common/InternalActivationGroup.java +++ b/drools-core/src/main/java/org/drools/core/common/InternalActivationGroup.java @@ -21,7 +21,7 @@ import java.util.Iterator; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; import org.kie.api.runtime.rule.ActivationGroup; public interface InternalActivationGroup extends ActivationGroup { diff --git a/drools-core/src/main/java/org/drools/core/common/InternalAgenda.java b/drools-core/src/main/java/org/drools/core/common/InternalAgenda.java index a7e1755c90d..8f94f02a9f6 100644 --- a/drools-core/src/main/java/org/drools/core/common/InternalAgenda.java +++ b/drools-core/src/main/java/org/drools/core/common/InternalAgenda.java @@ -21,7 +21,7 @@ import java.util.Iterator; import java.util.Map; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.kie.api.runtime.rule.Agenda; import org.kie.api.runtime.rule.AgendaFilter; diff --git a/drools-core/src/main/java/org/drools/core/common/InternalFactHandle.java b/drools-core/src/main/java/org/drools/core/common/InternalFactHandle.java index d8a4af38dff..71ec13c7f93 100644 --- a/drools-core/src/main/java/org/drools/core/common/InternalFactHandle.java +++ b/drools-core/src/main/java/org/drools/core/common/InternalFactHandle.java @@ -26,7 +26,7 @@ import org.drools.base.factmodel.traits.TraitTypeEnum; import org.drools.base.rule.EntryPointId; import org.drools.core.WorkingMemoryEntryPoint; -import org.drools.core.reteoo.ObjectTypeNodeId; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.core.reteoo.TupleImpl; import org.kie.api.runtime.rule.FactHandle; diff --git a/drools-core/src/main/java/org/drools/core/common/InternalKnowledgeRuntime.java b/drools-core/src/main/java/org/drools/core/common/InternalKnowledgeRuntime.java index e1634f0aed6..b76dc3075e0 100644 --- a/drools-core/src/main/java/org/drools/core/common/InternalKnowledgeRuntime.java +++ b/drools-core/src/main/java/org/drools/core/common/InternalKnowledgeRuntime.java @@ -19,7 +19,7 @@ package org.drools.core.common; import org.drools.core.runtime.process.InternalProcessRuntime; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.kie.api.runtime.KieRuntime; public interface InternalKnowledgeRuntime extends KieRuntime { diff --git a/drools-core/src/main/java/org/drools/core/common/InternalWorkingMemory.java b/drools-core/src/main/java/org/drools/core/common/InternalWorkingMemory.java index f6e01ce45cd..1e391f1d74d 100644 --- a/drools-core/src/main/java/org/drools/core/common/InternalWorkingMemory.java +++ b/drools-core/src/main/java/org/drools/core/common/InternalWorkingMemory.java @@ -27,7 +27,7 @@ import org.drools.core.WorkingMemoryEntryPoint; import org.drools.core.event.AgendaEventSupport; import org.drools.core.event.RuleRuntimeEventSupport; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.rule.consequence.InternalMatch; import org.drools.core.runtime.process.InternalProcessRuntime; import org.kie.api.runtime.Channel; diff --git a/drools-core/src/main/java/org/drools/core/common/Memory.java b/drools-core/src/main/java/org/drools/core/common/Memory.java index e4ac146e4a8..a4f16b78326 100644 --- a/drools-core/src/main/java/org/drools/core/common/Memory.java +++ b/drools-core/src/main/java/org/drools/core/common/Memory.java @@ -21,7 +21,7 @@ import org.drools.core.phreak.RuntimeSegmentUtilities; import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.SegmentMemory; -import org.drools.core.util.DoubleLinkedEntry; +import org.drools.base.util.DoubleLinkedEntry; /** * A super interface for node memories diff --git a/drools-core/src/main/java/org/drools/core/common/ReteEvaluator.java b/drools-core/src/main/java/org/drools/core/common/ReteEvaluator.java index c8bb8ce6acd..9228d6116b6 100644 --- a/drools-core/src/main/java/org/drools/core/common/ReteEvaluator.java +++ b/drools-core/src/main/java/org/drools/core/common/ReteEvaluator.java @@ -20,7 +20,6 @@ import java.util.Collection; import java.util.Collections; -import java.util.function.Consumer; import org.drools.base.base.ValueResolver; import org.drools.base.rule.EntryPointId; @@ -31,13 +30,13 @@ import org.drools.core.event.RuleEventListenerSupport; import org.drools.core.event.RuleRuntimeEventSupport; import org.drools.core.impl.InternalRuleBase; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.reteoo.ObjectTypeConf; import org.drools.core.reteoo.RuntimeComponentFactory; import org.drools.core.rule.accessor.FactHandleFactory; import org.drools.core.rule.consequence.KnowledgeHelper; -import org.drools.core.time.TimerService; -import org.drools.core.time.impl.TimerJobInstance; +import org.drools.base.time.TimerService; +import org.drools.base.time.impl.TimerJobInstance; import org.kie.api.runtime.Calendars; import org.kie.api.runtime.rule.AgendaFilter; import org.kie.api.runtime.rule.EntryPoint; diff --git a/drools-core/src/main/java/org/drools/core/common/SuperCacheFixer.java b/drools-core/src/main/java/org/drools/core/common/SuperCacheFixer.java index b08a1f10f75..6bcd765585b 100644 --- a/drools-core/src/main/java/org/drools/core/common/SuperCacheFixer.java +++ b/drools-core/src/main/java/org/drools/core/common/SuperCacheFixer.java @@ -38,15 +38,16 @@ import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.NotNode; import org.drools.core.reteoo.NotRight; -import org.drools.core.reteoo.ObjectTypeNodeId; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.core.reteoo.QueryElementNode; import org.drools.core.reteoo.QueryTerminalNode; import org.drools.core.reteoo.ReactiveFromNode; +import org.drools.core.reteoo.SequenceNode; import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.RightTuple; import org.drools.core.reteoo.RightTupleSink; import org.drools.core.reteoo.RuleTerminalNode; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import org.drools.core.reteoo.TerminalNode; import org.drools.core.reteoo.TimerNode; import org.drools.core.reteoo.TupleImpl; @@ -77,6 +78,7 @@ public static LeftTupleNode getLeftTupleNode(TupleImpl t) { case NodeTypeEnums.QueryElementNode: return (QueryElementNode) s; case NodeTypeEnums.TimerConditionNode: return (TimerNode) s; case NodeTypeEnums.MockBetaNode: return (LeftTupleNode) s; + case NodeTypeEnums.SequenceNode: return (SequenceNode) s; default: throw new UnsupportedOperationException("Cannot be cast to LeftTupleNode: " + s); } @@ -115,6 +117,7 @@ public static LeftTupleSinkNode asLeftTupleSink(NetworkNode n) { case NodeTypeEnums.QueryElementNode: return (QueryElementNode) n; case NodeTypeEnums.TimerConditionNode: return (TimerNode) n; case NodeTypeEnums.MockBetaNode: return (LeftTupleSinkNode) n; + case NodeTypeEnums.SequenceNode: return (SequenceNode) n; default: throw new UnsupportedOperationException("Cannot be cast to LeftTupleNode: " + n); } @@ -139,6 +142,7 @@ public static ObjectTypeNodeId getLeftInputOtnId(TupleImpl t) { case NodeTypeEnums.QueryElementNode: return ((QueryElementNode) s).getInputOtnId(); case NodeTypeEnums.TimerConditionNode: return ((TimerNode) s).getInputOtnId(); case NodeTypeEnums.MockBetaNode: return ((LeftTupleSource)s).getInputOtnId(); + case NodeTypeEnums.SequenceNode: return ((SequenceNode)s).getInputOtnId(); default: throw new UnsupportedOperationException("Node does not have an LeftInputOtnId: " + s); } @@ -175,6 +179,7 @@ public static LeftTupleSource getLeftTupleSource(TupleImpl t) { case NodeTypeEnums.ConditionalBranchNode: return ((ConditionalBranchNode) s).getLeftTupleSource(); case NodeTypeEnums.QueryElementNode: return ((QueryElementNode) s).getLeftTupleSource(); case NodeTypeEnums.TimerConditionNode: return ((TimerNode) s).getLeftTupleSource(); + case NodeTypeEnums.SequenceNode: return ((SequenceNode)s).getLeftTupleSource(); default: throw new UnsupportedOperationException("Does not have a LeftTupleSource: " + s); } diff --git a/drools-core/src/main/java/org/drools/core/common/WorkingMemoryAction.java b/drools-core/src/main/java/org/drools/core/common/WorkingMemoryAction.java index 866add5915b..ea9b3ed9a3b 100644 --- a/drools-core/src/main/java/org/drools/core/common/WorkingMemoryAction.java +++ b/drools-core/src/main/java/org/drools/core/common/WorkingMemoryAction.java @@ -18,7 +18,7 @@ */ package org.drools.core.common; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; public interface WorkingMemoryAction extends PropagationEntry { short WorkingMemoryReteAssertAction = 1; diff --git a/drools-core/src/main/java/org/drools/core/impl/ActivationsManagerImpl.java b/drools-core/src/main/java/org/drools/core/impl/ActivationsManagerImpl.java index 7b4ea779675..c51be7b2d9a 100644 --- a/drools-core/src/main/java/org/drools/core/impl/ActivationsManagerImpl.java +++ b/drools-core/src/main/java/org/drools/core/impl/ActivationsManagerImpl.java @@ -27,6 +27,7 @@ import org.drools.base.definitions.rule.impl.QueryImpl; import org.drools.base.definitions.rule.impl.RuleImpl; +import org.drools.base.util.LinkedList; import org.drools.core.common.ActivationGroupImpl; import org.drools.core.common.ActivationGroupNode; import org.drools.core.common.ActivationsFilter; @@ -42,7 +43,7 @@ import org.drools.core.concurrent.SequentialGroupEvaluator; import org.drools.core.event.AgendaEventSupport; import org.drools.core.phreak.ExecutableEntry; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.phreak.PropagationList; import org.drools.core.phreak.RuleAgendaItem; import org.drools.core.phreak.RuleExecutor; @@ -76,7 +77,7 @@ public class ActivationsManagerImpl implements ActivationsManager { private boolean firing = false; - private final org.drools.core.util.LinkedList eager = new org.drools.core.util.LinkedList<>(); + private final LinkedList eager = new LinkedList<>(); private final Map queries = new ConcurrentHashMap<>(); diff --git a/drools-core/src/main/java/org/drools/core/impl/WorkingMemoryReteExpireAction.java b/drools-core/src/main/java/org/drools/core/impl/WorkingMemoryReteExpireAction.java index e7179f6fdb4..925ceafd861 100644 --- a/drools-core/src/main/java/org/drools/core/impl/WorkingMemoryReteExpireAction.java +++ b/drools-core/src/main/java/org/drools/core/impl/WorkingMemoryReteExpireAction.java @@ -29,9 +29,9 @@ import org.drools.core.common.ReteEvaluator; import org.drools.core.common.WorkingMemoryAction; import org.drools.core.marshalling.MarshallerReaderContext; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.phreak.actions.AbstractPartitionedPropagationEntry; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.RightTuple; diff --git a/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java b/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java index 1475867533f..8e8b56692d5 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java +++ b/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java @@ -55,7 +55,6 @@ import org.drools.core.reteoo.LeftTupleNode; import org.drools.core.reteoo.LeftTupleSinkNode; import org.drools.core.reteoo.ObjectSink; -import org.drools.core.reteoo.ObjectSource; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.PathEndNode; import org.drools.core.reteoo.PathEndNode.PathMemSpec; @@ -76,7 +75,7 @@ import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; import org.drools.core.reteoo.WindowNode; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java b/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java index 518f425ba08..b4b873aeb62 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java +++ b/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java @@ -82,7 +82,7 @@ import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; import org.drools.core.reteoo.WindowNode; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import org.kie.api.definition.rule.Rule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakAccumulateNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakAccumulateNode.java index 05b0b4fa80f..fb4bf30ab82 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakAccumulateNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakAccumulateNode.java @@ -40,7 +40,7 @@ import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; import org.drools.core.util.AbstractHashTable; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import org.kie.api.runtime.rule.FactHandle; import static org.drools.core.phreak.RuleNetworkEvaluator.normalizeStagedTuples; diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakExistsNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakExistsNode.java index 7cf6734b428..7148443dbb9 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakExistsNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakExistsNode.java @@ -30,7 +30,7 @@ import org.drools.core.reteoo.TupleFactory; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import static org.drools.core.phreak.PhreakJoinNode.updateChildLeftTuple; diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakFromNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakFromNode.java index 3efdbc129a1..b8b6f6f29ba 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakFromNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakFromNode.java @@ -36,8 +36,8 @@ import org.drools.core.reteoo.LeftTupleSink; import org.drools.core.reteoo.RightTuple; import org.drools.core.reteoo.TupleMemory; -import org.drools.core.util.FastIterator; -import org.drools.core.util.LinkedList; +import org.drools.base.util.FastIterator; +import org.drools.base.util.LinkedList; import org.kie.api.runtime.rule.FactHandle; import static org.drools.core.phreak.PhreakJoinNode.updateChildLeftTuple; diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakJoinNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakJoinNode.java index 5620f393642..ffafd853107 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakJoinNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakJoinNode.java @@ -29,7 +29,7 @@ import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; import org.drools.core.util.AbstractHashTable; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; public class PhreakJoinNode { public void doNode(JoinNode joinNode, diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakNotNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakNotNode.java index f8eb034df20..69fe246f518 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakNotNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakNotNode.java @@ -30,7 +30,7 @@ import org.drools.core.reteoo.TupleFactory; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import static org.drools.core.phreak.PhreakJoinNode.updateChildLeftTuple; diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakQueryTerminalNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakQueryTerminalNode.java index 676351d3efa..7e9ddfb4e47 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakQueryTerminalNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakQueryTerminalNode.java @@ -23,14 +23,13 @@ import org.drools.core.base.DroolsQueryImpl; import org.drools.core.common.ActivationsManager; import org.drools.core.common.TupleSets; -import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.LeftTupleSink; import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory; import org.drools.core.reteoo.QueryTerminalNode; import org.drools.core.reteoo.Tuple; import org.drools.core.reteoo.TupleImpl; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; /** * Created with IntelliJ IDEA. diff --git a/drools-core/src/main/java/org/drools/core/phreak/PhreakTimerNode.java b/drools-core/src/main/java/org/drools/core/phreak/PhreakTimerNode.java index f5429df7e32..2a55faffbbc 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PhreakTimerNode.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PhreakTimerNode.java @@ -34,7 +34,7 @@ import org.drools.core.common.TupleSets; import org.drools.core.common.WorkingMemoryAction; import org.drools.core.marshalling.TupleKey; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.LeftTupleSink; import org.drools.core.reteoo.LeftTupleSource; @@ -47,9 +47,9 @@ import org.drools.core.reteoo.TupleImpl; import org.drools.base.time.Job; import org.drools.base.time.JobContext; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.drools.core.time.impl.DefaultJobHandle; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; import org.drools.core.util.index.TupleList; import org.kie.api.definition.rule.Rule; import org.kie.api.runtime.Calendars; diff --git a/drools-core/src/main/java/org/drools/core/phreak/PropagationList.java b/drools-core/src/main/java/org/drools/core/phreak/PropagationList.java index 73db997171b..a3dab69c181 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/PropagationList.java +++ b/drools-core/src/main/java/org/drools/core/phreak/PropagationList.java @@ -18,6 +18,8 @@ */ package org.drools.core.phreak; +import org.drools.base.phreak.PropagationEntry; + import java.util.Iterator; public interface PropagationList { diff --git a/drools-core/src/main/java/org/drools/core/phreak/ReactiveObjectUtil.java b/drools-core/src/main/java/org/drools/core/phreak/ReactiveObjectUtil.java index 4f85d66165c..d9af6e12e29 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/ReactiveObjectUtil.java +++ b/drools-core/src/main/java/org/drools/core/phreak/ReactiveObjectUtil.java @@ -26,7 +26,7 @@ import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.LeftTupleSinkNode; import org.drools.core.reteoo.ReactiveFromNode; import org.drools.core.reteoo.ReactiveFromNodeLeftTuple; diff --git a/drools-core/src/main/java/org/drools/core/phreak/RuleAgendaItem.java b/drools-core/src/main/java/org/drools/core/phreak/RuleAgendaItem.java index 6714c8aedca..ea139682970 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/RuleAgendaItem.java +++ b/drools-core/src/main/java/org/drools/core/phreak/RuleAgendaItem.java @@ -23,8 +23,8 @@ import org.drools.core.common.InternalAgendaGroup; import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.TerminalNode; -import org.drools.core.util.LinkedList; -import org.drools.core.util.DoubleLinkedEntry; +import org.drools.base.util.LinkedList; +import org.drools.base.util.DoubleLinkedEntry; import org.drools.core.util.Queue.QueueEntry; public class RuleAgendaItem implements DoubleLinkedEntry, QueueEntry { diff --git a/drools-core/src/main/java/org/drools/core/phreak/RuleExecutor.java b/drools-core/src/main/java/org/drools/core/phreak/RuleExecutor.java index d4db8329ffd..48556a0d2cc 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/RuleExecutor.java +++ b/drools-core/src/main/java/org/drools/core/phreak/RuleExecutor.java @@ -37,7 +37,7 @@ import org.drools.core.reteoo.TupleImpl; import org.drools.core.rule.consequence.InternalMatch; import org.drools.core.rule.consequence.KnowledgeHelper; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; import org.drools.core.util.Queue; import org.drools.core.util.QueueFactory; import org.drools.core.util.index.TupleList; diff --git a/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java b/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java index 516ef2283a2..1f78ed9d708 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java +++ b/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java @@ -75,8 +75,8 @@ import org.drools.core.reteoo.TimerNode.TimerNodeMemory; import org.drools.core.reteoo.Tuple; import org.drools.core.reteoo.TupleMemory; -import org.drools.core.util.FastIterator; -import org.drools.core.util.LinkedList; +import org.drools.base.util.FastIterator; +import org.drools.base.util.LinkedList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/drools-core/src/main/java/org/drools/core/phreak/StackEntry.java b/drools-core/src/main/java/org/drools/core/phreak/StackEntry.java index 8bfc4a1a680..1412d468a3f 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/StackEntry.java +++ b/drools-core/src/main/java/org/drools/core/phreak/StackEntry.java @@ -24,7 +24,7 @@ import org.drools.core.reteoo.LeftTupleSinkNode; import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.SegmentMemory; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; /** * Created with IntelliJ IDEA. diff --git a/drools-core/src/main/java/org/drools/core/phreak/SynchronizedBypassPropagationList.java b/drools-core/src/main/java/org/drools/core/phreak/SynchronizedBypassPropagationList.java index cd94fc298f7..33f1d91b393 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/SynchronizedBypassPropagationList.java +++ b/drools-core/src/main/java/org/drools/core/phreak/SynchronizedBypassPropagationList.java @@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicBoolean; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.common.ReteEvaluator; public class SynchronizedBypassPropagationList extends SynchronizedPropagationList { diff --git a/drools-core/src/main/java/org/drools/core/phreak/SynchronizedPropagationList.java b/drools-core/src/main/java/org/drools/core/phreak/SynchronizedPropagationList.java index e46a618a1a0..4b8d9813f00 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/SynchronizedPropagationList.java +++ b/drools-core/src/main/java/org/drools/core/phreak/SynchronizedPropagationList.java @@ -20,6 +20,7 @@ import java.util.Iterator; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.common.ReteEvaluator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/drools-core/src/main/java/org/drools/core/phreak/ThreadUnsafePropagationList.java b/drools-core/src/main/java/org/drools/core/phreak/ThreadUnsafePropagationList.java index c169b9fddb8..8b5ff098e09 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/ThreadUnsafePropagationList.java +++ b/drools-core/src/main/java/org/drools/core/phreak/ThreadUnsafePropagationList.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.Iterator; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.common.ReteEvaluator; public class ThreadUnsafePropagationList implements PropagationList { @@ -32,7 +33,7 @@ public ThreadUnsafePropagationList( ReteEvaluator reteEvaluator ) { } @Override - public void addEntry( PropagationEntry propagationEntry ) { + public void addEntry( PropagationEntry propagationEntry) { propagationEntry.execute( reteEvaluator ); } diff --git a/drools-core/src/main/java/org/drools/core/phreak/TupleEvaluationUtil.java b/drools-core/src/main/java/org/drools/core/phreak/TupleEvaluationUtil.java index 9bb89fd6fe7..339a3a3529c 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/TupleEvaluationUtil.java +++ b/drools-core/src/main/java/org/drools/core/phreak/TupleEvaluationUtil.java @@ -35,7 +35,7 @@ import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.SegmentMemory; import org.drools.core.reteoo.Tuple; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; public class TupleEvaluationUtil { public static boolean flushLeftTupleIfNecessary(ReteEvaluator reteEvaluator, SegmentMemory sm, boolean streamMode) { diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/AbstractPartitionedPropagationEntry.java b/drools-core/src/main/java/org/drools/core/phreak/actions/AbstractPartitionedPropagationEntry.java index aa0adbc8d41..141d00caacf 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/actions/AbstractPartitionedPropagationEntry.java +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/AbstractPartitionedPropagationEntry.java @@ -1,6 +1,7 @@ package org.drools.core.phreak.actions; import org.drools.base.base.ValueResolver; +import org.drools.base.phreak.actions.AbstractPropagationEntry; public abstract class AbstractPartitionedPropagationEntry extends AbstractPropagationEntry { protected final int partition; diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/Delete.java b/drools-core/src/main/java/org/drools/core/phreak/actions/Delete.java index 916864573e7..c0137222cf4 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/actions/Delete.java +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/Delete.java @@ -1,9 +1,10 @@ package org.drools.core.phreak.actions; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.ObjectTypeConf; diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/Insert.java b/drools-core/src/main/java/org/drools/core/phreak/actions/Insert.java index afccfcfc71f..b7782738941 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/actions/Insert.java +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/Insert.java @@ -1,11 +1,12 @@ package org.drools.core.phreak.actions; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.common.DefaultEventHandle; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; import org.drools.core.impl.WorkingMemoryReteExpireAction; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.reteoo.ClassObjectTypeConf; import org.drools.core.reteoo.ObjectTypeConf; import org.drools.core.reteoo.ObjectTypeNode; diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/PropagationEntryWithResult.java b/drools-core/src/main/java/org/drools/core/phreak/actions/PropagationEntryWithResult.java index 62001d4ec64..27fbdfbc4bc 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/actions/PropagationEntryWithResult.java +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/PropagationEntryWithResult.java @@ -1,6 +1,7 @@ package org.drools.core.phreak.actions; import org.drools.base.base.ValueResolver; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import java.util.concurrent.CountDownLatch; diff --git a/drools-core/src/main/java/org/drools/core/phreak/actions/Update.java b/drools-core/src/main/java/org/drools/core/phreak/actions/Update.java index 739e50bc0a0..4ebf015ce32 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/actions/Update.java +++ b/drools-core/src/main/java/org/drools/core/phreak/actions/Update.java @@ -1,9 +1,10 @@ package org.drools.core.phreak.actions; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.reteoo.ModifyPreviousTuples; import org.drools.core.reteoo.ObjectTypeConf; import org.drools.core.reteoo.ObjectTypeNode; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AccumulateNode.java b/drools-core/src/main/java/org/drools/core/reteoo/AccumulateNode.java index 28b829aab90..556d16ed88f 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AccumulateNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AccumulateNode.java @@ -44,7 +44,7 @@ import org.drools.core.impl.InternalRuleBase; import org.drools.core.phreak.PhreakAccumulateNode; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.drools.core.util.index.TupleList; import org.drools.core.util.index.TupleListWithContext; import org.drools.util.bitmask.BitMask; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AgendaComponentFactory.java b/drools-core/src/main/java/org/drools/core/reteoo/AgendaComponentFactory.java index aa88561e922..6e1291c2805 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AgendaComponentFactory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AgendaComponentFactory.java @@ -18,6 +18,7 @@ */ package org.drools.core.reteoo; +import org.drools.base.reteoo.Sink; import org.drools.core.common.InternalAgendaGroup; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AlphaTerminalNode.java b/drools-core/src/main/java/org/drools/core/reteoo/AlphaTerminalNode.java index 99d6107c8c0..3dbbb236724 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AlphaTerminalNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AlphaTerminalNode.java @@ -20,6 +20,7 @@ import org.drools.base.common.NetworkNode; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.core.common.ActivationsManager; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java b/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java index baeab3c84a4..6dc92f147fa 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AsyncReceiveNode.java @@ -34,9 +34,9 @@ import org.drools.core.common.MemoryFactory; import org.drools.core.common.ReteEvaluator; import org.drools.core.common.UpdateContext; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.drools.core.util.index.TupleList; public class AsyncReceiveNode extends LeftTupleSource diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AsyncSendNode.java b/drools-core/src/main/java/org/drools/core/reteoo/AsyncSendNode.java index cd0e252dda5..3837dbddd33 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AsyncSendNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AsyncSendNode.java @@ -37,7 +37,7 @@ import org.drools.core.common.ReteEvaluator; import org.drools.core.common.UpdateContext; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.drools.core.util.index.TupleList; public class AsyncSendNode extends LeftTupleSource diff --git a/drools-core/src/main/java/org/drools/core/reteoo/BetaMemory.java b/drools-core/src/main/java/org/drools/core/reteoo/BetaMemory.java index cddd87111f6..cbbd95a3b76 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/BetaMemory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/BetaMemory.java @@ -23,7 +23,7 @@ import org.drools.core.common.TupleSets; import org.drools.core.common.TupleSetsImpl; import org.drools.core.reteoo.TupleToObjectNode.SubnetworkPathMemory; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; public class BetaMemory extends AbstractLinkedListNode implements SegmentNodeMemory { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java b/drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java index f0be4ccae4f..9f038a10970 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java @@ -27,6 +27,7 @@ import org.drools.base.common.RuleBasePartitionId; import org.drools.base.reteoo.BaseTerminalNode; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.base.rule.IndexableConstraint; import org.drools.base.util.index.IndexUtil; import org.drools.core.RuleBaseConfiguration; @@ -50,7 +51,7 @@ import org.drools.core.reteoo.AccumulateNode.AccumulateMemory; import org.drools.core.reteoo.builder.BuildContext; import org.drools.base.rule.constraint.BetaConstraint; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import org.kie.api.definition.rule.Rule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -473,8 +474,8 @@ public RightTupleSinkAdapter() { public void assertObject(final InternalFactHandle factHandle, final PropagationContext context, final ReteEvaluator reteEvaluator) { - ObjectTypeNodeId otnId = bnNode.getRightInput().getInputOtnId(); - TupleImpl detached = factHandle.getLinkedTuples().detachRightTupleAfter(getPartitionId(), otnId); + ObjectTypeNodeId otnId = bnNode.getRightInput().getInputOtnId(); + TupleImpl detached = factHandle.getLinkedTuples().detachRightTupleAfter(getPartitionId(), otnId); if (detached != null) { detachedTuples.add(new DetachedTuple((DefaultFactHandle) factHandle, detached)); } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java b/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java index c8fdb54d5b8..4632910f982 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java @@ -35,7 +35,7 @@ import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.CompositeObjectSinkAdapter.FieldIndex; public class CompositePartitionAwareObjectSinkAdapter implements ObjectSinkPropagator { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ConditionalBranchNode.java b/drools-core/src/main/java/org/drools/core/reteoo/ConditionalBranchNode.java index fcff4080429..eff2255fe82 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ConditionalBranchNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ConditionalBranchNode.java @@ -26,14 +26,12 @@ import org.drools.base.common.NetworkNode; import org.drools.base.reteoo.NodeTypeEnums; import org.drools.core.RuleBaseConfiguration; -import org.drools.core.common.InternalFactHandle; import org.drools.core.common.Memory; import org.drools.core.common.MemoryFactory; -import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; import org.drools.core.common.UpdateContext; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; /** * Node which allows to follow different paths in the Rete-OO network, diff --git a/drools-core/src/main/java/org/drools/core/reteoo/EntryPointNode.java b/drools-core/src/main/java/org/drools/core/reteoo/EntryPointNode.java index 34b0a8792f6..d005ba36c5a 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/EntryPointNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/EntryPointNode.java @@ -28,6 +28,7 @@ import org.drools.base.common.NetworkNode; import org.drools.base.common.RuleBasePartitionId; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.Sink; import org.drools.base.rule.EntryPointId; import org.drools.base.rule.Pattern; import org.drools.core.WorkingMemoryEntryPoint; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/EvalConditionNode.java b/drools-core/src/main/java/org/drools/core/reteoo/EvalConditionNode.java index 7aa457ee388..b1b108ccded 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/EvalConditionNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/EvalConditionNode.java @@ -35,7 +35,7 @@ import org.drools.core.common.ReteEvaluator; import org.drools.core.common.UpdateContext; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.kie.api.definition.rule.Rule; public class EvalConditionNode extends LeftTupleSource diff --git a/drools-core/src/main/java/org/drools/core/reteoo/EvalNodeLeftTuple.java b/drools-core/src/main/java/org/drools/core/reteoo/EvalNodeLeftTuple.java index 8d1140611fd..9cb5969aa47 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/EvalNodeLeftTuple.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/EvalNodeLeftTuple.java @@ -18,6 +18,7 @@ */ package org.drools.core.reteoo; +import org.drools.base.reteoo.Sink; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java b/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java index 07911833534..ad4e0ffa782 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java @@ -43,7 +43,7 @@ import org.drools.core.common.ReteEvaluator; import org.drools.core.common.UpdateContext; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.drools.core.util.index.TupleList; import org.drools.util.bitmask.AllSetBitMask; import org.drools.util.bitmask.BitMask; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/LeftInputAdapterNode.java b/drools-core/src/main/java/org/drools/core/reteoo/LeftInputAdapterNode.java index 99295c32dc6..d7dfaa2cb40 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/LeftInputAdapterNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/LeftInputAdapterNode.java @@ -29,6 +29,7 @@ import org.drools.base.common.RuleBasePartitionId; import org.drools.base.reteoo.BaseTerminalNode; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.base.rule.Pattern; import org.drools.core.RuleBaseConfiguration; import org.drools.core.common.BaseNode; @@ -45,7 +46,7 @@ import org.drools.core.phreak.RuntimeSegmentUtilities; import org.drools.core.reteoo.builder.BuildContext; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.drools.util.bitmask.AllSetBitMask; import org.drools.util.bitmask.BitMask; import org.kie.api.definition.rule.Rule; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/LeftTuple.java b/drools-core/src/main/java/org/drools/core/reteoo/LeftTuple.java index 76be3ad1c55..985304458ee 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/LeftTuple.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/LeftTuple.java @@ -18,8 +18,8 @@ */ package org.drools.core.reteoo; -import org.drools.base.common.NetworkNode; -import org.drools.core.common.BaseNode; +import org.drools.base.reteoo.ObjectTypeNodeId; +import org.drools.base.reteoo.Sink; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; import org.drools.core.common.SuperCacheFixer; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSink.java b/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSink.java index 6b2a7847ea3..6a924f29b27 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSink.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSink.java @@ -19,6 +19,8 @@ package org.drools.core.reteoo; import org.drools.base.common.RuleBasePartitionId; +import org.drools.base.reteoo.ObjectTypeNodeId; +import org.drools.base.reteoo.Sink; import org.drools.util.bitmask.BitMask; /** diff --git a/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSource.java b/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSource.java index ec379058912..4c9de220952 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSource.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSource.java @@ -25,6 +25,7 @@ import org.drools.base.base.ObjectType; import org.drools.base.common.RuleBasePartitionId; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.base.rule.Pattern; import org.drools.core.common.BaseNode; import org.drools.core.phreak.BuildtimeSegmentUtilities; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/NotNodeLeftTuple.java b/drools-core/src/main/java/org/drools/core/reteoo/NotNodeLeftTuple.java index 69dc86b89aa..176af8bb70c 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/NotNodeLeftTuple.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/NotNodeLeftTuple.java @@ -23,12 +23,13 @@ import java.util.Collections; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.Sink; import org.drools.core.common.BetaConstraints; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.MemoryFactory; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; public class NotNodeLeftTuple extends LeftTuple { private static final long serialVersionUID = 540l; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ObjectRouter.java b/drools-core/src/main/java/org/drools/core/reteoo/ObjectRouter.java deleted file mode 100644 index 3fda077e05a..00000000000 --- a/drools-core/src/main/java/org/drools/core/reteoo/ObjectRouter.java +++ /dev/null @@ -1,214 +0,0 @@ -package org.drools.core.reteoo; - -import org.drools.base.base.ObjectType; -import org.drools.base.common.RuleBasePartitionId; -import org.drools.base.reteoo.NodeTypeEnums; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.common.InternalFactHandle; -import org.drools.core.common.InternalWorkingMemory; -import org.drools.core.common.PropagationContext; -import org.drools.core.common.ReteEvaluator; -import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.util.AbstractLinkedListNode; -import org.drools.core.util.LinkedList; -import org.drools.util.bitmask.BitMask; - -import java.util.List; - -public class ObjectRouter { - - private RouteAdapter[] adapters; - - private LinkedList[] activeFilters; - - public ObjectRouter() { - } - - public void setRouterAdapters(RouteAdapter[] adapters) { - this.adapters = adapters; - activeFilters = new LinkedList[adapters.length]; - for (int i = 0; i < activeFilters.length; i++) { - activeFilters[i] = new LinkedList<>(); - } - } - - public void addFilter(Filter filter, int index) { - activeFilters[index].add(filter); - } - -// public void received(InternalFactHandle factHandle, PropagationContext pctx, ReteEvaluator reteEvaluator, RouteAdapter adapter) { -// System.out.println(adapter.getObjectTypeNode() + " : " + adapter.adapterIndex); -// -// for (Filter filter = activeFilters[adapter.adapterIndex].getFirst(); filter != null; filter = filter.getNext()) { -// filter.assertObject(factHandle, pctx, reteEvaluator); -// } -// } - - public void assertObject(final InternalFactHandle factHandle, - final PropagationContext pctx, - final ReteEvaluator reteEvaluator) { -// System.out.println(adapter.getObjectTypeNode() + " : " + adapter.adapterIndex); -// -// for (Filter filter = activeFilters[adapter.adapterIndex].getFirst(); filter != null; filter = filter.getNext()) { -// filter.assertObject(factHandle, pctx, reteEvaluator); -// } - } - - public void modifyObject(InternalFactHandle factHandle, - ModifyPreviousTuples modifyPreviousTuples, - PropagationContext context, - ReteEvaluator reteEvaluator) { - - } - - public void retractRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { - // for now assuming we don't have any deletes, but we could add this later. - } - - public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { - // for now assuming we don't have any modifies, but we could add this later. - // typically just gets treated as another add, as the processor is not that stateful (for this use case) - to keep it fast. - } - - - public static class Filter extends AbstractLinkedListNode { - private AlphaNodeFieldConstraint constraint; - private SequenceNode node; - - - public Filter(AlphaNodeFieldConstraint constraint) { - this.constraint = constraint; - } - - public AlphaNodeFieldConstraint getConstraint() { - return constraint; - } - - public void assertObject(final InternalFactHandle factHandle, - final PropagationContext pctx, - final ReteEvaluator reteEvaluator) { - if (constraint.isAllowed(factHandle, reteEvaluator)) { - System.out.println("true : " + factHandle.getObject()); - //router.received(factHandle, pctx, reteEvaluator, this); - } - } - - public void modifyObject(InternalFactHandle factHandle, - ModifyPreviousTuples modifyPreviousTuples, - PropagationContext context, - ReteEvaluator reteEvaluator) { - - } - - public void retractRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { - // for now assuming we don't have any deletes, but we could add this later. - } - - public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { - // for now assuming we don't have any modifies, but we could add this later. - // typically just gets treated as another add, as the processor is not that stateful (for this use case) - to keep it fast. - } - } - - /** - * Used with the updateSink method, so that the parent ObjectSource - * can update the TupleSink - */ - public static class RouteAdapter extends ObjectSource - implements - ObjectSinkNode, - RightTupleSink { - - private ObjectRouter router; - private int adapterIndex; - - private ObjectTypeNodeId otnId; - - - public RouteAdapter(int id, ObjectSource source, RuleBasePartitionId partitionId, ObjectRouter router, int adapterIndex) { - super(id, source, partitionId); - this.router = router; - this.adapterIndex = adapterIndex; - } - - public void assertObject(final InternalFactHandle factHandle, - final PropagationContext pctx, - final ReteEvaluator reteEvaluator) { - //router.received(factHandle, pctx, reteEvaluator, this); - - } - - public void modifyObject(InternalFactHandle factHandle, - ModifyPreviousTuples modifyPreviousTuples, - PropagationContext context, - ReteEvaluator reteEvaluator) { - - } - - @Override - public void retractRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { - // for now assuming we don't have any deletes, but we could add this later. - } - - @Override - public void modifyRightTuple(TupleImpl rightTuple, PropagationContext context, ReteEvaluator reteEvaluator) { - // for now assuming we don't have any modifies, but we could add this later. - // typically just gets treated as another add, as the processor is not that stateful (for this use case) - to keep it fast. - } - - public int getId() { - return 0; - } - - public void byPassModifyToBetaNode(InternalFactHandle factHandle, - ModifyPreviousTuples modifyPreviousTuples, - PropagationContext context, - ReteEvaluator reteEvaluator) { - throw new UnsupportedOperationException(); - } - - @Override - public ObjectSinkNode getNextObjectSinkNode() { - return null; - } - - @Override - public void setNextObjectSinkNode(ObjectSinkNode next) { - - } - - @Override - public ObjectSinkNode getPreviousObjectSinkNode() { - return null; - } - - @Override - public void setPreviousObjectSinkNode(ObjectSinkNode previous) { - - } - - @Override - public BitMask calculateDeclaredMask(ObjectType modifiedType, List settableProperties) { - return null; - } - - @Override - public void updateSink(ObjectSink sink, PropagationContext context, InternalWorkingMemory workingMemory) { - - } - - @Override - public ObjectTypeNodeId getInputOtnId() { - return otnId; - } - - public int getType() { - return NodeTypeEnums.SequenceNode; // need to update enums for multi input (mdp) - } - - public void doAttach(BuildContext context) { - super.doAttach(context); - this.source.addObjectSink(this); - } - } -} diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ObjectSink.java b/drools-core/src/main/java/org/drools/core/reteoo/ObjectSink.java index 844a7c4dde0..97d1b590208 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ObjectSink.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ObjectSink.java @@ -18,6 +18,7 @@ */ package org.drools.core.reteoo; +import org.drools.base.reteoo.Sink; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java b/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java index dab101d8115..4eff92af3ee 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java @@ -34,6 +34,7 @@ import org.drools.base.common.NetworkNode; import org.drools.base.common.RuleBasePartitionId; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.base.rule.EntryPointId; import org.drools.base.rule.Pattern; import org.drools.base.time.JobHandle; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/PathMemory.java b/drools-core/src/main/java/org/drools/core/reteoo/PathMemory.java index 93c41fe9aea..ddc5d01994a 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/PathMemory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/PathMemory.java @@ -28,7 +28,7 @@ import org.drools.core.common.Memory; import org.drools.core.common.ReteEvaluator; import org.drools.core.phreak.RuleAgendaItem; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/QueryElementNode.java b/drools-core/src/main/java/org/drools/core/reteoo/QueryElementNode.java index 73039ef50be..ef6d4cd8215 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/QueryElementNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/QueryElementNode.java @@ -43,7 +43,7 @@ import org.drools.core.phreak.StackEntry; import org.drools.core.reteoo.builder.BuildContext; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.kie.api.runtime.rule.FactHandle; public class QueryElementNode extends LeftTupleSource implements LeftTupleSinkNode, MemoryFactory { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/QueryTerminalNode.java b/drools-core/src/main/java/org/drools/core/reteoo/QueryTerminalNode.java index e4016cf7195..971fe7ca76f 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/QueryTerminalNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/QueryTerminalNode.java @@ -23,6 +23,7 @@ import org.drools.base.definitions.rule.impl.QueryImpl; import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.base.rule.Declaration; import org.drools.base.rule.GroupElement; import org.drools.core.reteoo.builder.BuildContext; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/ReactiveFromNodeLeftTuple.java b/drools-core/src/main/java/org/drools/core/reteoo/ReactiveFromNodeLeftTuple.java index dc751cafc6e..5a2c10437ea 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/ReactiveFromNodeLeftTuple.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/ReactiveFromNodeLeftTuple.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; +import org.drools.base.reteoo.Sink; import org.drools.core.common.InternalFactHandle; import org.drools.core.phreak.ReactiveObjectUtil.ModificationType; import org.kie.api.runtime.rule.FactHandle; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/RightInputAdapterNode.java b/drools-core/src/main/java/org/drools/core/reteoo/RightInputAdapterNode.java index 914870add92..4fb16f5809d 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/RightInputAdapterNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/RightInputAdapterNode.java @@ -3,6 +3,7 @@ import org.drools.base.base.ObjectType; import org.drools.base.common.RuleBasePartitionId; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.base.rule.Pattern; import org.drools.core.common.BaseNode; import org.drools.core.common.InternalFactHandle; @@ -40,8 +41,8 @@ public abstract class RightInputAdapterNode extends BaseNod protected BitMask declaredMask = EmptyBitMask.get(); protected BitMask inferredMask = EmptyBitMask.get(); private ObjectSinkNode nextObjectSinkNode; - private BitMask negativeMask = EmptyBitMask.get(); - private ObjectTypeNodeId inputOtnId = ObjectTypeNodeId.DEFAULT_ID; + private BitMask negativeMask = EmptyBitMask.get(); + private ObjectTypeNodeId inputOtnId = ObjectTypeNodeId.DEFAULT_ID; private ObjectSource source; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/RightTuple.java b/drools-core/src/main/java/org/drools/core/reteoo/RightTuple.java index 4f43608398c..cbe8bdae813 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/RightTuple.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/RightTuple.java @@ -19,6 +19,8 @@ package org.drools.core.reteoo; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; +import org.drools.base.reteoo.Sink; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/RightTupleSink.java b/drools-core/src/main/java/org/drools/core/reteoo/RightTupleSink.java index 6f4ad29f117..d286f0a26a6 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/RightTupleSink.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/RightTupleSink.java @@ -18,6 +18,8 @@ */ package org.drools.core.reteoo; +import org.drools.base.reteoo.ObjectTypeNodeId; +import org.drools.base.reteoo.Sink; import org.drools.core.common.PropagationContext; import org.drools.core.common.ReteEvaluator; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNode.java b/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNode.java index 52ddbcbee1a..e5daca2154a 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNode.java @@ -24,6 +24,7 @@ import org.drools.base.base.SalienceInteger; import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.base.rule.Declaration; import org.drools.base.rule.GroupElement; import org.drools.core.common.ReteEvaluator; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNodeLeftTuple.java b/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNodeLeftTuple.java index b02f2afe6db..b06b26a4136 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNodeLeftTuple.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNodeLeftTuple.java @@ -25,6 +25,7 @@ import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.Sink; import org.drools.base.rule.Declaration; import org.drools.base.rule.consequence.Consequence; import org.drools.core.common.ActivationGroupNode; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/RuntimeComponentFactory.java b/drools-core/src/main/java/org/drools/core/reteoo/RuntimeComponentFactory.java index 638e2034775..834e58626c9 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/RuntimeComponentFactory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/RuntimeComponentFactory.java @@ -33,7 +33,7 @@ import org.drools.core.marshalling.SerializablePlaceholderResolverStrategy; import org.drools.core.rule.accessor.FactHandleFactory; import org.drools.core.rule.consequence.KnowledgeHelper; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.kie.api.internal.utils.KieService; import org.kie.api.marshalling.ObjectMarshallingStrategy; import org.kie.api.marshalling.ObjectMarshallingStrategyAcceptor; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java b/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java index b2d4b344baa..6c2961f0951 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java @@ -37,8 +37,8 @@ import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; import org.drools.core.reteoo.TupleToObjectNode.SubnetworkPathMemory; import org.drools.core.reteoo.TimerNode.TimerNodeMemory; -import org.drools.core.util.LinkedList; -import org.drools.core.util.DoubleLinkedEntry; +import org.drools.base.util.LinkedList; +import org.drools.base.util.DoubleLinkedEntry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/SequenceNode.java b/drools-core/src/main/java/org/drools/core/reteoo/SequenceNode.java index f18722143d0..f4632932b69 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/SequenceNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/SequenceNode.java @@ -18,7 +18,11 @@ import org.drools.base.base.ObjectType; import org.drools.base.common.RuleBasePartitionId; +import org.drools.base.reteoo.DynamicFilter; +import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; +import org.drools.base.rule.Pattern; import org.drools.core.RuleBaseConfiguration; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.InternalWorkingMemory; @@ -30,11 +34,11 @@ import org.drools.core.common.UpdateContext; import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.core.reteoo.sequencing.SequencerMemoryImpl; -import org.drools.core.reteoo.sequencing.SequencerMemory; -import org.drools.core.util.AbstractLinkedListNode; -import org.drools.core.util.LinkedList; +import org.drools.base.reteoo.sequencing.SequencerMemory; +import org.drools.base.util.AbstractLinkedListNode; +import org.drools.base.util.LinkedList; import org.drools.core.util.index.TupleList; import org.drools.util.bitmask.BitMask; @@ -46,6 +50,7 @@ public class SequenceNode extends LeftTupleSource implements + LeftTupleNode, LeftTupleSinkNode, MemoryFactory { @@ -57,7 +62,7 @@ public class SequenceNode extends LeftTupleSource private AlphaAdapter[] alphaAdapters; - private DynamicFilterProto[] dynamicFilters; + private DynamicFilterProto[] dynamicFilters; private LeftTupleSinkNode previousTupleSinkNode; @@ -112,7 +117,7 @@ public void networkUpdated(UpdateContext updateContext) { * @return The debug string. */ public String toString() { - return "[MultiInputNode(" + this.id + ")]]"; + return "[SequenceNode(" + this.id + ")]]"; } private int calculateHashCode() { @@ -413,7 +418,7 @@ public void setPreviousObjectSinkNode(ObjectSinkNode previous) { } @Override - public BitMask calculateDeclaredMask(ObjectType modifiedType, List settableProperties) { + public BitMask calculateDeclaredMask(Pattern pattern, ObjectType modifiedType, List settableProperties) { return null; } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/SubnetworkTuple.java b/drools-core/src/main/java/org/drools/core/reteoo/SubnetworkTuple.java index 5f8e3b09622..cf2f30d0a44 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/SubnetworkTuple.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/SubnetworkTuple.java @@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger; +import org.drools.base.reteoo.Sink; import org.drools.core.common.DefaultFactHandle; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/TerminalNode.java b/drools-core/src/main/java/org/drools/core/reteoo/TerminalNode.java index 542d039527f..4537de557e5 100755 --- a/drools-core/src/main/java/org/drools/core/reteoo/TerminalNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/TerminalNode.java @@ -22,13 +22,14 @@ import org.drools.base.common.NetworkNode; import org.drools.base.reteoo.BaseTerminalNode; +import org.drools.base.reteoo.Sink; /** * A markup interface for terminal nodes */ public interface TerminalNode extends - BaseTerminalNode, NetworkNode, Sink, PathEndNode { + BaseTerminalNode, NetworkNode, Sink, PathEndNode { LeftTupleSource getLeftTupleSource(); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java b/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java index 0c71a06c80f..84d7b5e110c 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java @@ -31,7 +31,7 @@ import org.drools.core.common.ReteEvaluator; import org.drools.core.common.UpdateContext; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.drools.core.util.index.TupleList; public class TimerNode extends LeftTupleSource diff --git a/drools-core/src/main/java/org/drools/core/reteoo/Tuple.java b/drools-core/src/main/java/org/drools/core/reteoo/Tuple.java index a48cd011335..95fac89c543 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/Tuple.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/Tuple.java @@ -20,11 +20,12 @@ import java.io.Serializable; -import org.drools.base.common.NetworkNode; import org.drools.base.reteoo.BaseTuple; +import org.drools.base.reteoo.ObjectTypeNodeId; +import org.drools.base.reteoo.Sink; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; -import org.drools.core.util.DoubleLinkedEntry; +import org.drools.base.util.DoubleLinkedEntry; import org.drools.core.util.index.TupleList; import org.kie.api.runtime.rule.FactHandle; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java b/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java index b544443bd44..70de8a0de08 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/TupleFactory.java @@ -19,6 +19,7 @@ package org.drools.core.reteoo; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.Sink; import org.drools.core.common.InternalFactHandle; import org.drools.core.common.PropagationContext; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/TupleImpl.java b/drools-core/src/main/java/org/drools/core/reteoo/TupleImpl.java index fea2b07301d..df728234f03 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/TupleImpl.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/TupleImpl.java @@ -18,6 +18,8 @@ */ package org.drools.core.reteoo; +import org.drools.base.reteoo.ObjectTypeNodeId; +import org.drools.base.reteoo.Sink; import org.drools.base.rule.Declaration; import org.drools.core.common.DefaultEventHandle; import org.drools.core.common.InternalFactHandle; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/TupleMemory.java b/drools-core/src/main/java/org/drools/core/reteoo/TupleMemory.java index 9b6135dd375..0111f5494b1 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/TupleMemory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/TupleMemory.java @@ -19,7 +19,7 @@ package org.drools.core.reteoo; import org.drools.core.util.AbstractHashTable.Index; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; public interface TupleMemory { diff --git a/drools-core/src/main/java/org/drools/core/reteoo/TupleToObjectNode.java b/drools-core/src/main/java/org/drools/core/reteoo/TupleToObjectNode.java index 6712dc63bd0..5215cd0ca12 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/TupleToObjectNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/TupleToObjectNode.java @@ -27,6 +27,7 @@ import org.drools.base.common.NetworkNode; import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.base.rule.Pattern; import org.drools.core.RuleBaseConfiguration; import org.drools.core.common.ActivationsManager; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/WindowNode.java b/drools-core/src/main/java/org/drools/core/reteoo/WindowNode.java index d3f54b76df5..ccabc0c1a50 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/WindowNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/WindowNode.java @@ -25,6 +25,7 @@ import org.drools.base.base.ObjectType; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.base.rule.EntryPointId; import org.drools.base.rule.Pattern; import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java index 26c4e2a3d84..b5bac2415ce 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/NodeFactory.java @@ -24,6 +24,7 @@ import org.drools.base.base.ObjectType; import org.drools.base.common.RuleBasePartitionId; import org.drools.base.definitions.rule.impl.RuleImpl; +import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.rule.Accumulate; import org.drools.base.rule.AsyncReceive; import org.drools.base.rule.AsyncSend; @@ -55,6 +56,7 @@ import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.QueryElementNode; import org.drools.core.reteoo.ReactiveFromNode; +import org.drools.core.reteoo.SequenceNode; import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.TerminalNode; import org.drools.core.reteoo.TimerNode; @@ -96,6 +98,11 @@ EvalConditionNode buildEvalNode( int id, BuildContext context); + SequenceNode buildSequenceNode(int id, + LeftTupleSource tupleSource, + Sequence seq, + BuildContext context); + TupleToObjectNode buildRightInputNode(int id, LeftTupleSource leftInput, LeftTupleSource startTupleSource, diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java index b21305f2b40..4197b1d22c6 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java @@ -20,11 +20,19 @@ import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import org.drools.base.base.ClassObjectType; import org.drools.base.base.ObjectType; import org.drools.base.common.RuleBasePartitionId; import org.drools.base.definitions.rule.impl.RuleImpl; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.rule.Accumulate; import org.drools.base.rule.AsyncReceive; import org.drools.base.rule.AsyncSend; @@ -33,6 +41,7 @@ import org.drools.base.rule.EvalCondition; import org.drools.base.rule.From; import org.drools.base.rule.GroupElement; +import org.drools.base.rule.Pattern; import org.drools.base.rule.QueryElement; import org.drools.base.rule.accessor.DataProvider; import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; @@ -46,6 +55,7 @@ import org.drools.core.reteoo.AsyncSendNode; import org.drools.core.reteoo.ConditionalBranchEvaluator; import org.drools.core.reteoo.ConditionalBranchNode; +import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.EvalConditionNode; import org.drools.core.reteoo.ExistsNode; @@ -62,6 +72,8 @@ import org.drools.core.reteoo.QueryElementNode; import org.drools.core.reteoo.QueryTerminalNode; import org.drools.core.reteoo.ReactiveFromNode; +import org.drools.core.reteoo.SequenceNode; +import org.drools.core.reteoo.SequenceNode.AlphaAdapter; import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.RuleTerminalNode; import org.drools.core.reteoo.TerminalNode; @@ -105,6 +117,55 @@ public EvalConditionNode buildEvalNode(final int id, return new EvalConditionNode( id, tupleSource, eval, context ); } + public SequenceNode buildSequenceNode(final int id, + final LeftTupleSource tupleSource, + final Sequence seq, + final BuildContext context) { + SequenceNode node = new SequenceNode(id, tupleSource, context); + node.setSequencer(new Sequencer(seq)); + + NodeFactory nFactory = CoreComponentFactory.get().getNodeFactoryService(); + + Pattern[] patterns = seq.getFilters(); + + // first attach the OTN sources in Rete. + Set objectTypeSet = new HashSet<>(); + Arrays.stream(patterns).forEach(p -> objectTypeSet.add(p.getObjectType())); + List objectTypeList = new ArrayList<>(objectTypeSet); + + ObjectSource[] otns = new ObjectSource[objectTypeList.size()]; + EntryPointNode epn = context.getRuleBase().getRete().getEntryPointNode(context.getCurrentEntryPoint()); + for ( int i = 0; i < objectTypeSet.size(); i++ ) { + otns[i] = nFactory.buildObjectTypeNode(context.getNextNodeId(), + epn, + objectTypeList.get(i), + context); + + otns[i].attach(context); + } + + // For each source create an alpha adapter, which will map it to any filters on the stack. + AlphaAdapter[] adapters = new AlphaAdapter[objectTypeList.size()]; + for ( int i = 0; i < objectTypeList.size(); i++ ) { + adapters[i] = new AlphaAdapter(context.getNextNodeId(), otns[i], + context.getPartitionId(), node, i); + + adapters[i].attach(context); + } + node.setAlphaAdapters(adapters); + + + // Create all the dynamic filters, these are added on demand to the stack. + DynamicFilterProto[] filters = new DynamicFilterProto[patterns.length]; + for ( int i = 0; i < patterns.length; i++ ) { + filters[i] = new DynamicFilterProto((AlphaNodeFieldConstraint) patterns[i].getConstraints().get(0), i); + } + + node.setDynamicFilters( filters); + + return node; + } + public TupleToObjectNode buildRightInputNode(int id, LeftTupleSource leftInput, LeftTupleSource splitStart, BuildContext context) { LeftTupleSource startTupleSource = leftInput; diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java index 5bd03f914b8..310bff2b15c 100755 --- a/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/ReteooRuleBuilder.java @@ -25,6 +25,7 @@ import org.drools.base.base.ClassObjectType; import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.base.reteoo.NodeTypeEnums; +import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.rule.Accumulate; import org.drools.base.rule.AsyncReceive; import org.drools.base.rule.AsyncSend; @@ -70,6 +71,8 @@ public ReteooRuleBuilder() { new PatternBuilder() ); this.utils.addBuilder( EvalCondition.class, new EvalBuilder() ); + this.utils.addBuilder( Sequence.class, + new SequenceBuilder() ); this.utils.addBuilder( QueryElement.class, new QueryElementBuilder() ); this.utils.addBuilder( From.class, diff --git a/drools-core/src/main/java/org/drools/core/reteoo/builder/SequenceBuilder.java b/drools-core/src/main/java/org/drools/core/reteoo/builder/SequenceBuilder.java new file mode 100755 index 00000000000..ebbc7263563 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/reteoo/builder/SequenceBuilder.java @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.drools.core.reteoo.builder; + +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.rule.EvalCondition; +import org.drools.base.rule.RuleConditionElement; +import org.drools.core.reteoo.CoreComponentFactory; + +public class SequenceBuilder + implements + ReteooComponentBuilder { + + /** + * @inheritDoc + */ + public void build(final BuildContext context, + final BuildUtils utils, + final RuleConditionElement rce) { + final Sequence seq = (Sequence) rce; + context.pushRuleComponent( rce ); + context.setTupleSource( utils.attachNode( context, + CoreComponentFactory.get() + .getNodeFactoryService().buildSequenceNode(context.getNextNodeId(), + context.getTupleSource(), + seq, + context) ) ); + + context.popRuleComponent(); + } + + /** + * @inheritDoc + */ + public boolean requiresLeftActivation(final BuildUtils utils, + final RuleConditionElement rce) { + return true; + } + +} diff --git a/drools-core/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemoryImpl.java b/drools-core/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemoryImpl.java index b6367947680..4778c861d8f 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemoryImpl.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/sequencing/SequencerMemoryImpl.java @@ -1,20 +1,19 @@ package org.drools.core.reteoo.sequencing; -import org.drools.base.reteoo.BaseTuple; -import org.drools.core.reteoo.DynamicFilter; +import org.drools.base.reteoo.DynamicFilter; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.SequencerMemory; import org.drools.core.reteoo.LeftTuple; -import org.drools.core.reteoo.LeftTupleNode; import org.drools.core.reteoo.LeftTupleSink; -import org.drools.core.reteoo.LeftTupleSinkNode; import org.drools.core.reteoo.SequenceNode; import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; -import org.drools.core.reteoo.SignalAdapter; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.SignalAdapter; import org.drools.core.reteoo.TupleImpl; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.util.CircularArrayList; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.util.CircularArrayList; import org.kie.api.runtime.rule.FactHandle; import java.util.ArrayList; diff --git a/drools-core/src/main/java/org/drools/core/rule/SlidingTimeWindow.java b/drools-core/src/main/java/org/drools/core/rule/SlidingTimeWindow.java index 083785aca0c..0bdda7cab5b 100644 --- a/drools-core/src/main/java/org/drools/core/rule/SlidingTimeWindow.java +++ b/drools-core/src/main/java/org/drools/core/rule/SlidingTimeWindow.java @@ -34,13 +34,13 @@ import org.drools.core.common.ReteEvaluator; import org.drools.core.common.WorkingMemoryAction; import org.drools.core.marshalling.MarshallerReaderContext; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.WindowNode; import org.drools.core.reteoo.WindowNode.WindowMemory; import org.drools.base.time.Job; import org.drools.base.time.JobContext; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.drools.core.time.impl.PointInTimeTrigger; import org.kie.api.runtime.rule.FactHandle; diff --git a/drools-core/src/main/java/org/drools/core/time/EnqueuedSelfRemovalJobContext.java b/drools-core/src/main/java/org/drools/core/time/EnqueuedSelfRemovalJobContext.java index cbc8556704a..0c42a91751d 100644 --- a/drools-core/src/main/java/org/drools/core/time/EnqueuedSelfRemovalJobContext.java +++ b/drools-core/src/main/java/org/drools/core/time/EnqueuedSelfRemovalJobContext.java @@ -22,8 +22,8 @@ import org.drools.base.time.JobContext; import org.drools.core.common.ReteEvaluator; -import org.drools.core.phreak.actions.AbstractPropagationEntry; -import org.drools.core.time.impl.TimerJobInstance; +import org.drools.base.phreak.actions.AbstractPropagationEntry; +import org.drools.base.time.impl.TimerJobInstance; public class EnqueuedSelfRemovalJobContext extends SelfRemovalJobContext { public EnqueuedSelfRemovalJobContext(JobContext jobContext, Map timerInstances) { diff --git a/drools-core/src/main/java/org/drools/core/time/SelfRemovalJobContext.java b/drools-core/src/main/java/org/drools/core/time/SelfRemovalJobContext.java index bccefa0e717..9f607c765a5 100644 --- a/drools-core/src/main/java/org/drools/core/time/SelfRemovalJobContext.java +++ b/drools-core/src/main/java/org/drools/core/time/SelfRemovalJobContext.java @@ -23,7 +23,7 @@ import org.drools.base.base.ValueResolver; import org.drools.base.time.JobContext; import org.drools.base.time.JobHandle; -import org.drools.core.time.impl.TimerJobInstance; +import org.drools.base.time.impl.TimerJobInstance; public class SelfRemovalJobContext implements JobContext { diff --git a/drools-core/src/main/java/org/drools/core/time/impl/AbstractJobHandle.java b/drools-core/src/main/java/org/drools/core/time/impl/AbstractJobHandle.java index c22cc1f7600..cb4e510c053 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/AbstractJobHandle.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/AbstractJobHandle.java @@ -19,8 +19,8 @@ package org.drools.core.time.impl; import org.drools.base.time.JobHandle; -import org.drools.core.util.AbstractLinkedListNode; -import org.drools.core.util.DoubleLinkedEntry; +import org.drools.base.util.AbstractLinkedListNode; +import org.drools.base.util.DoubleLinkedEntry; public abstract class AbstractJobHandle> extends AbstractLinkedListNode implements JobHandle, DoubleLinkedEntry { diff --git a/drools-core/src/main/java/org/drools/core/time/impl/CommandServiceTimerJobFactoryManager.java b/drools-core/src/main/java/org/drools/core/time/impl/CommandServiceTimerJobFactoryManager.java index 6ebe31272e2..1d44abef08a 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/CommandServiceTimerJobFactoryManager.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/CommandServiceTimerJobFactoryManager.java @@ -18,6 +18,7 @@ */ package org.drools.core.time.impl; +import org.drools.base.time.impl.TimerJobFactoryManager; import org.kie.api.runtime.ExecutableRunner; public interface CommandServiceTimerJobFactoryManager extends TimerJobFactoryManager { diff --git a/drools-core/src/main/java/org/drools/core/time/impl/DefaultJobHandle.java b/drools-core/src/main/java/org/drools/core/time/impl/DefaultJobHandle.java index 79e06f90f40..4957a803ed2 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/DefaultJobHandle.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/DefaultJobHandle.java @@ -21,6 +21,7 @@ import java.io.Serializable; import org.drools.base.time.Job; +import org.drools.base.time.impl.TimerJobInstance; /** * A default implementation for the JobHandle interface @@ -33,7 +34,7 @@ public class DefaultJobHandle extends AbstractJobHandle implem private long id; - private TimerJobInstance timerJobInstance; + private TimerJobInstance timerJobInstance; public DefaultJobHandle(long id) { this.id = id; diff --git a/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobFactoryManager.java b/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobFactoryManager.java index 694dd72783a..6f342f9f9bc 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobFactoryManager.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobFactoryManager.java @@ -25,6 +25,9 @@ import org.drools.base.time.Trigger; import org.drools.base.time.Job; import org.drools.base.time.JobContext; +import org.drools.base.time.impl.InternalSchedulerService; +import org.drools.base.time.impl.TimerJobFactoryManager; +import org.drools.base.time.impl.TimerJobInstance; public class DefaultTimerJobFactoryManager implements diff --git a/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobInstance.java b/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobInstance.java index b599fe6668f..db72668fac6 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobInstance.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/DefaultTimerJobInstance.java @@ -26,6 +26,8 @@ import org.drools.base.time.Trigger; import org.drools.base.time.Job; import org.drools.base.time.JobContext; +import org.drools.base.time.impl.InternalSchedulerService; +import org.drools.base.time.impl.TimerJobInstance; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,7 +42,7 @@ public class DefaultTimerJobInstance implements Callable, Comparable> { diff --git a/drools-core/src/main/java/org/drools/core/util/index/TupleIndexHashTable.java b/drools-core/src/main/java/org/drools/core/util/index/TupleIndexHashTable.java index d277c6a3890..4e93d917fcb 100644 --- a/drools-core/src/main/java/org/drools/core/util/index/TupleIndexHashTable.java +++ b/drools-core/src/main/java/org/drools/core/util/index/TupleIndexHashTable.java @@ -25,9 +25,9 @@ import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; import org.drools.core.util.AbstractHashTable; -import org.drools.core.util.FastIterator; -import org.drools.core.util.Iterator; -import org.drools.core.util.LinkedList; +import org.drools.base.util.FastIterator; +import org.drools.base.util.Iterator; +import org.drools.base.util.LinkedList; public class TupleIndexHashTable extends AbstractHashTable implements TupleMemory { diff --git a/drools-core/src/main/java/org/drools/core/util/index/TupleIndexRBTree.java b/drools-core/src/main/java/org/drools/core/util/index/TupleIndexRBTree.java index 5f61a12508c..156d765e963 100644 --- a/drools-core/src/main/java/org/drools/core/util/index/TupleIndexRBTree.java +++ b/drools-core/src/main/java/org/drools/core/util/index/TupleIndexRBTree.java @@ -27,8 +27,8 @@ import org.drools.base.util.index.ConstraintTypeOperator; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; -import org.drools.core.util.FastIterator; -import org.drools.core.util.Iterator; +import org.drools.base.util.FastIterator; +import org.drools.base.util.Iterator; import org.drools.core.util.TupleRBTree; import org.drools.core.util.TupleRBTree.Boundary; import org.drools.core.util.TupleRBTree.Node; diff --git a/drools-core/src/main/java/org/drools/core/util/index/TupleList.java b/drools-core/src/main/java/org/drools/core/util/index/TupleList.java index 75f219fc19e..493ec2fa89e 100644 --- a/drools-core/src/main/java/org/drools/core/util/index/TupleList.java +++ b/drools-core/src/main/java/org/drools/core/util/index/TupleList.java @@ -23,9 +23,9 @@ import org.drools.core.common.InternalFactHandle; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; -import org.drools.core.util.SingleLinkedEntry; -import org.drools.core.util.FastIterator; -import org.drools.core.util.LinkedList; +import org.drools.base.util.SingleLinkedEntry; +import org.drools.base.util.FastIterator; +import org.drools.base.util.LinkedList; public class TupleList extends LinkedList implements TupleMemory, SingleLinkedEntry, Serializable { diff --git a/drools-core/src/main/java/org/drools/core/util/index/TupleListWithContext.java b/drools-core/src/main/java/org/drools/core/util/index/TupleListWithContext.java index 6703c301284..5f995d98708 100644 --- a/drools-core/src/main/java/org/drools/core/util/index/TupleListWithContext.java +++ b/drools-core/src/main/java/org/drools/core/util/index/TupleListWithContext.java @@ -18,14 +18,7 @@ */ package org.drools.core.util.index; -import org.drools.core.common.InternalFactHandle; import org.drools.core.reteoo.TupleImpl; -import org.drools.core.reteoo.TupleMemory; -import org.drools.core.util.FastIterator; -import org.drools.core.util.LinkedList; -import org.drools.core.util.SingleLinkedEntry; - -import java.io.Serializable; public class TupleListWithContext extends TupleList { diff --git a/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java b/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java index 7c121541f1a..a716eb84633 100644 --- a/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java +++ b/drools-core/src/test/java/org/drools/core/time/impl/JDKTimerServiceTest.java @@ -37,10 +37,10 @@ import org.drools.core.common.InternalWorkingMemory; import org.drools.core.common.ReteEvaluator; import org.drools.core.impl.RuleBaseFactory; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.base.time.Job; import org.drools.base.time.JobContext; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-core/src/test/java/org/drools/core/util/LeftTupleRBTreeTest.java b/drools-core/src/test/java/org/drools/core/util/LeftTupleRBTreeTest.java index 0942747f4c9..7ade574c52a 100644 --- a/drools-core/src/test/java/org/drools/core/util/LeftTupleRBTreeTest.java +++ b/drools-core/src/test/java/org/drools/core/util/LeftTupleRBTreeTest.java @@ -20,6 +20,7 @@ import java.util.Random; +import org.drools.base.util.Iterator; import org.drools.core.util.TupleRBTree.Node; import org.junit.Test; @@ -38,9 +39,9 @@ public void testIterator() { tree.insert( key ); } - int i = 0; + int i = 0; Iterator> fastIterator = tree.iterator(); - int lastKey = Integer.MIN_VALUE; + int lastKey = Integer.MIN_VALUE; for (Node node = fastIterator.next(); node != null; node = fastIterator.next()) { int currentKey = node.key; if (currentKey < lastKey) { diff --git a/drools-core/src/test/java/org/drools/core/util/LinkedListTest.java b/drools-core/src/test/java/org/drools/core/util/LinkedListTest.java index 9025cd40c5c..7ffdb632f1a 100644 --- a/drools-core/src/test/java/org/drools/core/util/LinkedListTest.java +++ b/drools-core/src/test/java/org/drools/core/util/LinkedListTest.java @@ -18,6 +18,9 @@ */ package org.drools.core.util; +import org.drools.base.util.AbstractLinkedListNode; +import org.drools.base.util.DoubleLinkedEntry; +import org.drools.base.util.LinkedList; import org.junit.Before; import org.junit.Test; diff --git a/drools-fastutil/src/main/java/org/drools/fastutil/FastUtilHashTupleMemory.java b/drools-fastutil/src/main/java/org/drools/fastutil/FastUtilHashTupleMemory.java index 9197f0139de..d6f06aef33d 100644 --- a/drools-fastutil/src/main/java/org/drools/fastutil/FastUtilHashTupleMemory.java +++ b/drools-fastutil/src/main/java/org/drools/fastutil/FastUtilHashTupleMemory.java @@ -25,9 +25,9 @@ import org.drools.core.reteoo.TupleMemory; import org.drools.core.util.AbstractHashTable.HashEntry; import org.drools.core.util.AbstractHashTable.Index; -import org.drools.core.util.FastIterator; -import org.drools.core.util.Iterator; -import org.drools.core.util.LinkedList; +import org.drools.base.util.FastIterator; +import org.drools.base.util.Iterator; +import org.drools.base.util.LinkedList; import org.drools.core.util.index.TupleList; public class FastUtilHashTupleMemory implements TupleMemory { diff --git a/drools-fastutil/src/main/java/org/drools/fastutil/FastUtilTreeMemory.java b/drools-fastutil/src/main/java/org/drools/fastutil/FastUtilTreeMemory.java index 1f26eaf0859..e1850fd78d6 100644 --- a/drools-fastutil/src/main/java/org/drools/fastutil/FastUtilTreeMemory.java +++ b/drools-fastutil/src/main/java/org/drools/fastutil/FastUtilTreeMemory.java @@ -19,16 +19,14 @@ package org.drools.fastutil; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; -import it.unimi.dsi.fastutil.objects.Object2ObjectMaps; import it.unimi.dsi.fastutil.objects.Object2ObjectRBTreeMap; import it.unimi.dsi.fastutil.objects.ObjectBidirectionalIterator; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.Tuple; import org.drools.core.reteoo.TupleMemory; import it.unimi.dsi.fastutil.objects.ObjectIterator; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import org.drools.base.util.IndexedValueReader; -import org.drools.core.util.Iterator; import org.drools.core.util.index.AbstractTupleIndexTree; import org.drools.base.util.index.ConstraintTypeOperator; import org.drools.core.util.index.TupleIndexRBTree; diff --git a/drools-fastutil/src/test/java/org/drools/fastutil/FastUtilTreeMemoryTest.java b/drools-fastutil/src/test/java/org/drools/fastutil/FastUtilTreeMemoryTest.java index bd42b7a9e69..5971fbc47c2 100644 --- a/drools-fastutil/src/test/java/org/drools/fastutil/FastUtilTreeMemoryTest.java +++ b/drools-fastutil/src/test/java/org/drools/fastutil/FastUtilTreeMemoryTest.java @@ -27,10 +27,9 @@ import org.drools.base.reteoo.BaseTuple; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.LeftTuple; -import org.drools.core.reteoo.Tuple; import org.drools.base.rule.accessor.ReadAccessor; import org.drools.base.rule.accessor.TupleValueExtractor; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import org.drools.base.util.IndexedValueReader; import org.drools.fastutil.FastUtilTreeMemory.TreeFastIterator; import org.drools.base.util.index.ConstraintTypeOperator; diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/agenda/CompositeDefaultAgenda.java b/drools-kiesession/src/main/java/org/drools/kiesession/agenda/CompositeDefaultAgenda.java index be94289414a..310d173f6ae 100644 --- a/drools-kiesession/src/main/java/org/drools/kiesession/agenda/CompositeDefaultAgenda.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/agenda/CompositeDefaultAgenda.java @@ -32,7 +32,7 @@ import org.drools.core.event.AgendaEventSupport; import org.drools.core.impl.InternalRuleBase; import org.drools.core.phreak.ExecutableEntry; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.phreak.PropagationList; import org.drools.core.phreak.RuleAgendaItem; import org.drools.core.reteoo.PathMemory; diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/agenda/DefaultAgenda.java b/drools-kiesession/src/main/java/org/drools/kiesession/agenda/DefaultAgenda.java index fea92b0b359..40b39c2d358 100644 --- a/drools-kiesession/src/main/java/org/drools/kiesession/agenda/DefaultAgenda.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/agenda/DefaultAgenda.java @@ -27,6 +27,7 @@ import org.drools.base.definitions.rule.impl.QueryImpl; import org.drools.base.definitions.rule.impl.RuleImpl; +import org.drools.base.util.LinkedList; import org.drools.core.RuleBaseConfiguration; import org.drools.core.common.ActivationGroupImpl; import org.drools.core.common.ActivationGroupNode; @@ -49,18 +50,17 @@ import org.drools.core.event.AgendaEventSupport; import org.drools.core.impl.InternalRuleBase; import org.drools.core.phreak.ExecutableEntry; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.phreak.PropagationList; import org.drools.core.phreak.RuleAgendaItem; import org.drools.core.phreak.RuleExecutor; import org.drools.core.phreak.SynchronizedBypassPropagationList; import org.drools.core.phreak.SynchronizedPropagationList; import org.drools.core.phreak.ThreadUnsafePropagationList; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.AgendaComponentFactory; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.PathMemory; -import org.drools.core.reteoo.Rete; import org.drools.core.reteoo.RuleTerminalNodeLeftTuple; import org.drools.core.reteoo.TerminalNode; import org.drools.core.rule.consequence.ConsequenceExceptionHandler; @@ -100,7 +100,7 @@ public class DefaultAgenda implements InternalAgenda { private final Map activationGroups; - private final org.drools.core.util.LinkedList eager = new org.drools.core.util.LinkedList<>(); + private final LinkedList eager = new LinkedList<>(); private final Map queries = new ConcurrentHashMap<>(); diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/consequence/StatefulKnowledgeSessionForRHS.java b/drools-kiesession/src/main/java/org/drools/kiesession/consequence/StatefulKnowledgeSessionForRHS.java index 18fdf662a9d..222d92f2200 100644 --- a/drools-kiesession/src/main/java/org/drools/kiesession/consequence/StatefulKnowledgeSessionForRHS.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/consequence/StatefulKnowledgeSessionForRHS.java @@ -44,13 +44,13 @@ import org.drools.core.event.AgendaEventSupport; import org.drools.core.event.RuleEventListenerSupport; import org.drools.core.event.RuleRuntimeEventSupport; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.TerminalNode; import org.drools.core.rule.accessor.FactHandleFactory; import org.drools.core.rule.consequence.InternalMatch; import org.drools.core.runtime.process.InternalProcessRuntime; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.drools.util.bitmask.BitMask; import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/debug/AccumulateNodeVisitor.java b/drools-kiesession/src/main/java/org/drools/kiesession/debug/AccumulateNodeVisitor.java index a064377db23..4612b8e6960 100755 --- a/drools-kiesession/src/main/java/org/drools/kiesession/debug/AccumulateNodeVisitor.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/debug/AccumulateNodeVisitor.java @@ -24,7 +24,7 @@ import org.drools.core.reteoo.AccumulateNode.AccumulateMemory; import org.drools.core.reteoo.BetaNode; import org.drools.core.reteoo.Tuple; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import java.util.Collection; diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/debug/FromNodeVisitor.java b/drools-kiesession/src/main/java/org/drools/kiesession/debug/FromNodeVisitor.java index a39a5c390a5..75cfb2c066c 100755 --- a/drools-kiesession/src/main/java/org/drools/kiesession/debug/FromNodeVisitor.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/debug/FromNodeVisitor.java @@ -21,9 +21,8 @@ import org.drools.base.common.NetworkNode; import org.drools.core.reteoo.FromNode; import org.drools.core.reteoo.FromNode.FromMemory; -import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.TupleImpl; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import java.util.Collection; diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/factory/RuntimeComponentFactoryImpl.java b/drools-kiesession/src/main/java/org/drools/kiesession/factory/RuntimeComponentFactoryImpl.java index c428b85d8a5..d84246a2b62 100644 --- a/drools-kiesession/src/main/java/org/drools/kiesession/factory/RuntimeComponentFactoryImpl.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/factory/RuntimeComponentFactoryImpl.java @@ -37,7 +37,7 @@ import org.drools.core.rule.accessor.FactHandleFactory; import org.drools.base.rule.accessor.GlobalResolver; import org.drools.core.rule.consequence.KnowledgeHelper; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.drools.kiesession.agenda.DefaultAgendaFactory; import org.drools.kiesession.entrypoints.NamedEntryPointFactory; import org.drools.kiesession.management.KieSessionMonitoringImpl; diff --git a/drools-kiesession/src/main/java/org/drools/kiesession/session/StatefulKnowledgeSessionImpl.java b/drools-kiesession/src/main/java/org/drools/kiesession/session/StatefulKnowledgeSessionImpl.java index f5915866102..4f1e3caee4c 100644 --- a/drools-kiesession/src/main/java/org/drools/kiesession/session/StatefulKnowledgeSessionImpl.java +++ b/drools-kiesession/src/main/java/org/drools/kiesession/session/StatefulKnowledgeSessionImpl.java @@ -63,11 +63,11 @@ import org.drools.core.impl.EnvironmentFactory; import org.drools.core.management.DroolsManagementAgent; import org.drools.core.marshalling.MarshallerReaderContext; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.phreak.actions.ExecuteQuery; import org.drools.core.phreak.actions.PropagationEntryWithResult; import org.drools.core.phreak.RuleAgendaItem; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.AsyncReceiveNode; import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.LeftInputAdapterNode; @@ -83,7 +83,7 @@ import org.drools.core.runtime.process.InternalProcessRuntime; import org.drools.core.runtime.rule.impl.LiveQueryImpl; import org.drools.core.runtime.rule.impl.OpenQueryViewChangedEventListenerAdapter; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.drools.util.bitmask.BitMask; import org.drools.kiesession.entrypoints.NamedEntryPointsManager; import org.drools.kiesession.rulebase.InternalKnowledgeBase; diff --git a/drools-kiesession/src/test/java/org/drools/kiesession/MockInternalMatch.java b/drools-kiesession/src/test/java/org/drools/kiesession/MockInternalMatch.java index ddbe92dd39e..71aaef635ba 100644 --- a/drools-kiesession/src/test/java/org/drools/kiesession/MockInternalMatch.java +++ b/drools-kiesession/src/test/java/org/drools/kiesession/MockInternalMatch.java @@ -29,12 +29,11 @@ import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.core.phreak.RuleAgendaItem; import org.drools.core.reteoo.TerminalNode; -import org.drools.core.reteoo.Tuple; import org.drools.core.reteoo.TupleImpl; import org.drools.core.rule.consequence.InternalMatch; import org.drools.base.rule.consequence.Consequence; import org.drools.core.common.PropagationContext; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; import org.kie.api.runtime.rule.FactHandle; public class MockInternalMatch implements InternalMatch { diff --git a/drools-kiesession/src/test/java/org/drools/kiesession/ReteooWorkingMemoryTest.java b/drools-kiesession/src/test/java/org/drools/kiesession/ReteooWorkingMemoryTest.java index 04b0d69228d..0aa90a7e42a 100644 --- a/drools-kiesession/src/test/java/org/drools/kiesession/ReteooWorkingMemoryTest.java +++ b/drools-kiesession/src/test/java/org/drools/kiesession/ReteooWorkingMemoryTest.java @@ -30,7 +30,7 @@ import org.drools.core.common.TruthMaintenanceSystem; import org.drools.core.common.TruthMaintenanceSystemFactory; import org.drools.core.common.WorkingMemoryAction; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.Rete; import org.drools.core.reteoo.builder.NodeFactory; diff --git a/drools-metric/src/main/java/org/drools/metric/phreak/PhreakQueryTerminalNodeMetric.java b/drools-metric/src/main/java/org/drools/metric/phreak/PhreakQueryTerminalNodeMetric.java index 860730b92b1..e35decc3265 100644 --- a/drools-metric/src/main/java/org/drools/metric/phreak/PhreakQueryTerminalNodeMetric.java +++ b/drools-metric/src/main/java/org/drools/metric/phreak/PhreakQueryTerminalNodeMetric.java @@ -22,9 +22,8 @@ import org.drools.core.common.TupleSets; import org.drools.core.phreak.PhreakQueryTerminalNode; import org.drools.core.phreak.StackEntry; -import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.QueryTerminalNode; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; import org.drools.metric.util.MetricLogUtils; public class PhreakQueryTerminalNodeMetric extends PhreakQueryTerminalNode { diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ReteDumper.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ReteDumper.java index a84b9107034..9286feb3736 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ReteDumper.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ReteDumper.java @@ -31,7 +31,7 @@ import org.drools.core.reteoo.ObjectSource; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.Rete; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import org.kie.api.KieBase; import org.kie.api.runtime.KieSession; diff --git a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/PersistableRunner.java b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/PersistableRunner.java index 0e39c934786..0e492c88bfb 100644 --- a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/PersistableRunner.java +++ b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/PersistableRunner.java @@ -35,7 +35,7 @@ import org.drools.core.common.InternalWorkingMemory; import org.drools.core.runtime.process.InternalProcessRuntime; import org.drools.core.time.impl.CommandServiceTimerJobFactoryManager; -import org.drools.core.time.impl.TimerJobFactoryManager; +import org.drools.base.time.impl.TimerJobFactoryManager; import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.drools.persistence.api.OrderedTransactionSynchronization; diff --git a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java index 466fdde0dd8..82d71360ab2 100644 --- a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java +++ b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java @@ -23,7 +23,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; -import org.drools.core.time.impl.InternalSchedulerService; +import org.drools.base.time.impl.InternalSchedulerService; import org.drools.base.time.Job; import org.drools.base.time.JobContext; import org.drools.core.time.SelfRemovalJob; @@ -31,7 +31,7 @@ import org.drools.base.time.Trigger; import org.drools.core.time.impl.DefaultTimerJobInstance; import org.drools.core.time.impl.JDKTimerService; -import org.drools.core.time.impl.TimerJobInstance; +import org.drools.base.time.impl.TimerJobInstance; import org.kie.api.command.ExecutableCommand; import org.kie.api.runtime.Context; import org.kie.api.runtime.ExecutableRunner; diff --git a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java index 0e5ffddba7a..9f0efa62757 100644 --- a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java +++ b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java @@ -19,7 +19,7 @@ package org.drools.persistence.jpa; import org.kie.api.runtime.ExecutableRunner; -import org.drools.core.time.impl.InternalSchedulerService; +import org.drools.base.time.impl.InternalSchedulerService; import org.drools.base.time.Job; import org.drools.base.time.JobContext; import org.drools.base.time.JobHandle; @@ -27,7 +27,7 @@ import org.drools.base.time.Trigger; import org.drools.core.time.impl.CommandServiceTimerJobFactoryManager; import org.drools.core.time.impl.ThreadSafeTrackableTimeJobFactoryManager; -import org.drools.core.time.impl.TimerJobInstance; +import org.drools.base.time.impl.TimerJobInstance; public class JpaTimeJobFactoryManager extends ThreadSafeTrackableTimeJobFactoryManager diff --git a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java index 968c92220a2..92a9bf5ddeb 100644 --- a/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java +++ b/drools-persistence/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java @@ -19,11 +19,11 @@ package org.drools.persistence.jpa; import org.kie.api.runtime.ExecutableRunner; -import org.drools.core.time.impl.InternalSchedulerService; +import org.drools.base.time.impl.InternalSchedulerService; import org.drools.base.time.Job; import org.drools.base.time.JobContext; import org.drools.base.time.JobHandle; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.drools.base.time.Trigger; import org.drools.core.time.impl.CommandServiceTimerJobFactoryManager; import org.drools.core.time.impl.DefaultTimerJobInstance; diff --git a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliablePropagationList.java b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliablePropagationList.java index 85fb52a0d60..7c14f33838e 100644 --- a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliablePropagationList.java +++ b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliablePropagationList.java @@ -20,7 +20,7 @@ import org.drools.core.common.ReteEvaluator; import org.drools.core.common.Storage; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.phreak.SynchronizedPropagationList; import java.io.Externalizable; diff --git a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliablePseudoClockScheduler.java b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliablePseudoClockScheduler.java index 8f6c964c0c3..241b465c21a 100644 --- a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliablePseudoClockScheduler.java +++ b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliablePseudoClockScheduler.java @@ -29,7 +29,7 @@ import org.drools.core.phreak.PhreakTimerNode.TimerNodeJob; import org.drools.core.reteoo.ObjectTypeNode.ExpireJob; import org.drools.core.time.impl.PseudoClockScheduler; -import org.drools.core.time.impl.TimerJobInstance; +import org.drools.base.time.impl.TimerJobInstance; public class ReliablePseudoClockScheduler extends PseudoClockScheduler { diff --git a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableRuntimeComponentFactoryImpl.java b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableRuntimeComponentFactoryImpl.java index 58be3e8d163..e8c6c6e3eaf 100644 --- a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableRuntimeComponentFactoryImpl.java +++ b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableRuntimeComponentFactoryImpl.java @@ -28,7 +28,7 @@ import org.drools.core.common.InternalWorkingMemory; import org.drools.core.common.ReteEvaluator; import org.drools.core.common.Storage; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.drools.kiesession.factory.RuntimeComponentFactoryImpl; import org.drools.kiesession.factory.WorkingMemoryFactory; import org.drools.kiesession.rulebase.InternalKnowledgeBase; diff --git a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableSessionInitializer.java b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableSessionInitializer.java index 010a21c49dd..33b7b398d2b 100644 --- a/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableSessionInitializer.java +++ b/drools-reliability/drools-reliability-core/src/main/java/org/drools/reliability/core/ReliableSessionInitializer.java @@ -28,7 +28,7 @@ import org.drools.core.common.InternalWorkingMemory; import org.drools.core.common.InternalWorkingMemoryEntryPoint; import org.drools.core.common.Storage; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.phreak.actions.Insert; import org.drools.reliability.core.util.ReliabilityUtils; import org.kie.api.event.rule.AfterMatchFiredEvent; diff --git a/drools-retediagram/src/main/java/org/drools/retediagram/ReteDiagram.java b/drools-retediagram/src/main/java/org/drools/retediagram/ReteDiagram.java index 6b69f3a248e..f04f4a34623 100644 --- a/drools-retediagram/src/main/java/org/drools/retediagram/ReteDiagram.java +++ b/drools-retediagram/src/main/java/org/drools/retediagram/ReteDiagram.java @@ -55,7 +55,7 @@ import org.drools.core.reteoo.Rete; import org.drools.core.reteoo.TupleToObjectNode; import org.drools.core.reteoo.RuleTerminalNode; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import org.drools.base.rule.constraint.BetaConstraint; import org.drools.base.base.ObjectType; import org.kie.api.KieBase; diff --git a/drools-ruleunits/drools-ruleunits-impl/src/main/java/org/drools/ruleunits/impl/sessions/RuleUnitExecutorImpl.java b/drools-ruleunits/drools-ruleunits-impl/src/main/java/org/drools/ruleunits/impl/sessions/RuleUnitExecutorImpl.java index daf2e8d0b56..5d969d1a3d8 100644 --- a/drools-ruleunits/drools-ruleunits-impl/src/main/java/org/drools/ruleunits/impl/sessions/RuleUnitExecutorImpl.java +++ b/drools-ruleunits/drools-ruleunits-impl/src/main/java/org/drools/ruleunits/impl/sessions/RuleUnitExecutorImpl.java @@ -52,7 +52,7 @@ import org.drools.core.event.RuleRuntimeEventSupport; import org.drools.core.impl.ActivationsManagerImpl; import org.drools.core.impl.InternalRuleBase; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.phreak.actions.ExecuteQuery; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.RuntimeComponentFactory; @@ -61,7 +61,7 @@ import org.drools.core.rule.accessor.FactHandleFactory; import org.drools.core.rule.consequence.InternalMatch; import org.drools.core.rule.consequence.KnowledgeHelper; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.drools.util.bitmask.BitMask; import org.drools.kiesession.consequence.DefaultKnowledgeHelper; import org.drools.kiesession.consequence.StatefulKnowledgeSessionForRHS; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/ProtobufOutputMarshaller.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/ProtobufOutputMarshaller.java index 37774be1bc0..6b855b0141e 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/ProtobufOutputMarshaller.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/ProtobufOutputMarshaller.java @@ -42,14 +42,14 @@ import org.drools.core.common.TruthMaintenanceSystem; import org.drools.core.common.TruthMaintenanceSystemFactory; import org.drools.core.marshalling.MarshallerWriteContext; -import org.drools.core.phreak.PropagationEntry; +import org.drools.base.phreak.PropagationEntry; import org.drools.core.phreak.RuleAgendaItem; import org.drools.core.process.WorkItem; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.ObjectTypeConf; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import org.drools.core.reteoo.TerminalNode; import org.drools.core.rule.consequence.InternalMatch; import org.drools.base.time.JobContext; @@ -59,10 +59,10 @@ import org.drools.core.time.impl.IntervalTrigger; import org.drools.core.time.impl.PointInTimeTrigger; 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.base.time.impl.TimerJobInstance; +import org.drools.base.util.FastIterator; +import org.drools.base.util.LinkedList; +import org.drools.base.util.LinkedListEntry; import org.drools.kiesession.entrypoints.NamedEntryPoint; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.drools.serialization.protobuf.ProtobufMessages.FactHandle; @@ -297,8 +297,8 @@ private static void writeAgenda( MarshallerWriteContext context, _ab.setFocusStack( _fsb.build() ); // serialize all dormant activations - org.drools.core.util.Iterator it = ActivationIterator.iterator( wm ); - List dormant = new ArrayList<>(); + org.drools.base.util.Iterator it = ActivationIterator.iterator(wm); + List dormant = new ArrayList<>(); for (InternalMatch item = (InternalMatch) it.next(); item != null; item = (InternalMatch) it.next() ) { if ( !item.isQueued() ) { dormant.add( item ); @@ -356,7 +356,7 @@ private static ByteString serializeObject( MarshallerWriteContext context, Objec private static ProtobufMessages.NodeMemory writeQueryElementNodeMemory(final int nodeId, final Memory memory, final InternalWorkingMemory wm) { - org.drools.core.util.Iterator it = LeftTupleIterator.iterator(wm, ((QueryElementNodeMemory) memory).getNode() ); + org.drools.base.util.Iterator it = LeftTupleIterator.iterator(wm, ((QueryElementNodeMemory) memory).getNode()); ProtobufMessages.NodeMemory.QueryElementNodeMemory.Builder _query = ProtobufMessages.NodeMemory.QueryElementNodeMemory.newBuilder(); for ( TupleImpl leftTuple = it.next(); leftTuple != null; leftTuple = it.next() ) { @@ -681,7 +681,7 @@ public static > ProtobufMessages.Activation writeAct } if (internalMatch instanceof TruthMaintenanceSystemInternalMatch) { - org.drools.core.util.LinkedList> list = ((TruthMaintenanceSystemInternalMatch) internalMatch).getLogicalDependencies(); + LinkedList> list = ((TruthMaintenanceSystemInternalMatch) internalMatch).getLogicalDependencies(); if (list != null && !list.isEmpty()) { for (LogicalDependency node = list.getFirst(); node != null; node = node.getNext()) { _activation.addLogicalDependency(((BeliefSet) node.getJustified()).getFactHandle().getId()); diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/WorkingMemoryReteAssertAction.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/WorkingMemoryReteAssertAction.java index 59a513b27c5..2feab45f749 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/WorkingMemoryReteAssertAction.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/WorkingMemoryReteAssertAction.java @@ -27,7 +27,7 @@ import org.drools.base.definitions.InternalKnowledgePackage; import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.core.marshalling.MarshallerReaderContext; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.RuntimeComponentFactory; import org.drools.core.common.PropagationContext; import org.drools.core.reteoo.TerminalNode; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/ActivationIterator.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/ActivationIterator.java index 7d565554c9e..61a9045b2bc 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/ActivationIterator.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/ActivationIterator.java @@ -21,13 +21,12 @@ import org.drools.core.WorkingMemoryEntryPoint; import org.drools.core.common.InternalWorkingMemory; import org.drools.core.common.ReteEvaluator; -import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.RuleTerminalNode; import org.drools.core.reteoo.TerminalNode; import org.drools.core.reteoo.TupleImpl; import org.drools.core.rule.consequence.InternalMatch; import org.drools.core.reteoo.Tuple; -import org.drools.core.util.Iterator; +import org.drools.base.util.Iterator; import org.kie.api.KieBase; import org.kie.api.runtime.KieSession; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/LeftTupleIterator.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/LeftTupleIterator.java index e865089074c..55885e270f6 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/LeftTupleIterator.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/LeftTupleIterator.java @@ -37,14 +37,13 @@ import org.drools.core.reteoo.LeftTupleSource; import org.drools.base.reteoo.NodeTypeEnums; import org.drools.core.reteoo.NotNode; -import org.drools.core.reteoo.ObjectSource; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.QueryElementNode; import org.drools.core.reteoo.RightTuple; import org.drools.core.reteoo.Tuple; import org.drools.core.reteoo.TupleImpl; -import org.drools.core.util.FastIterator; -import org.drools.core.util.Iterator; +import org.drools.base.util.FastIterator; +import org.drools.base.util.Iterator; public class LeftTupleIterator implements diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/PhreakActivationIterator.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/PhreakActivationIterator.java index 198207dabd6..dd552c736d4 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/PhreakActivationIterator.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/PhreakActivationIterator.java @@ -22,17 +22,13 @@ import java.util.List; import org.drools.base.reteoo.NodeTypeEnums; -import org.drools.core.common.BaseNode; -import org.drools.core.common.InternalFactHandle; -import org.drools.core.common.InternalWorkingMemory; -import org.drools.core.common.Memory; import org.drools.core.common.ReteEvaluator; import org.drools.core.impl.InternalRuleBase; import org.drools.core.phreak.RuleExecutor; import org.drools.core.reteoo.PathMemory; import org.drools.core.reteoo.TerminalNode; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.util.Iterator; +import org.drools.base.util.Iterator; public class PhreakActivationIterator implements Iterator { diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/TerminalNodeIterator.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/TerminalNodeIterator.java index 9b8866fe6a5..eecd2fd8cfb 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/TerminalNodeIterator.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/iterators/TerminalNodeIterator.java @@ -22,7 +22,7 @@ import org.drools.core.impl.InternalRuleBase; import org.drools.core.reteoo.TerminalNode; -import org.drools.core.util.Iterator; +import org.drools.base.util.Iterator; import org.kie.api.KieBase; public class TerminalNodeIterator implements Iterator { diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/marshalling/RightTupleKey.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/marshalling/RightTupleKey.java index 42e99d34308..978f7d1232e 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/marshalling/RightTupleKey.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/marshalling/RightTupleKey.java @@ -18,7 +18,7 @@ */ package org.drools.serialization.protobuf.marshalling; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; public class RightTupleKey { private final int id; diff --git a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerInputMarshaller.java b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerInputMarshaller.java index 4cd2959a38c..dc8d9b6b177 100644 --- a/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerInputMarshaller.java +++ b/drools-serialization-protobuf/src/main/java/org/drools/serialization/protobuf/timers/ExpireJobContextTimerInputMarshaller.java @@ -26,7 +26,7 @@ import org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext; import org.drools.base.time.JobContext; import org.drools.base.time.JobHandle; -import org.drools.core.time.TimerService; +import org.drools.base.time.TimerService; import org.drools.core.time.impl.DefaultJobHandle; import org.drools.core.time.impl.PointInTimeTrigger; import org.drools.serialization.protobuf.ProtobufMarshallerReaderContext; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/IndexingTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/IndexingTest.java index 5426dc6f9ec..2c090665d33 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/IndexingTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/IndexingTest.java @@ -46,7 +46,7 @@ import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.RightTuple; import org.drools.core.reteoo.TupleMemory; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.drools.testcoverage.common.model.Address; import org.drools.testcoverage.common.model.Cheese; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/operators/NotTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/operators/NotTest.java index 1a49e8738d5..8806e0ad52c 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/operators/NotTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/operators/NotTest.java @@ -34,7 +34,7 @@ import org.drools.core.reteoo.RightTuple; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.drools.testcoverage.common.model.AFact; import org.drools.testcoverage.common.model.Cheese; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/AbstractTupleIndexHashTableIteratorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/AbstractTupleIndexHashTableIteratorTest.java index 4062f3ca681..042a8bca463 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/AbstractTupleIndexHashTableIteratorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/AbstractTupleIndexHashTableIteratorTest.java @@ -29,7 +29,7 @@ import org.drools.base.rule.Pattern; import org.drools.base.rule.accessor.ReadAccessor; import org.drools.base.rule.constraint.BetaConstraint; -import org.drools.core.util.SingleLinkedEntry; +import org.drools.base.util.SingleLinkedEntry; import org.drools.core.util.index.IndexMemory; import org.drools.core.util.index.TupleIndexHashTable; import org.drools.drl.parser.impl.Operator; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/BaseBetaConstraintsTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/BaseBetaConstraintsTest.java index 63ed505e233..2a981493252 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/BaseBetaConstraintsTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/BaseBetaConstraintsTest.java @@ -40,8 +40,8 @@ import org.drools.base.rule.accessor.ReadAccessor; import org.drools.base.util.IndexedValueReader; import org.drools.core.util.AbstractHashTable.Index; -import org.drools.core.util.LinkedList; -import org.drools.core.util.LinkedListEntry; +import org.drools.base.util.LinkedList; +import org.drools.base.util.LinkedListEntry; import org.drools.base.util.index.ConstraintTypeOperator; import org.drools.core.util.index.TupleList; import org.drools.model.functions.Predicate1; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/LeftTupleIndexHashTableIteratorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/LeftTupleIndexHashTableIteratorTest.java index 73ed977990e..b85a1700518 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/LeftTupleIndexHashTableIteratorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/LeftTupleIndexHashTableIteratorTest.java @@ -35,7 +35,7 @@ import org.drools.core.reteoo.MockLeftTupleSink; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import org.drools.core.util.index.TupleIndexHashTable; import org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator; import org.drools.core.util.index.TupleList; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/RightTupleIndexHashTableIteratorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/RightTupleIndexHashTableIteratorTest.java index b333261944a..1423579a585 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/RightTupleIndexHashTableIteratorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/RightTupleIndexHashTableIteratorTest.java @@ -33,7 +33,7 @@ import org.drools.core.reteoo.RightTuple; import org.drools.base.rule.constraint.BetaConstraint; import org.drools.core.reteoo.TupleImpl; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import org.drools.core.util.index.TupleIndexHashTable; import org.drools.core.util.index.TupleIndexHashTable.FieldIndexHashTableFullIterator; import org.drools.core.util.index.TupleList; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/command/PropagationListTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/command/PropagationListTest.java index aaa9cafa8bb..6f3c1491a7c 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/command/PropagationListTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/command/PropagationListTest.java @@ -27,7 +27,7 @@ import org.drools.core.common.ReteEvaluator; import org.drools.core.phreak.PropagationList; import org.drools.core.phreak.SynchronizedPropagationList; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.junit.Ignore; import org.junit.Test; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/common/InternalMatchIteratorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/common/InternalMatchIteratorTest.java index 88d13384662..9a67e35bd3b 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/common/InternalMatchIteratorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/common/InternalMatchIteratorTest.java @@ -27,7 +27,7 @@ import org.drools.core.common.InternalWorkingMemory; import org.drools.core.impl.RuleBaseFactory; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.util.Iterator; +import org.drools.base.util.Iterator; import org.drools.serialization.protobuf.iterators.ActivationIterator; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/common/TerminalNodeIteratorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/common/TerminalNodeIteratorTest.java index e5e40f46871..a3305e7a578 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/common/TerminalNodeIteratorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/common/TerminalNodeIteratorTest.java @@ -23,9 +23,8 @@ import java.util.List; import org.drools.serialization.protobuf.iterators.TerminalNodeIterator; -import org.drools.core.reteoo.RuleTerminalNode; import org.drools.core.reteoo.TerminalNode; -import org.drools.core.util.Iterator; +import org.drools.base.util.Iterator; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestParametersUtil; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/oopath/OOPathReactiveTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/oopath/OOPathReactiveTest.java index 88a3662458e..9e6cf609a1e 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/oopath/OOPathReactiveTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/oopath/OOPathReactiveTest.java @@ -29,11 +29,9 @@ import org.drools.core.reteoo.LeftInputAdapterNode; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.ReactiveFromNode; -import org.drools.core.reteoo.Tuple; import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; -import org.drools.core.util.FastIterator; -import org.drools.core.util.Iterator; +import org.drools.base.util.FastIterator; import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.mvel.compiler.oopath.model.Adult; import org.drools.mvel.compiler.oopath.model.Child; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/reteoo/MockLeftTupleSink.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/reteoo/MockLeftTupleSink.java index b8d7b143797..cf50c6851bc 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/reteoo/MockLeftTupleSink.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/compiler/reteoo/MockLeftTupleSink.java @@ -22,22 +22,16 @@ import java.util.List; import org.drools.core.RuleBaseConfiguration; -import org.drools.core.common.InternalFactHandle; import org.drools.core.common.Memory; import org.drools.core.common.MemoryFactory; import org.drools.core.common.ReteEvaluator; import org.drools.core.common.UpdateContext; -import org.drools.core.reteoo.LeftTuple; -import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.LeftTupleSinkNode; import org.drools.core.reteoo.LeftTupleSource; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.ReteooBuilder; import org.drools.core.reteoo.RuleRemovalContext; -import org.drools.core.reteoo.Sink; -import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.common.PropagationContext; public class MockLeftTupleSink extends LeftTupleSource implements diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/Misc2Test.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/Misc2Test.java index 980e59288cb..33dae725e61 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/Misc2Test.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/Misc2Test.java @@ -19,7 +19,6 @@ package org.drools.mvel.integrationtests; import java.io.Serializable; -import java.io.StringReader; import java.math.BigDecimal; import java.net.URL; import java.net.URLClassLoader; @@ -45,7 +44,6 @@ import org.drools.base.base.ValueResolver; import org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl; -import org.drools.compiler.builder.impl.KnowledgeBuilderImpl; import org.kie.api.runtime.ClassObjectFilter; import org.drools.base.InitialFact; import org.drools.base.base.ClassObjectType; @@ -55,13 +53,11 @@ import org.drools.core.common.InternalWorkingMemory; import org.drools.core.common.Memory; import org.drools.core.common.NodeMemories; -import org.drools.base.definitions.InternalKnowledgePackage; import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.core.impl.InternalRuleBase; -import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.reteoo.LeftInputAdapterNode; import org.drools.core.reteoo.ObjectTypeNode; -import org.drools.core.reteoo.ObjectTypeNodeId; +import org.drools.base.reteoo.ObjectTypeNodeId; import org.drools.core.reteoo.Rete; import org.drools.core.reteoo.SegmentMemory; import org.drools.base.rule.accessor.Salience; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/Scenario.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/Scenario.java index c5c237e7ddc..8d26c3b0cf4 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/Scenario.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/Scenario.java @@ -35,7 +35,7 @@ import org.drools.core.reteoo.TupleImpl; import org.drools.core.reteoo.TupleMemory; import org.drools.core.reteoo.Tuple; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import java.util.ArrayList; import java.util.List; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java index cfd77523bd0..2f633470025 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java @@ -11,11 +11,11 @@ import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.MockLeftTupleSink; import org.drools.core.reteoo.SequenceNode; -import org.drools.core.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.DynamicFilterProto; import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.SequencerMemory; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.SequencerMemory; import org.drools.core.rule.JavaDialectRuntimeData; import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/CircularArrayListTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/CircularArrayListTest.java index ceae52e054c..92aa62c2b4a 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/CircularArrayListTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/CircularArrayListTest.java @@ -1,6 +1,6 @@ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.core.util.CircularArrayList; +import org.drools.base.util.CircularArrayList; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java index 5c0238147a4..81cd629e211 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java @@ -29,7 +29,6 @@ import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.reteoo.EntryPointNode; import org.drools.core.reteoo.LeftTupleSource; -import org.drools.core.reteoo.ObjectRouter; import org.drools.core.reteoo.SequenceNode; import org.drools.core.reteoo.SequenceNode.AlphaAdapter; import org.drools.core.reteoo.ObjectSource; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java index 1bd07d6619a..11086c269e6 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java @@ -24,16 +24,16 @@ import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.core.util.CircularArrayList; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.util.CircularArrayList; import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java index d210008e7c8..3bea1266335 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java @@ -24,18 +24,18 @@ import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.DynamicFilter; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.SignalAdapter; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.core.util.LinkedList; +import org.drools.base.reteoo.DynamicFilter; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.SignalAdapter; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.util.LinkedList; import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java index 31e13a3652c..58d38624c25 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java @@ -24,17 +24,17 @@ import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.LoopController; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.core.util.CircularArrayList; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.LoopController; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.util.CircularArrayList; import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java index b6d6d26d68b..4ee671f5bc3 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java @@ -24,16 +24,16 @@ import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.core.util.CircularArrayList; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.util.CircularArrayList; import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java index e43c6a48c42..27368aa4c40 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java @@ -23,16 +23,16 @@ import org.drools.base.rule.Pattern; import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGateOutputSignalProcessor; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.signalprocessors.SignalIndex; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGateOutputSignalProcessor; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.signalprocessors.SignalIndex; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java index df765d48059..2ac325c48e3 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java @@ -24,16 +24,16 @@ import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.LoopController; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.LoopController; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java index 4a9f60001de..e07e932dfce 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java @@ -23,16 +23,16 @@ import org.drools.base.rule.Pattern; import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.Sequence.TimoutController; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequence.TimoutController; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.core.time.impl.DurationTimer; import org.drools.core.time.impl.PseudoClockScheduler; import org.drools.mvel.integrationtests.phreak.A; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java index e7910d2fd40..6f8ce666420 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java @@ -23,18 +23,18 @@ import org.drools.base.rule.Pattern; import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGateOutputSignalProcessor; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.signalprocessors.SignalIndex; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGateOutputSignalProcessor; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.signalprocessors.SignalIndex; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java index ec1e354020a..48e3d35d92c 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java @@ -23,18 +23,18 @@ import org.drools.base.rule.Pattern; import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate.DelayFromActivatedTimer; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate.DelayFromMatchTimer; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate.TimeoutTimer; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate.DelayFromActivatedTimer; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate.DelayFromMatchTimer; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate.TimeoutTimer; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.core.time.impl.DurationTimer; import org.drools.core.time.impl.PseudoClockScheduler; import org.drools.mvel.integrationtests.phreak.A; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java index 2f5c9383d8b..7599860cace 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java @@ -26,17 +26,17 @@ import org.drools.core.common.InternalFactHandle; import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.MockLeftTupleSink; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.sequencing.SequencerMemory; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.LoopController; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.SequencerMemory; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.LoopController; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.drools.mvel.integrationtests.phreak.A; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java index 7ca0333a5fc..b32d3174797 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java @@ -24,15 +24,15 @@ import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java index 47673cafb0e..8264ab97a8d 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java @@ -25,16 +25,16 @@ import org.drools.base.time.JobHandle; import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.DynamicFilterProto; -import org.drools.core.reteoo.sequencing.signalprocessors.Gates; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicCircuit; -import org.drools.core.reteoo.sequencing.signalprocessors.LogicGate; -import org.drools.core.reteoo.sequencing.Sequence; -import org.drools.core.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.core.reteoo.sequencing.Sequence.TimoutController; -import org.drools.core.reteoo.sequencing.Sequencer; -import org.drools.core.reteoo.sequencing.steps.Step; -import org.drools.core.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.Sequence.TimoutController; +import org.drools.base.reteoo.sequencing.Sequencer; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.core.time.impl.DurationTimer; import org.drools.core.time.impl.PseudoClockScheduler; import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java new file mode 100644 index 00000000000..12c91041d85 --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java @@ -0,0 +1,126 @@ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; +import org.drools.base.definitions.InternalKnowledgePackage; +import org.drools.base.definitions.impl.KnowledgePackageImpl; +import org.drools.base.definitions.rule.impl.RuleImpl; +import org.drools.base.reteoo.DynamicFilterProto; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.rule.Pattern; +import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; +import org.drools.core.impl.KnowledgeBaseImpl; +import org.drools.core.impl.RuleBaseFactory; +import org.drools.core.reteoo.CoreComponentFactory; +import org.drools.core.reteoo.builder.BuildContext; +import org.drools.core.rule.JavaDialectRuntimeData; +import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; +import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.C; +import org.drools.mvel.integrationtests.phreak.D; +import org.drools.mvel.integrationtests.phreak.E; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; +import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; +import org.junit.Before; +import org.junit.Test; +import org.kie.api.conf.EventProcessingOption; +import org.kie.api.runtime.KieSession; +import org.kie.internal.conf.CompositeBaseConfiguration; + +import java.util.Collections; + +public class SequenceInRuleTest { + SessionsAwareKnowledgeBase kbase; + @Before + public void setup() { + CompositeBaseConfiguration conf = (CompositeBaseConfiguration) RuleBaseFactory.newKnowledgeBaseConfiguration(); + + KnowledgeBaseImpl rbase = new KnowledgeBaseImpl("ID", conf ); + + kbase = new SessionsAwareKnowledgeBase(rbase); + + RuleImpl rule = new RuleImpl("rule1").setPackage("org.pkg1"); + InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("org.pkg1"); + pkg.getDialectRuntimeRegistry().setDialectData( "java", new JavaDialectRuntimeData()); + pkg.addRule( rule ); + + //rule.addPattern(); + +// buildContext = createContext(); +// buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); +// +// MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); +// +// mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); +// + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + final ObjectType cObjectType = new ClassObjectType(C.class); + + Pattern aPattern = new Pattern(0, aObjectType); + rule.addPattern(aPattern); + +// final ObjectType dObjectType = new ClassObjectType(D.class); +// final ObjectType eObjectType = new ClassObjectType(E.class); +// + final Pattern bpattern = new Pattern(0, + bObjectType, + "b" ); + bpattern.addConstraint(new AlphaConstraint((Predicate1) b -> b.getText().equals("b"))); + + final Pattern cpattern = new Pattern(0, + cObjectType, + "c" ); + cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); +// +// final Pattern dpattern = new Pattern(0, +// dObjectType, +// "d" ); +// dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); +// +// final Pattern epattern = new Pattern(0, +// eObjectType, +// "e" ); +// epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); +// +// DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); +// DynamicFilterProto cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); + + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask), 0, + new int[] {0, 1}, // B and C + new int[] {0, 1}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + + gate1.setOutput(TerminatingSignalProcessor.get()); + LogicCircuit circuit1 = new LogicCircuit(gate1); + Sequence seq = new Sequence(0, Step.of(circuit1)); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + + rbase.addPackage(pkg); + +// buildContext.getRule().addSequence(seq); + +// KnowledgePackageImpl pkg = new KnowledgePackageImpl("org.default"); +// pkg.addRule(rule); +// +// buildContext.getRuleBase() + + } + + @Test + public void tes1() { + KieSession session = kbase.newKieSession(); + session.insert(new A(0)); + session.fireAllRules(); + session.insert(new B(0, "b")); + session.insert(new C(0, "c")); + session.fireAllRules(); + } +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/util/RightTupleIndexHashTableTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/util/RightTupleIndexHashTableTest.java index 1885446a8ea..5550f00ce21 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/util/RightTupleIndexHashTableTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/util/RightTupleIndexHashTableTest.java @@ -43,7 +43,7 @@ import org.drools.core.test.model.Cheese; import org.drools.core.util.AbstractHashTable; import org.drools.base.util.IndexedValueReader; -import org.drools.core.util.SingleLinkedEntry; +import org.drools.base.util.SingleLinkedEntry; import org.drools.core.util.index.TupleIndexHashTable; import org.drools.core.util.index.TupleList; import org.junit.Before; diff --git a/drools-tms/src/main/java/org/drools/tms/LogicalDependency.java b/drools-tms/src/main/java/org/drools/tms/LogicalDependency.java index 385b7049363..bd9117f75e2 100644 --- a/drools-tms/src/main/java/org/drools/tms/LogicalDependency.java +++ b/drools-tms/src/main/java/org/drools/tms/LogicalDependency.java @@ -18,7 +18,7 @@ */ package org.drools.tms; -import org.drools.core.util.DoubleLinkedEntry; +import org.drools.base.util.DoubleLinkedEntry; import org.drools.tms.agenda.TruthMaintenanceSystemInternalMatch; import org.drools.tms.beliefsystem.ModedAssertion; diff --git a/drools-tms/src/main/java/org/drools/tms/SimpleMode.java b/drools-tms/src/main/java/org/drools/tms/SimpleMode.java index b0a2d736a13..8a5c45a8659 100644 --- a/drools-tms/src/main/java/org/drools/tms/SimpleMode.java +++ b/drools-tms/src/main/java/org/drools/tms/SimpleMode.java @@ -24,7 +24,7 @@ import org.drools.tms.beliefsystem.BeliefSystem; import org.drools.base.beliefsystem.Mode; -import org.drools.core.util.LinkedListEntry; +import org.drools.base.util.LinkedListEntry; import org.drools.tms.beliefsystem.ModedAssertion; public class SimpleMode extends LinkedListEntry> diff --git a/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemAgendaComponentFactory.java b/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemAgendaComponentFactory.java index f80ad5c6305..aefd179267d 100644 --- a/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemAgendaComponentFactory.java +++ b/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemAgendaComponentFactory.java @@ -24,7 +24,7 @@ import org.drools.core.reteoo.AgendaComponentFactory; import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.PathMemory; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import org.drools.core.reteoo.TerminalNode; import org.drools.core.common.PropagationContext; import org.drools.core.reteoo.TupleImpl; diff --git a/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemImpl.java b/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemImpl.java index 9b110399984..a64530d0d9b 100644 --- a/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemImpl.java +++ b/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemImpl.java @@ -35,7 +35,7 @@ import org.drools.core.reteoo.ObjectTypeConf; import org.drools.core.reteoo.Tuple; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; import org.drools.tms.agenda.TruthMaintenanceSystemInternalMatch; import org.drools.tms.beliefsystem.BeliefSet; import org.drools.tms.beliefsystem.BeliefSystem; diff --git a/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemKnowledgeHelper.java b/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemKnowledgeHelper.java index 0127ee866f9..ed36fb8face 100644 --- a/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemKnowledgeHelper.java +++ b/drools-tms/src/main/java/org/drools/tms/TruthMaintenanceSystemKnowledgeHelper.java @@ -29,8 +29,8 @@ import org.drools.core.reteoo.RuntimeComponentFactory; import org.drools.base.rule.EntryPointId; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.util.LinkedList; -import org.drools.core.util.LinkedListEntry; +import org.drools.base.util.LinkedList; +import org.drools.base.util.LinkedListEntry; import org.drools.kiesession.consequence.DefaultKnowledgeHelper; import org.drools.kiesession.entrypoints.NamedEntryPoint; import org.drools.tms.agenda.TruthMaintenanceSystemInternalMatch; diff --git a/drools-tms/src/main/java/org/drools/tms/agenda/TruthMaintenanceSystemInternalMatch.java b/drools-tms/src/main/java/org/drools/tms/agenda/TruthMaintenanceSystemInternalMatch.java index c848102bcdf..dae02754a7f 100644 --- a/drools-tms/src/main/java/org/drools/tms/agenda/TruthMaintenanceSystemInternalMatch.java +++ b/drools-tms/src/main/java/org/drools/tms/agenda/TruthMaintenanceSystemInternalMatch.java @@ -23,7 +23,7 @@ import org.drools.tms.SimpleMode; import org.drools.tms.LogicalDependency; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; public interface TruthMaintenanceSystemInternalMatch> extends InternalMatch { diff --git a/drools-tms/src/main/java/org/drools/tms/agenda/TruthMaintenanceSystemRuleTerminalNodeLeftTuple.java b/drools-tms/src/main/java/org/drools/tms/agenda/TruthMaintenanceSystemRuleTerminalNodeLeftTuple.java index 0c0a5db05fa..4693cafbefa 100644 --- a/drools-tms/src/main/java/org/drools/tms/agenda/TruthMaintenanceSystemRuleTerminalNodeLeftTuple.java +++ b/drools-tms/src/main/java/org/drools/tms/agenda/TruthMaintenanceSystemRuleTerminalNodeLeftTuple.java @@ -21,10 +21,10 @@ import org.drools.core.common.ActivationsManager; import org.drools.core.common.InternalFactHandle; import org.drools.core.reteoo.RuleTerminalNodeLeftTuple; -import org.drools.core.reteoo.Sink; +import org.drools.base.reteoo.Sink; import org.drools.core.common.PropagationContext; import org.drools.core.reteoo.TupleImpl; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; import org.drools.tms.LogicalDependency; import org.drools.tms.SimpleMode; import org.drools.tms.TruthMaintenanceSystemImpl; diff --git a/drools-tms/src/main/java/org/drools/tms/beliefsystem/BeliefSet.java b/drools-tms/src/main/java/org/drools/tms/beliefsystem/BeliefSet.java index eca9aef60e8..8c48fffbc14 100644 --- a/drools-tms/src/main/java/org/drools/tms/beliefsystem/BeliefSet.java +++ b/drools-tms/src/main/java/org/drools/tms/beliefsystem/BeliefSet.java @@ -20,7 +20,7 @@ import org.drools.core.common.InternalFactHandle; import org.drools.core.common.WorkingMemoryAction; -import org.drools.core.util.FastIterator; +import org.drools.base.util.FastIterator; import org.drools.core.common.PropagationContext; public interface BeliefSet> { diff --git a/drools-tms/src/main/java/org/drools/tms/beliefsystem/ModedAssertion.java b/drools-tms/src/main/java/org/drools/tms/beliefsystem/ModedAssertion.java index c58db895d59..a47c2f21567 100644 --- a/drools-tms/src/main/java/org/drools/tms/beliefsystem/ModedAssertion.java +++ b/drools-tms/src/main/java/org/drools/tms/beliefsystem/ModedAssertion.java @@ -18,7 +18,7 @@ */ package org.drools.tms.beliefsystem; -import org.drools.core.util.DoubleLinkedEntry; +import org.drools.base.util.DoubleLinkedEntry; public interface ModedAssertion> extends BeliefSystemMode, DoubleLinkedEntry { diff --git a/drools-tms/src/main/java/org/drools/tms/beliefsystem/defeasible/DefeasibleBeliefSet.java b/drools-tms/src/main/java/org/drools/tms/beliefsystem/defeasible/DefeasibleBeliefSet.java index feb331af6b8..d10cdfba4f3 100644 --- a/drools-tms/src/main/java/org/drools/tms/beliefsystem/defeasible/DefeasibleBeliefSet.java +++ b/drools-tms/src/main/java/org/drools/tms/beliefsystem/defeasible/DefeasibleBeliefSet.java @@ -27,8 +27,8 @@ import org.drools.core.common.WorkingMemoryAction; import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.core.common.PropagationContext; -import org.drools.core.util.FastIterator; -import org.drools.core.util.DoubleLinkedEntry; +import org.drools.base.util.FastIterator; +import org.drools.base.util.DoubleLinkedEntry; import org.drools.tms.LogicalDependency; import org.drools.tms.TruthMaintenanceSystemEqualityKey; import org.drools.tms.beliefsystem.BeliefSystem; diff --git a/drools-tms/src/main/java/org/drools/tms/beliefsystem/jtms/JTMSBeliefSetImpl.java b/drools-tms/src/main/java/org/drools/tms/beliefsystem/jtms/JTMSBeliefSetImpl.java index f92016ea0fb..6e3bd1d6a6f 100644 --- a/drools-tms/src/main/java/org/drools/tms/beliefsystem/jtms/JTMSBeliefSetImpl.java +++ b/drools-tms/src/main/java/org/drools/tms/beliefsystem/jtms/JTMSBeliefSetImpl.java @@ -23,7 +23,7 @@ import org.drools.tms.LogicalDependency; import org.drools.core.common.WorkingMemoryAction; import org.drools.core.common.PropagationContext; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; public class JTMSBeliefSetImpl> extends LinkedList implements JTMSBeliefSet { diff --git a/drools-tms/src/main/java/org/drools/tms/beliefsystem/jtms/JTMSMode.java b/drools-tms/src/main/java/org/drools/tms/beliefsystem/jtms/JTMSMode.java index 463ffb03bfd..849faf6e268 100644 --- a/drools-tms/src/main/java/org/drools/tms/beliefsystem/jtms/JTMSMode.java +++ b/drools-tms/src/main/java/org/drools/tms/beliefsystem/jtms/JTMSMode.java @@ -21,7 +21,7 @@ import org.drools.tms.beliefsystem.BeliefSystem; import org.drools.tms.beliefsystem.ModedAssertion; import org.drools.tms.LogicalDependency; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.drools.base.beliefsystem.Mode; public class JTMSMode> extends AbstractLinkedListNode implements ModedAssertion { diff --git a/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/BeliefSystemLogicalCallback.java b/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/BeliefSystemLogicalCallback.java index c85866688b2..7dd05b1baaa 100644 --- a/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/BeliefSystemLogicalCallback.java +++ b/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/BeliefSystemLogicalCallback.java @@ -24,7 +24,7 @@ import org.drools.core.common.SuperCacheFixer; import org.drools.core.common.WorkingMemoryAction; import org.drools.core.marshalling.MarshallerReaderContext; -import org.drools.core.phreak.actions.AbstractPropagationEntry; +import org.drools.base.phreak.actions.AbstractPropagationEntry; import org.drools.core.reteoo.ObjectTypeConf; import org.drools.core.rule.consequence.InternalMatch; import org.drools.kiesession.entrypoints.NamedEntryPoint; diff --git a/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/SimpleBeliefSet.java b/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/SimpleBeliefSet.java index 5a7c59c5698..d62008c4fca 100644 --- a/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/SimpleBeliefSet.java +++ b/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/SimpleBeliefSet.java @@ -25,8 +25,8 @@ import org.drools.tms.LogicalDependency; import org.drools.core.common.WorkingMemoryAction; import org.drools.core.common.PropagationContext; -import org.drools.core.util.LinkedList; -import org.drools.core.util.LinkedListEntry; +import org.drools.base.util.LinkedList; +import org.drools.base.util.LinkedListEntry; public class SimpleBeliefSet extends LinkedList implements BeliefSet { protected BeliefSystem beliefSystem; diff --git a/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/SimpleLogicalDependency.java b/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/SimpleLogicalDependency.java index 39663212f3f..91a8f0c1e2a 100644 --- a/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/SimpleLogicalDependency.java +++ b/drools-tms/src/main/java/org/drools/tms/beliefsystem/simple/SimpleLogicalDependency.java @@ -19,7 +19,7 @@ package org.drools.tms.beliefsystem.simple; import org.drools.tms.beliefsystem.ModedAssertion; -import org.drools.core.util.AbstractLinkedListNode; +import org.drools.base.util.AbstractLinkedListNode; import org.drools.tms.LogicalDependency; import org.drools.tms.agenda.TruthMaintenanceSystemInternalMatch; diff --git a/drools-tms/src/test/java/org/drools/tms/TMSMockInternalMatch.java b/drools-tms/src/test/java/org/drools/tms/TMSMockInternalMatch.java index 65df15722ca..ae80fbbefee 100644 --- a/drools-tms/src/test/java/org/drools/tms/TMSMockInternalMatch.java +++ b/drools-tms/src/test/java/org/drools/tms/TMSMockInternalMatch.java @@ -21,7 +21,7 @@ import org.drools.core.common.ActivationsManager; import org.drools.core.common.InternalFactHandle; import org.drools.core.reteoo.TerminalNode; -import org.drools.core.util.LinkedList; +import org.drools.base.util.LinkedList; import org.drools.kiesession.MockInternalMatch; import org.drools.tms.agenda.TruthMaintenanceSystemInternalMatch; diff --git a/drools-traits/src/main/java/org/drools/traits/core/factmodel/Triple.java b/drools-traits/src/main/java/org/drools/traits/core/factmodel/Triple.java index ffa26ffe83c..b237d5c15b4 100644 --- a/drools-traits/src/main/java/org/drools/traits/core/factmodel/Triple.java +++ b/drools-traits/src/main/java/org/drools/traits/core/factmodel/Triple.java @@ -20,7 +20,7 @@ import java.io.Serializable; -import org.drools.core.util.SingleLinkedEntry; +import org.drools.base.util.SingleLinkedEntry; public interface Triple extends SingleLinkedEntry, Serializable { diff --git a/drools-traits/src/main/java/org/drools/traits/core/factmodel/TripleImpl.java b/drools-traits/src/main/java/org/drools/traits/core/factmodel/TripleImpl.java index 6d47fd95582..0b792e08a1a 100644 --- a/drools-traits/src/main/java/org/drools/traits/core/factmodel/TripleImpl.java +++ b/drools-traits/src/main/java/org/drools/traits/core/factmodel/TripleImpl.java @@ -18,7 +18,7 @@ */ package org.drools.traits.core.factmodel; -import org.drools.core.util.SingleLinkedEntry; +import org.drools.base.util.SingleLinkedEntry; public class TripleImpl extends AbstractTriple { private SingleLinkedEntry next; diff --git a/drools-traits/src/main/java/org/drools/traits/core/factmodel/TripleStore.java b/drools-traits/src/main/java/org/drools/traits/core/factmodel/TripleStore.java index d7078b82ce0..1ca6f538820 100644 --- a/drools-traits/src/main/java/org/drools/traits/core/factmodel/TripleStore.java +++ b/drools-traits/src/main/java/org/drools/traits/core/factmodel/TripleStore.java @@ -29,7 +29,7 @@ import java.util.List; import java.util.Map; -import org.drools.core.util.SingleLinkedEntry; +import org.drools.base.util.SingleLinkedEntry; import org.kie.api.runtime.rule.Variable; public class TripleStore implements Externalizable { From 7cfaef25c65756ca463ffafbcff8c3c02d9f05c1 Mon Sep 17 00:00:00 2001 From: Mark Proctor Date: Thu, 15 Aug 2024 18:12:34 +0100 Subject: [PATCH 4/5] -Sequencing now has Rule AST for adding a Sequence. Now tests builds it's node from a Rule. --- ...bstractPhreakSequencerSubsequenceTest.java | 89 ++++++++++- .../phreak/sequencing/AlphaConstraint.java | 55 +++++++ .../sequencing/MultiInputNodeBuilder.java | 151 ------------------ .../sequencing/PhreakSequencerActionTest.java | 45 +----- ...akSequencerActivateDeactivateStepTest.java | 73 +-------- .../PhreakSequencerAggregatorTest.java | 46 +----- .../PhreakSequencerEventsMemoryTest.java | 48 +----- .../PhreakSequencerLogicGateTest.java | 83 ++-------- .../PhreakSequencerSequenceLoopTest.java | 54 +------ .../PhreakSequencerSequenceTimerTest.java | 52 +----- ...akSequencerSignalProcessorCounterTest.java | 99 +++--------- ...reakSequencerSignalProcessorTimerTest.java | 89 +++-------- .../PhreakSequencerSubsequenceLoopTest.java | 56 +------ .../PhreakSequencerSubsequenceTest.java | 44 +---- .../PhreakSequencerSubsequenceTimerTest.java | 53 +----- .../phreak/sequencing/Predicate1.java | 5 + .../phreak/sequencing/SequenceInRuleTest.java | 12 -- .../phreak/sequencing/TestMemories.java | 89 +++++++++++ 18 files changed, 345 insertions(+), 798 deletions(-) create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AlphaConstraint.java delete mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/Predicate1.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/TestMemories.java diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java index 2f633470025..13f7910fb2f 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java @@ -1,7 +1,11 @@ package org.drools.mvel.integrationtests.phreak.sequencing; +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; import org.drools.base.definitions.InternalKnowledgePackage; import org.drools.base.definitions.rule.impl.RuleImpl; +import org.drools.base.rule.EntryPointId; +import org.drools.base.rule.Pattern; import org.drools.core.ClockType; import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; @@ -10,6 +14,7 @@ import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.MockLeftTupleSink; +import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.SequenceNode; import org.drools.base.reteoo.DynamicFilterProto; import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; @@ -20,6 +25,11 @@ import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.C; +import org.drools.mvel.integrationtests.phreak.D; +import org.drools.mvel.integrationtests.phreak.E; +import org.kie.api.conf.EventProcessingOption; import org.kie.api.runtime.conf.ThreadSafeOption; import org.kie.internal.conf.CompositeBaseConfiguration; @@ -32,14 +42,58 @@ public class AbstractPhreakSequencerSubsequenceTest { BuildContext buildContext; Sequence seq0; Sequence seq1; - Sequence seq2; - SequenceNode mnode; + Sequence seq2; + SequenceNode snode; + + Pattern bpattern; + Pattern cpattern; + Pattern dpattern; + Pattern epattern; + + RuleImpl rule; + InternalKnowledgePackage pkg; + SessionsAwareKnowledgeBase kbase; DynamicFilterProto bfilter; DynamicFilterProto cfilter; DynamicFilterProto dfilter; DynamicFilterProto efilter; + public void initKBaseWithEmptyRule() { + CompositeBaseConfiguration conf = (CompositeBaseConfiguration) RuleBaseFactory.newKnowledgeBaseConfiguration(); + conf.setOption(EventProcessingOption.STREAM); + + KnowledgeBaseImpl rbase = new KnowledgeBaseImpl("ID", conf ); + + kbase = new SessionsAwareKnowledgeBase(rbase); + + rule = new RuleImpl("rule1").setPackage("org.pkg1"); + pkg = CoreComponentFactory.get().createKnowledgePackage("org.pkg1"); + pkg.getDialectRuntimeRegistry().setDialectData( "java", new JavaDialectRuntimeData()); + pkg.addRule( rule ); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + final ObjectType cObjectType = new ClassObjectType(C.class); + final ObjectType dObjectType = new ClassObjectType(D.class); + final ObjectType eObjectType = new ClassObjectType(E.class); + + Pattern aPattern = new Pattern(0, aObjectType); + rule.addPattern(aPattern); + + bpattern = new Pattern(0, bObjectType, "b" ); + bpattern.addConstraint(new AlphaConstraint((Predicate1) b -> b.getText().equals("b"))); + + cpattern = new Pattern(0, cObjectType, "c" ); + cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); + + dpattern = new Pattern(0, dObjectType, "d" ); + dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); + + epattern = new Pattern(0, eObjectType, "e" ); + epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); + } + public static BuildContext createContext() { CompositeBaseConfiguration conf = (CompositeBaseConfiguration) RuleBaseFactory.newKnowledgeBaseConfiguration(); @@ -74,10 +128,35 @@ void createSession() { session = (StatefulKnowledgeSessionImpl) kbase.newKieSession(sessionConf, null); InternalFactHandle fhA0 = (InternalFactHandle) session.insert(new A(0)); - nodeMemory = session.getNodeMemory(mnode); - LeftTuple lt = new LeftTuple(fhA0, mnode, true); - lt.setContextObject(mnode.createSequencerMemory(lt, new MockLeftTupleSink(buildContext.getNextNodeId(), buildContext), nodeMemory)); + nodeMemory = session.getNodeMemory(snode); + LeftTuple lt = new LeftTuple(fhA0, snode, true); + lt.setContextObject(snode.createSequencerMemory(lt, new MockLeftTupleSink(buildContext.getNextNodeId(), buildContext), nodeMemory)); nodeMemory.getLeftTupleMemory().add(lt); sequencerMemory = (SequencerMemory) lt.getContextObject(); } + + void createSession2() { + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.NO); + sessionConf.setClockType(ClockType.PSEUDO_CLOCK); + + if (snode == null) { + ObjectTypeNode aNode = kbase.getRete().getEntryPointNode(EntryPointId.DEFAULT).getObjectTypeNodes().get(new ClassObjectType(A.class)); + snode = (SequenceNode) aNode.getSinks()[0].getSinks()[0]; + } + + if (session != null) { + nodeMemory = null; + sequencerMemory = null; + session.dispose(); + session = null; + } + + session = (StatefulKnowledgeSessionImpl) kbase.newKieSession(sessionConf, null); + + InternalFactHandle fhA0 = (InternalFactHandle) session.insert(new A(0)); + session.fireAllRules(); + nodeMemory = session.getNodeMemory(snode); + sequencerMemory = (SequencerMemory) fhA0.getFirstLeftTuple().getContextObject(); + } } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AlphaConstraint.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AlphaConstraint.java new file mode 100644 index 00000000000..6832fe6d744 --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AlphaConstraint.java @@ -0,0 +1,55 @@ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ValueResolver; +import org.drools.base.reteoo.BaseTuple; +import org.drools.base.rule.Declaration; +import org.drools.base.rule.MutableTypeConstraint; +import org.kie.api.runtime.rule.FactHandle; + +public class AlphaConstraint extends MutableTypeConstraint { + private Predicate1 predicate1; + + public AlphaConstraint(Predicate1 predicate1) { + this.predicate1 = predicate1; + } + + @Override + public Declaration[] getRequiredDeclarations() { + return new Declaration[0]; + } + + @Override + public void replaceDeclaration(Declaration oldDecl, Declaration newDecl) { + + } + + @Override + public MutableTypeConstraint clone() { + return null; + } + + @Override + public boolean isTemporal() { + return false; + } + + @Override + public boolean isAllowed(FactHandle handle, ValueResolver valueResolver) { + return predicate1.test(handle.getObject()); + } + + @Override + public boolean isAllowedCachedLeft(Object context, FactHandle handle) { + return false; + } + + @Override + public boolean isAllowedCachedRight(BaseTuple tuple, Object context) { + return false; + } + + @Override + public Object createContext() { + return null; + } +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java deleted file mode 100644 index 81cd629e211..00000000000 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.drools.mvel.integrationtests.phreak.sequencing; - -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ValueResolver; -import org.drools.base.common.RuleBasePartitionId; -import org.drools.base.reteoo.BaseTuple; -import org.drools.base.rule.Declaration; -import org.drools.base.rule.EntryPointId; -import org.drools.base.rule.MutableTypeConstraint; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.reteoo.CoreComponentFactory; -import org.drools.core.reteoo.EntryPointNode; -import org.drools.core.reteoo.LeftTupleSource; -import org.drools.core.reteoo.SequenceNode; -import org.drools.core.reteoo.SequenceNode.AlphaAdapter; -import org.drools.core.reteoo.ObjectSource; -import org.drools.core.reteoo.ObjectTypeNode; -import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.reteoo.builder.NodeFactory; -import org.kie.api.runtime.rule.FactHandle; - -public class MultiInputNodeBuilder { - BuildContext buildContext; - - public MultiInputNodeBuilder(BuildContext buildContext) { - this.buildContext = buildContext; - } - - public static MultiInputNodeBuilder create(BuildContext buildContext) { - return new MultiInputNodeBuilder(buildContext); - } - - public SequenceNode buildNode(Class leftType, Class[] rightTypes) { - NodeFactory nFactory = CoreComponentFactory.get().getNodeFactoryService(); - - EntryPointNode epn = buildContext.getRuleBase().getRete().getEntryPointNodes().get(EntryPointId.DEFAULT); - - buildContext.setCurrentEntryPoint(epn.getEntryPoint()); - buildContext.setTupleMemoryEnabled(true); - buildContext.setPartitionId(RuleBasePartitionId.MAIN_PARTITION); - - ObjectTypeNode otn = nFactory.buildObjectTypeNode(buildContext.getNextNodeId(), - epn, - new ClassObjectType(leftType), - buildContext); - LeftTupleSource leftTs = nFactory.buildLeftInputAdapterNode(buildContext.getNextNodeId(), otn, - buildContext, false); - - ObjectSource[] otns = new ObjectSource[rightTypes.length]; - for ( int i = 0; i < rightTypes.length; i++ ) { - otns[i] = nFactory.buildObjectTypeNode(buildContext.getNextNodeId(), epn, - new ClassObjectType(rightTypes[i]), - buildContext); - - otns[i].attach(buildContext); - } - - - SequenceNode mn = new SequenceNode(buildContext.getNextNodeId(), - leftTs, buildContext); - - AlphaAdapter[] adapters = new AlphaAdapter[rightTypes.length]; - for ( int i = 0; i < rightTypes.length; i++ ) { - adapters[i] = new AlphaAdapter(buildContext.getNextNodeId(), otns[i], - buildContext.getPartitionId(), mn, i); - - adapters[i].attach(buildContext); - } - - mn.setAlphaAdapters(adapters); - - mn.attach(buildContext); - - return mn; - } - - public AlphaNodeFieldConstraint buildConstraint(Predicate1 predicate1) { - return new AlphaConstraint(predicate1); - } - - public static class AlphaConstraint extends MutableTypeConstraint { - private Predicate1 predicate1; - - public AlphaConstraint(Predicate1 predicate1) { - this.predicate1 = predicate1; - } - - @Override - public Declaration[] getRequiredDeclarations() { - return new Declaration[0]; - } - - @Override - public void replaceDeclaration(Declaration oldDecl, Declaration newDecl) { - - } - - @Override - public MutableTypeConstraint clone() { - return null; - } - - @Override - public boolean isTemporal() { - return false; - } - - @Override - public boolean isAllowed(FactHandle handle, ValueResolver valueResolver) { - return predicate1.test(handle.getObject()); - } - - @Override - public boolean isAllowedCachedLeft(Object context, FactHandle handle) { - return false; - } - - @Override - public boolean isAllowedCachedRight(BaseTuple tuple, Object context) { - return false; - } - - @Override - public Object createContext() { - return null; - } - } - - interface Predicate1 { - boolean test(A a); - } - -} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java index 11086c269e6..b9a6ead02e3 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java @@ -18,31 +18,18 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.base.util.CircularArrayList; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import org.kie.api.runtime.rule.FactHandle; import java.util.ArrayList; @@ -56,24 +43,9 @@ public class PhreakSequencerActionTest extends AbstractPhreakSequencerSubsequenc @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + initKBaseWithEmptyRule(); recorder.clear(); - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - LogicCircuit circuit1 = getLogicCircuit(); LogicCircuit circuit2 = getLogicCircuit(); @@ -84,14 +56,12 @@ public void setup() { Step.of(circuit2), Step.of( m -> recorder.add("spacer")), Step.of( m -> recorder.add(((FactHandle)m.getSequencerMemory().getEvents().getHead()).getObject()))); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters(new DynamicFilterProto[] {bfilter}); - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.NO); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); - createSession(); + createSession2(); } private LogicCircuit getLogicCircuit() { @@ -111,11 +81,6 @@ private static LogicGate get1InputLogicGate() { @Test public void testAction() { - ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); - CircularArrayList events = sequencerMemory.getEvents(); assertThat(events.size()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(b(0)); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java index 3bea1266335..2a23ca84cac 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java @@ -18,35 +18,22 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; import org.drools.base.reteoo.DynamicFilter; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.SignalAdapter; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.base.util.LinkedList; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; import org.drools.mvel.integrationtests.phreak.D; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import static org.assertj.core.api.Assertions.assertThat; @@ -56,36 +43,7 @@ public class PhreakSequencerActivateDeactivateStepTest extends AbstractPhreakSeq @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - final ObjectType dObjectType = new ClassObjectType(D.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c" ); - cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); - - final Pattern dpattern = new Pattern(0, - dObjectType, - "d" ); - dpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("d"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - DynamicFilterProto cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); - DynamicFilterProto dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); + initKBaseWithEmptyRule(); LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, new int[] {0, 1}, // B and C @@ -104,34 +62,17 @@ public void setup() { LogicCircuit circuit2 = new LogicCircuit(gate2); seq0 = new Sequence(0, Step.of(circuit1), Step.of(circuit2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter, dfilter}); - - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.YES); - - createSession(); + seq0.setFilters(new Pattern[]{bpattern, cpattern, dpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); + createSession2(); sequenceMemory = sequencerMemory.getSequenceMemory(seq0); } - @Test - public void testInitialisedMemories() { - // make sure these are empty - assertThat(nodeMemory.getFilters()).usingRecursiveComparison().isEqualTo(new DynamicFilter[3]); - assertThat(nodeMemory.getActiveFilters()).usingRecursiveComparison().isEqualTo(new LinkedList[3]); - assertThat(nodeMemory.getActiveFilters()).usingRecursiveComparison().isEqualTo(new LinkedList[3]); - assertThat(sequenceMemory.getActiveSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[4]); - assertThat(sequenceMemory.getSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[4]); - assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // sequence not yet started - } - @Test public void testActivateAfterFirstCircuitStep() { // activate LogicCircuit1 and check filters are adapters are created and made active - mnode.getSequencer().start(sequencerMemory, session); - DynamicFilter filter0 = nodeMemory.getFilters()[0]; // B DynamicFilter filter1 = nodeMemory.getFilters()[1]; // C // [2] D is null @@ -155,8 +96,6 @@ public void testActivateAfterFirstCircuitStep() { @Test public void testDeactivateAndActivateAfterSecondCircuitStep() { - mnode.getSequencer().start(sequencerMemory, session); - DynamicFilter filter0 = nodeMemory.getFilters()[0]; // B DynamicFilter filter1 = nodeMemory.getFilters()[1]; // C @@ -193,8 +132,6 @@ public void testDeactivateAndActivateAfterSecondCircuitStep() { @Test public void testDeactivateAfterEndStep() { - mnode.getSequencer().start(sequencerMemory, session); - assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java index 58d38624c25..0e8e8cc1b30 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java @@ -18,32 +18,20 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.Sequence.LoopController; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.base.util.CircularArrayList; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import org.kie.api.runtime.rule.FactHandle; import java.util.ArrayList; @@ -58,23 +46,7 @@ public class PhreakSequencerAggregatorTest extends AbstractPhreakSequencerSubseq @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - recorder.clear(); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + initKBaseWithEmptyRule(); LogicCircuit circuit1 = getLogicCircuit(); LogicCircuit circuit2 = getLogicCircuit(); @@ -102,14 +74,11 @@ public void setup() { seq1.setOutputSize(1); seq0 = new Sequence(0, Step.of(circuit1), Step.of(seq1, aggregator), Step.of(circuit4)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters(new DynamicFilterProto[] {bfilter}); - - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.YES); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); - createSession(); + createSession2(); } private LogicCircuit getLogicCircuit() { @@ -129,11 +98,6 @@ private static LogicGate get1InputLogicGate() { @Test public void testSequenceEventsMemory() { - ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); - CircularArrayList events = sequencerMemory.getEvents(); assertThat(events.size()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(b(0)); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java index 4ee671f5bc3..b2d4be072a7 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java @@ -18,58 +18,27 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.base.util.CircularArrayList; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import org.kie.api.runtime.rule.FactHandle; -import java.util.ArrayList; - import static org.assertj.core.api.Assertions.assertThat; public class PhreakSequencerEventsMemoryTest extends AbstractPhreakSequencerSubsequenceTest { - @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + initKBaseWithEmptyRule(); LogicCircuit circuit1 = getLogicCircuit(); LogicCircuit circuit2 = getLogicCircuit(); @@ -82,14 +51,12 @@ public void setup() { seq2 = new Sequence(2, Step.of(circuit4), Step.of(circuit5)); seq0 = new Sequence(0, Step.of(circuit1), Step.of(seq1), Step.of(circuit3), Step.of(seq2), Step.of(circuit6)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.YES); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); - createSession(); + createSession2(); } private LogicCircuit getLogicCircuit() { @@ -109,11 +76,6 @@ private static LogicGate get1InputLogicGate() { @Test public void testSequenceEventsMemory() { - ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); - CircularArrayList events = sequencerMemory.getEvents(); assertThat(events.size()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java index 27368aa4c40..794118999a7 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java @@ -18,31 +18,21 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGateOutputSignalProcessor; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.signalprocessors.SignalIndex; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; import org.drools.mvel.integrationtests.phreak.D; -import org.drools.mvel.integrationtests.phreak.E; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; import static org.assertj.core.api.Assertions.assertThat; @@ -50,43 +40,7 @@ public class PhreakSequencerLogicGateTest extends AbstractPhreakSequencerSubsequ @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - final ObjectType dObjectType = new ClassObjectType(D.class); - final ObjectType eObjectType = new ClassObjectType(E.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c" ); - cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); - - final Pattern dpattern = new Pattern(0, - dObjectType, - "d" ); - dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); - - final Pattern epattern = new Pattern(0, - eObjectType, - "e" ); - epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); - - bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); - dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); - efilter = new DynamicFilterProto((AlphaNodeFieldConstraint) epattern.getConstraints().get(0), 3); + initKBaseWithEmptyRule(); } @Test @@ -101,12 +55,11 @@ public void testAnd() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern, dpattern, epattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); - - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 @@ -114,8 +67,7 @@ public void testAnd() { assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated // reverse B and C - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); @@ -136,20 +88,18 @@ public void testOr() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); - - createSession(); + seq.setFilters(new Pattern[]{bpattern, cpattern, dpattern, epattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated // reverse B and C - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); @@ -176,12 +126,12 @@ public void testComposite() { LogicCircuit circuit1 = new LogicCircuit(gate1, gate2); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter, dfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern, dpattern, epattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); // D last - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 @@ -193,8 +143,7 @@ public void testComposite() { assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated // change order, D first - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); fhD0 = (InternalFactHandle) session.insert(new D(0, "d")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java index 2ac325c48e3..9e3e834cdc1 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java @@ -18,32 +18,20 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.Sequence.LoopController; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import java.util.ArrayList; @@ -53,29 +41,7 @@ public class PhreakSequencerSequenceLoopTest extends AbstractPhreakSequencerSubs @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c" ); - cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - DynamicFilterProto cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); + initKBaseWithEmptyRule(); LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, new int[] {0}, // B @@ -92,25 +58,18 @@ public void setup() { LogicCircuit circuit2 = new LogicCircuit(gate2); seq0 = new Sequence(0, Step.of(circuit1), Step.of(circuit2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); - - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.YES); - - createSession(); + seq0.setFilters(new Pattern[]{bpattern, cpattern, dpattern, epattern}); } @Test public void testSequenceLoopConstraint() { seq0.setController(new LoopController(m -> m.getCount() < 2)); + rule.addSequence(seq0); + kbase.addPackage(pkg); - ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); + ArrayList stack = sequencerMemory.getSequenceStack(); assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(0); @@ -132,7 +91,6 @@ public void testSequenceLoopConstraint() { InternalFactHandle fhC4 = (InternalFactHandle) session.insert(new C(0, "c")); assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(3); - assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java index e07e932dfce..a165a0d232d 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java @@ -18,31 +18,21 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import org.drools.base.reteoo.sequencing.Sequence.TimoutController; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.core.time.impl.DurationTimer; import org.drools.core.time.impl.PseudoClockScheduler; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.C; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; import java.util.ArrayList; import java.util.concurrent.TimeUnit; @@ -53,29 +43,7 @@ public class PhreakSequencerSequenceTimerTest extends AbstractPhreakSequencerSu @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b"); - bpattern.addConstraint(new AlphaConstraint((Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c"); - cpattern.addConstraint(new AlphaConstraint((Predicate1) c -> c.getText().equals("c"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - DynamicFilterProto cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); + initKBaseWithEmptyRule(); LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask), 0, new int[]{0}, // B @@ -92,20 +60,17 @@ public void setup() { LogicCircuit circuit2 = new LogicCircuit(gate2); seq0 = new Sequence(0, Step.of(circuit1), Step.of(circuit2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters(new DynamicFilterProto[]{bfilter, cfilter}); + seq0.setFilters(new Pattern[]{bpattern, cpattern}); } @Test public void testSequenceTimeout() { seq0.setController(new TimoutController(new DurationTimer(1000))); - createSession(); + rule.addSequence(seq0); + kbase.addPackage(pkg); + createSession2(); ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); - InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); @@ -118,12 +83,11 @@ public void testSequenceTimeout() { @Test public void testSequenceComplete() { seq0.setController(new TimoutController(new DurationTimer(1000))); - createSession(); + rule.addSequence(seq0); + kbase.addPackage(pkg); + createSession2(); ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java index 6f8ce666420..881572c5ea1 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java @@ -18,33 +18,23 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGateOutputSignalProcessor; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import org.drools.base.reteoo.sequencing.signalprocessors.SignalIndex; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; import org.drools.mvel.integrationtests.phreak.D; -import org.drools.mvel.integrationtests.phreak.E; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; import static org.assertj.core.api.Assertions.assertThat; @@ -52,43 +42,7 @@ public class PhreakSequencerSignalProcessorCounterTest extends AbstractPhreakSeq @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - final ObjectType dObjectType = new ClassObjectType(D.class); - final ObjectType eObjectType = new ClassObjectType(E.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c" ); - cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); - - final Pattern dpattern = new Pattern(0, - dObjectType, - "d" ); - dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); - - final Pattern epattern = new Pattern(0, - eObjectType, - "e" ); - epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); - - bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); - dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); - efilter = new DynamicFilterProto((AlphaNodeFieldConstraint) epattern.getConstraints().get(0), 3); + initKBaseWithEmptyRule(); } @Test @@ -107,12 +61,11 @@ public void testEventCountEqual() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); - - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -138,12 +91,11 @@ public void testEventCountLessThan() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); - - createSession(); // pass - mnode.getSequencer().start(sequencerMemory, session); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -153,9 +105,7 @@ public void testEventCountLessThan() { InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); - createSession(); // fail - mnode.getSequencer().start(sequencerMemory, session); - + createSession2(); // fail assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -181,11 +131,11 @@ public void testEventCountBetween() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); // pass - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); // pass assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -196,9 +146,7 @@ public void testEventCountBetween() { InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); - createSession(); // fail - mnode.getSequencer().start(sequencerMemory, session); - + createSession2(); // fail assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -221,11 +169,12 @@ public void testSingleOutputCounter() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); + + createSession2(); // pass - createSession(); // pass - mnode.getSequencer().start(sequencerMemory, session); SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); @@ -275,12 +224,12 @@ public void testCompositeInputAndOutputCounters() { LogicCircuit circuit1 = new LogicCircuit(gate1, gate2); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter, dfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern, dpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); // D First - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq); InternalFactHandle fhD0 = (InternalFactHandle) session.insert(new D(0, "d")); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java index 48e3d35d92c..374d273458a 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java @@ -18,12 +18,8 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; @@ -32,21 +28,14 @@ import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate.DelayFromMatchTimer; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate.TimeoutTimer; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.core.time.impl.DurationTimer; import org.drools.core.time.impl.PseudoClockScheduler; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; -import org.drools.mvel.integrationtests.phreak.D; -import org.drools.mvel.integrationtests.phreak.E; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; import java.util.concurrent.TimeUnit; @@ -54,45 +43,10 @@ public class PhreakSequencerSignalProcessorTimerTest extends AbstractPhreakSequencerSubsequenceTest { + @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - final ObjectType dObjectType = new ClassObjectType(D.class); - final ObjectType eObjectType = new ClassObjectType(E.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c" ); - cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); - - final Pattern dpattern = new Pattern(0, - dObjectType, - "d" ); - dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); - - final Pattern epattern = new Pattern(0, - eObjectType, - "e" ); - epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); - - bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); - dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); - efilter = new DynamicFilterProto((AlphaNodeFieldConstraint) epattern.getConstraints().get(0), 3); + initKBaseWithEmptyRule(); } @Test @@ -109,12 +63,11 @@ public void testTimeout() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); - - createSession(); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); @@ -122,9 +75,8 @@ public void testTimeout() { pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); session.fireAllRules(); // if the rest of the system is immediate, why isn't this? assertThat(pseudo.getQueue().size()).isEqualTo(0); - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); pseudo = (PseudoClockScheduler) session.getTimerService(); @@ -154,12 +106,12 @@ public void testTimeoutWithCountFailure() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); + seq.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); + createSession2(); - mnode.getSequencer().start(sequencerMemory, session); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); InternalFactHandle fhB1 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -198,12 +150,12 @@ public void testDelayFromActivation() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); + createSession2(); - mnode.getSequencer().start(sequencerMemory, session); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); @@ -213,9 +165,8 @@ public void testDelayFromActivation() { session.fireAllRules(); // if the rest of the system is immediate, why isn't this? assertThat(pseudo.getQueue().size()).isEqualTo(0); - createSession(); + createSession2(); - mnode.getSequencer().start(sequencerMemory, session); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); pseudo = (PseudoClockScheduler) session.getTimerService(); @@ -239,12 +190,12 @@ public void testDelayFromMatch() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); + createSession2(); - mnode.getSequencer().start(sequencerMemory, session); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java index 7599860cace..e93c914a47f 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java @@ -18,35 +18,19 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.LeftTuple; -import org.drools.core.reteoo.MockLeftTupleSink; -import org.drools.base.reteoo.DynamicFilterProto; -import org.drools.base.reteoo.sequencing.SequencerMemory; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.Sequence.LoopController; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import java.util.ArrayList; @@ -56,22 +40,7 @@ public class PhreakSequencerSubsequenceLoopTest extends AbstractPhreakSequencerS @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + initKBaseWithEmptyRule(); LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, new int[] {0}, // B @@ -105,32 +74,19 @@ public void setup() { seq2 = new Sequence(2, Step.of(circuit3), Step.of(circuit4)); seq0 = new Sequence(0, Step.of(seq1), Step.of(seq2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); - - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.NO); - - session = (StatefulKnowledgeSessionImpl) kbase.newKieSession(sessionConf, null); - - InternalFactHandle fhA0 = (InternalFactHandle) session.insert(new A(0)); - nodeMemory = session.getNodeMemory(mnode); - LeftTuple lt = new LeftTuple(fhA0, mnode, true); - lt.setContextObject(mnode.createSequencerMemory(lt, new MockLeftTupleSink(buildContext.getNextNodeId(), buildContext), nodeMemory)); - nodeMemory.getLeftTupleMemory().add(lt); - sequencerMemory = (SequencerMemory) lt.getContextObject(); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); } @Test public void testSubSequence() { seq1.setController(new LoopController(m -> m.getCount() < 2)); seq2.setController(new LoopController(m -> m.getCount() < 2)); + kbase.addPackage(pkg); - ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); + createSession2(); - mnode.getSequencer().start(sequencerMemory, session); + ArrayList stack = sequencerMemory.getSequenceStack(); assertThat(stack.size()).isEqualTo(2); assertThat(stack.get(0).getSequence()).isSameAs(seq0); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java index b32d3174797..3a497de2a57 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java @@ -18,30 +18,18 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.steps.Step; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import java.util.ArrayList; @@ -49,25 +37,9 @@ public class PhreakSequencerSubsequenceTest extends AbstractPhreakSequencerSubsequenceTest { - @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + initKBaseWithEmptyRule(); LogicGate gate1 = get1InputLogicGate(); gate1.setOutput(TerminatingSignalProcessor.get()); @@ -89,14 +61,11 @@ public void setup() { seq2 = new Sequence(2, Step.of(circuit3), Step.of(circuit4)); seq0 = new Sequence(0, Step.of(seq1), Step.of(seq2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.YES); - - createSession(); + createSession2(); } private static LogicGate get1InputLogicGate() { @@ -110,9 +79,6 @@ private static LogicGate get1InputLogicGate() { @Test public void testSubSequence() { ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); assertThat(stack.size()).isEqualTo(2); assertThat(stack.get(0).getSequence()).isSameAs(seq0); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java index 8264ab97a8d..3a31220ab60 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java @@ -18,34 +18,22 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.base.time.JobHandle; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import org.drools.base.reteoo.sequencing.Sequence.TimoutController; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.core.time.impl.DurationTimer; import org.drools.core.time.impl.PseudoClockScheduler; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import java.util.ArrayList; import java.util.concurrent.TimeUnit; @@ -56,22 +44,7 @@ public class PhreakSequencerSubsequenceTimerTest extends AbstractPhreakSequencer @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + initKBaseWithEmptyRule(); LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, new int[] {0}, // B @@ -105,23 +78,17 @@ public void setup() { seq2 = new Sequence(2, Step.of(circuit3), Step.of(circuit4)); seq0 = new Sequence(0, Step.of(seq1), Step.of(seq2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); - - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.NO); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); } @Test public void testSubSequenceFailSeq1() { seq1.setController(new TimoutController(new DurationTimer(1000))); - createSession(); + createSession2(); ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); assertThat(stack.size()).isEqualTo(2); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); @@ -141,12 +108,9 @@ public void testSubSequenceFailSeq1() { public void testSubSequenceFailSeq2() { seq1.setController(new TimoutController(new DurationTimer(1000))); seq2.setController(new TimoutController(new DurationTimer(1000))); - createSession(); + createSession2(); ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); assertThat(stack.size()).isEqualTo(2); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); @@ -175,12 +139,9 @@ public void testSubSequenceFailSeq2() { public void testSubSequenceComplete() { seq1.setController(new TimoutController(new DurationTimer(1000))); seq2.setController(new TimoutController(new DurationTimer(1000))); - createSession(); + createSession2(); ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); assertThat(stack.size()).isEqualTo(2); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/Predicate1.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/Predicate1.java new file mode 100644 index 00000000000..406907a5e1d --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/Predicate1.java @@ -0,0 +1,5 @@ +package org.drools.mvel.integrationtests.phreak.sequencing; + +interface Predicate1 { + boolean test(A a); +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java index 12c91041d85..2daf9b63172 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java @@ -3,9 +3,7 @@ import org.drools.base.base.ClassObjectType; import org.drools.base.base.ObjectType; import org.drools.base.definitions.InternalKnowledgePackage; -import org.drools.base.definitions.impl.KnowledgePackageImpl; import org.drools.base.definitions.rule.impl.RuleImpl; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; @@ -13,28 +11,19 @@ import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.impl.KnowledgeBaseImpl; import org.drools.core.impl.RuleBaseFactory; import org.drools.core.reteoo.CoreComponentFactory; -import org.drools.core.reteoo.builder.BuildContext; import org.drools.core.rule.JavaDialectRuntimeData; import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; -import org.drools.mvel.integrationtests.phreak.D; -import org.drools.mvel.integrationtests.phreak.E; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; import org.kie.api.runtime.KieSession; import org.kie.internal.conf.CompositeBaseConfiguration; -import java.util.Collections; - public class SequenceInRuleTest { SessionsAwareKnowledgeBase kbase; @Before @@ -111,7 +100,6 @@ public void setup() { // pkg.addRule(rule); // // buildContext.getRuleBase() - } @Test diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/TestMemories.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/TestMemories.java new file mode 100644 index 00000000000..aaeda34ec8d --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/TestMemories.java @@ -0,0 +1,89 @@ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.reteoo.DynamicFilter; +import org.drools.base.reteoo.SignalAdapter; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.SequencerMemory; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.rule.EntryPointId; +import org.drools.base.rule.Pattern; +import org.drools.base.util.LinkedList; +import org.drools.core.ClockType; +import org.drools.core.SessionConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.LeftTuple; +import org.drools.core.reteoo.MockLeftTupleSink; +import org.drools.core.reteoo.ObjectTypeNode; +import org.drools.core.reteoo.SequenceNode; +import org.drools.core.reteoo.builder.BuildContext; +import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; +import org.drools.mvel.integrationtests.phreak.A; +import org.junit.Test; +import org.kie.api.runtime.conf.ThreadSafeOption; + +import java.util.Collections; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TestMemories extends AbstractPhreakSequencerSubsequenceTest { + + @Test + public void testInitilisedMemoryBeforeStart() { + initKBaseWithEmptyRule(); + buildContext = new BuildContext(kbase, Collections.emptyList() ); + buildContext.setRule(rule); + + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask), 0, + new int[] {0, 1}, // B and C + new int[] {0, 1}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + gate1.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + LogicGate gate2 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),1, + new int[] {1, 2}, // C and D, C Filter is re-used + new int[] {2, 3}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + gate2.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit2 = new LogicCircuit(gate2); + + seq0 = new Sequence(0, Step.of(circuit1), Step.of(circuit2)); + seq0.setFilters(new Pattern[]{bpattern, cpattern, dpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); + + ObjectTypeNode aNode = kbase.getRete().getEntryPointNode(EntryPointId.DEFAULT).getObjectTypeNodes().get(new ClassObjectType(A.class)); + snode = (SequenceNode) aNode.getSinks()[0].getSinks()[0]; + + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.NO); + sessionConf.setClockType(ClockType.PSEUDO_CLOCK); + + session = (StatefulKnowledgeSessionImpl) kbase.newKieSession(sessionConf, null); + + InternalFactHandle fhA0 = (InternalFactHandle) session.insert(new A(0)); + nodeMemory = session.getNodeMemory(snode); + LeftTuple lt = new LeftTuple(fhA0, snode, true); + lt.setContextObject(snode.createSequencerMemory(lt, new MockLeftTupleSink(buildContext.getNextNodeId(), buildContext), nodeMemory)); + nodeMemory.getLeftTupleMemory().add(lt); + sequencerMemory = (SequencerMemory) lt.getContextObject(); + + SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq0); + + // make sure these are empty + assertThat(nodeMemory.getFilters()).usingRecursiveComparison().isEqualTo(new DynamicFilter[3]); + assertThat(nodeMemory.getActiveFilters()).usingRecursiveComparison().isEqualTo(new LinkedList[3]); + assertThat(nodeMemory.getActiveFilters()).usingRecursiveComparison().isEqualTo(new LinkedList[3]); + assertThat(sequenceMemory.getActiveSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[4]); + assertThat(sequenceMemory.getSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[4]); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // sequence not yet started + } +} From 5fd8820e67c781df738d96a844807375ed934dec Mon Sep 17 00:00:00 2001 From: Mark Proctor Date: Thu, 15 Aug 2024 18:56:43 +0100 Subject: [PATCH 5/5] cleaned up abstract file --- ...bstractPhreakSequencerSubsequenceTest.java | 25 ------------------- .../sequencing/PhreakSequencerActionTest.java | 2 +- ...akSequencerActivateDeactivateStepTest.java | 2 +- .../PhreakSequencerAggregatorTest.java | 2 +- .../PhreakSequencerEventsMemoryTest.java | 2 +- .../PhreakSequencerLogicGateTest.java | 12 ++++----- .../PhreakSequencerSequenceLoopTest.java | 2 +- .../PhreakSequencerSequenceTimerTest.java | 4 +-- ...akSequencerSignalProcessorCounterTest.java | 14 +++++------ ...reakSequencerSignalProcessorTimerTest.java | 12 ++++----- .../PhreakSequencerSubsequenceLoopTest.java | 2 +- .../PhreakSequencerSubsequenceTest.java | 2 +- .../PhreakSequencerSubsequenceTimerTest.java | 6 ++--- 13 files changed, 31 insertions(+), 56 deletions(-) diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java index 13f7910fb2f..e108cf4901b 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java @@ -12,8 +12,6 @@ import org.drools.core.impl.KnowledgeBaseImpl; import org.drools.core.impl.RuleBaseFactory; import org.drools.core.reteoo.CoreComponentFactory; -import org.drools.core.reteoo.LeftTuple; -import org.drools.core.reteoo.MockLeftTupleSink; import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.SequenceNode; import org.drools.base.reteoo.DynamicFilterProto; @@ -113,29 +111,6 @@ public static BuildContext createContext() { } void createSession() { - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.NO); - sessionConf.setClockType(ClockType.PSEUDO_CLOCK); - - if (session != null) { - nodeMemory = null; - sequencerMemory = null; - session.dispose(); - session = null; - } - - session = (StatefulKnowledgeSessionImpl) kbase.newKieSession(sessionConf, null); - - InternalFactHandle fhA0 = (InternalFactHandle) session.insert(new A(0)); - nodeMemory = session.getNodeMemory(snode); - LeftTuple lt = new LeftTuple(fhA0, snode, true); - lt.setContextObject(snode.createSequencerMemory(lt, new MockLeftTupleSink(buildContext.getNextNodeId(), buildContext), nodeMemory)); - nodeMemory.getLeftTupleMemory().add(lt); - sequencerMemory = (SequencerMemory) lt.getContextObject(); - } - - void createSession2() { SessionConfiguration sessionConf = kbase.getSessionConfiguration(); sessionConf.setOption(ThreadSafeOption.NO); sessionConf.setClockType(ClockType.PSEUDO_CLOCK); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java index b9a6ead02e3..bf8f4f1ef09 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java @@ -61,7 +61,7 @@ public void setup() { rule.addSequence(seq0); kbase.addPackage(pkg); - createSession2(); + createSession(); } private LogicCircuit getLogicCircuit() { diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java index 2a23ca84cac..560da726b39 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java @@ -66,7 +66,7 @@ public void setup() { rule.addSequence(seq0); kbase.addPackage(pkg); - createSession2(); + createSession(); sequenceMemory = sequencerMemory.getSequenceMemory(seq0); } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java index 0e8e8cc1b30..39847f2a516 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java @@ -78,7 +78,7 @@ public void setup() { rule.addSequence(seq0); kbase.addPackage(pkg); - createSession2(); + createSession(); } private LogicCircuit getLogicCircuit() { diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java index b2d4be072a7..61c67d1566b 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java @@ -56,7 +56,7 @@ public void setup() { rule.addSequence(seq0); kbase.addPackage(pkg); - createSession2(); + createSession(); } private LogicCircuit getLogicCircuit() { diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java index 794118999a7..85055b1053b 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java @@ -59,7 +59,7 @@ public void testAnd() { rule.addSequence(seq); kbase.addPackage(pkg); - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 @@ -67,7 +67,7 @@ public void testAnd() { assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated // reverse B and C - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); @@ -92,14 +92,14 @@ public void testOr() { rule.addSequence(seq); kbase.addPackage(pkg); - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated // reverse B and C - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); @@ -131,7 +131,7 @@ public void testComposite() { kbase.addPackage(pkg); // D last - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 @@ -143,7 +143,7 @@ public void testComposite() { assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated // change order, D first - createSession2(); + createSession(); fhD0 = (InternalFactHandle) session.insert(new D(0, "d")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java index 9e3e834cdc1..68b9d4a4578 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java @@ -67,7 +67,7 @@ public void testSequenceLoopConstraint() { rule.addSequence(seq0); kbase.addPackage(pkg); - createSession2(); + createSession(); ArrayList stack = sequencerMemory.getSequenceStack(); assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(0); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java index a165a0d232d..ddbe5f6b024 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java @@ -69,7 +69,7 @@ public void testSequenceTimeout() { rule.addSequence(seq0); kbase.addPackage(pkg); - createSession2(); + createSession(); ArrayList stack = sequencerMemory.getSequenceStack(); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); @@ -86,7 +86,7 @@ public void testSequenceComplete() { rule.addSequence(seq0); kbase.addPackage(pkg); - createSession2(); + createSession(); ArrayList stack = sequencerMemory.getSequenceStack(); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java index 881572c5ea1..c54a361b7be 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java @@ -65,7 +65,7 @@ public void testEventCountEqual() { rule.addSequence(seq); kbase.addPackage(pkg); - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -95,7 +95,7 @@ public void testEventCountLessThan() { rule.addSequence(seq); kbase.addPackage(pkg); - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -105,7 +105,7 @@ public void testEventCountLessThan() { InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); - createSession2(); // fail + createSession(); // fail assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -135,7 +135,7 @@ public void testEventCountBetween() { rule.addSequence(seq); kbase.addPackage(pkg); - createSession2(); // pass + createSession(); // pass assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -146,7 +146,7 @@ public void testEventCountBetween() { InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); - createSession2(); // fail + createSession(); // fail assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -173,7 +173,7 @@ public void testSingleOutputCounter() { rule.addSequence(seq); kbase.addPackage(pkg); - createSession2(); // pass + createSession(); // pass SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq); @@ -229,7 +229,7 @@ public void testCompositeInputAndOutputCounters() { kbase.addPackage(pkg); // D First - createSession2(); + createSession(); SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq); InternalFactHandle fhD0 = (InternalFactHandle) session.insert(new D(0, "d")); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java index 374d273458a..cac7c16c2ad 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java @@ -67,7 +67,7 @@ public void testTimeout() { rule.addSequence(seq); kbase.addPackage(pkg); - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); @@ -76,7 +76,7 @@ public void testTimeout() { session.fireAllRules(); // if the rest of the system is immediate, why isn't this? assertThat(pseudo.getQueue().size()).isEqualTo(0); - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); pseudo = (PseudoClockScheduler) session.getTimerService(); @@ -110,7 +110,7 @@ public void testTimeoutWithCountFailure() { rule.addSequence(seq); kbase.addPackage(pkg); - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -154,7 +154,7 @@ public void testDelayFromActivation() { rule.addSequence(seq); kbase.addPackage(pkg); - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -165,7 +165,7 @@ public void testDelayFromActivation() { session.fireAllRules(); // if the rest of the system is immediate, why isn't this? assertThat(pseudo.getQueue().size()).isEqualTo(0); - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -194,7 +194,7 @@ public void testDelayFromMatch() { rule.addSequence(seq); kbase.addPackage(pkg); - createSession2(); + createSession(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java index e93c914a47f..00d4e1034c2 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java @@ -84,7 +84,7 @@ public void testSubSequence() { seq2.setController(new LoopController(m -> m.getCount() < 2)); kbase.addPackage(pkg); - createSession2(); + createSession(); ArrayList stack = sequencerMemory.getSequenceStack(); assertThat(stack.size()).isEqualTo(2); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java index 3a497de2a57..14c451e4d8c 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java @@ -65,7 +65,7 @@ public void setup() { rule.addSequence(seq0); kbase.addPackage(pkg); - createSession2(); + createSession(); } private static LogicGate get1InputLogicGate() { diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java index 3a31220ab60..f112e9ac01d 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java @@ -86,7 +86,7 @@ public void setup() { @Test public void testSubSequenceFailSeq1() { seq1.setController(new TimoutController(new DurationTimer(1000))); - createSession2(); + createSession(); ArrayList stack = sequencerMemory.getSequenceStack(); assertThat(stack.size()).isEqualTo(2); @@ -108,7 +108,7 @@ public void testSubSequenceFailSeq1() { public void testSubSequenceFailSeq2() { seq1.setController(new TimoutController(new DurationTimer(1000))); seq2.setController(new TimoutController(new DurationTimer(1000))); - createSession2(); + createSession(); ArrayList stack = sequencerMemory.getSequenceStack(); assertThat(stack.size()).isEqualTo(2); @@ -139,7 +139,7 @@ public void testSubSequenceFailSeq2() { public void testSubSequenceComplete() { seq1.setController(new TimoutController(new DurationTimer(1000))); seq2.setController(new TimoutController(new DurationTimer(1000))); - createSession2(); + createSession(); ArrayList stack = sequencerMemory.getSequenceStack(); assertThat(stack.size()).isEqualTo(2);