From 94f1493d0bd7e26ef79a1cbac53c84cc6e662616 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Tue, 7 Jul 2020 12:42:30 +0900 Subject: [PATCH] - move collectRules to CountBasedOrderingStrategy --- .../core/addon/AlphaNodeOrderingStrategy.java | 7 ++++--- .../core/addon/CountBasedOrderingStrategy.java | 14 +++++++++++++- .../drools/core/addon/NoopOrderingStrategy.java | 7 ++++--- .../org/drools/core/impl/KnowledgeBaseImpl.java | 10 +--------- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/drools-core/src/main/java/org/drools/core/addon/AlphaNodeOrderingStrategy.java b/drools-core/src/main/java/org/drools/core/addon/AlphaNodeOrderingStrategy.java index 9d44fc6e194..d749bcf8437 100644 --- a/drools-core/src/main/java/org/drools/core/addon/AlphaNodeOrderingStrategy.java +++ b/drools-core/src/main/java/org/drools/core/addon/AlphaNodeOrderingStrategy.java @@ -15,13 +15,14 @@ package org.drools.core.addon; +import java.util.Collection; import java.util.List; -import java.util.Set; +import java.util.Map; +import org.drools.core.definitions.InternalKnowledgePackage; import org.drools.core.spi.AlphaNodeFieldConstraint; import org.drools.core.spi.ObjectType; import org.kie.api.conf.AlphaNodeOrderingOption; -import org.kie.api.definition.rule.Rule; /** * @@ -31,7 +32,7 @@ */ public interface AlphaNodeOrderingStrategy { - void analyzeAlphaConstraints(Set ruleSet); + void analyzeAlphaConstraints(Map pkgs, Collection newPkgs); void reorderAlphaConstraints(List alphaConstraints, ObjectType objectType); diff --git a/drools-core/src/main/java/org/drools/core/addon/CountBasedOrderingStrategy.java b/drools-core/src/main/java/org/drools/core/addon/CountBasedOrderingStrategy.java index c72b6e34d60..8fa3aa8413c 100644 --- a/drools-core/src/main/java/org/drools/core/addon/CountBasedOrderingStrategy.java +++ b/drools-core/src/main/java/org/drools/core/addon/CountBasedOrderingStrategy.java @@ -16,12 +16,15 @@ package org.drools.core.addon; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import org.drools.core.definitions.InternalKnowledgePackage; import org.drools.core.definitions.rule.impl.RuleImpl; import org.drools.core.rule.Accumulate; import org.drools.core.rule.Collect; @@ -48,7 +51,9 @@ public class CountBasedOrderingStrategy implements AlphaNodeOrderingStrategy { private Map> analyzedAlphaConstraints = new HashMap<>(); @Override - public void analyzeAlphaConstraints(Set ruleSet) { + public void analyzeAlphaConstraints(Map pkgs, Collection newPkgs) { + + Set ruleSet = collectRules(pkgs, newPkgs); List patternList = new ArrayList<>(); ruleSet.stream() @@ -68,6 +73,13 @@ public void analyzeAlphaConstraints(Set ruleSet) { logger.trace("analyzedAlphaConstraints : {}", analyzedAlphaConstraints); } + private Set collectRules(Map pkgs, Collection newPkgs) { + Set ruleSet = new HashSet<>(); + pkgs.forEach((pkgName, pkg) -> ruleSet.addAll(pkg.getRules())); + newPkgs.forEach(pkg -> ruleSet.addAll(pkg.getRules())); // okay to overwrite + return ruleSet; + } + private void collectPatterns(GroupElement ge, List patternList) { List children = ge.getChildren(); for (RuleConditionElement child : children) { diff --git a/drools-core/src/main/java/org/drools/core/addon/NoopOrderingStrategy.java b/drools-core/src/main/java/org/drools/core/addon/NoopOrderingStrategy.java index bf818f914bb..c88310e7c20 100644 --- a/drools-core/src/main/java/org/drools/core/addon/NoopOrderingStrategy.java +++ b/drools-core/src/main/java/org/drools/core/addon/NoopOrderingStrategy.java @@ -15,17 +15,18 @@ package org.drools.core.addon; +import java.util.Collection; import java.util.List; -import java.util.Set; +import java.util.Map; +import org.drools.core.definitions.InternalKnowledgePackage; import org.drools.core.spi.AlphaNodeFieldConstraint; import org.drools.core.spi.ObjectType; -import org.kie.api.definition.rule.Rule; public class NoopOrderingStrategy implements AlphaNodeOrderingStrategy { @Override - public void analyzeAlphaConstraints(Set ruleSet) { + public void analyzeAlphaConstraints(Map pkgs, Collection newPkgs) { // no op } 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 829776dbf3a..558d4d1087b 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 @@ -55,7 +55,6 @@ import org.drools.core.common.InternalWorkingMemory; import org.drools.core.common.RuleBasePartitionId; import org.drools.core.definitions.InternalKnowledgePackage; -import org.drools.core.definitions.impl.KnowledgePackageImpl; import org.drools.core.definitions.rule.impl.RuleImpl; import org.drools.core.event.KieBaseEventSupport; import org.drools.core.factmodel.ClassDefinition; @@ -850,7 +849,7 @@ private void internalAddPackages(Collection clonedPkgs wm.flushPropagations(); } - alphaNodeOrderingStrategy.analyzeAlphaConstraints(collectRules(pkgs, clonedPkgs)); + alphaNodeOrderingStrategy.analyzeAlphaConstraints(pkgs, clonedPkgs); // we need to merge all byte[] first, so that the root classloader can resolve classes for (InternalKnowledgePackage newPkg : clonedPkgs) { @@ -961,13 +960,6 @@ private void internalAddPackages(Collection clonedPkgs } } - private Set collectRules(Map pkgs, Collection newPkgs) { - Set ruleSet = new HashSet<>(); - pkgs.forEach((pkgName, pkg) -> ruleSet.addAll(pkg.getRules())); - newPkgs.forEach(pkg -> ruleSet.addAll(pkg.getRules())); // okay to overwrite - return ruleSet; - } - public void processAllTypesDeclaration( Collection pkgs ) { List allTypeDeclarations = new ArrayList<>(); // Add all Type Declarations, this has to be done first incase packages cross reference each other during build process.