Skip to content

Commit

Permalink
Removing use of InternalRuleBase (apache#5577)
Browse files Browse the repository at this point in the history
  • Loading branch information
pibizza authored and rgdoliveira committed Jan 16, 2024
1 parent 26ece0f commit ce7c76f
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 41 deletions.
27 changes: 27 additions & 0 deletions drools-base/src/main/java/org/drools/base/RuleBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@
package org.drools.base;


import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.Future;

import org.drools.base.definitions.InternalKnowledgePackage;
import org.drools.base.definitions.rule.impl.RuleImpl;
import org.drools.base.rule.InvalidPatternException;
import org.drools.base.rule.TypeDeclaration;
import org.kie.api.KieBaseConfiguration;
import org.kie.api.definition.KiePackage;

public interface RuleBase {
ClassLoader getRootClassLoader();
Expand All @@ -30,4 +39,22 @@ public interface RuleBase {
TypeDeclaration getTypeDeclaration(Class<?> classType);

KieBaseConfiguration getConfiguration();

InternalKnowledgePackage[] getPackages();
InternalKnowledgePackage getPackage(String name);
Future<KiePackage> addPackage(KiePackage pkg );
void addPackages( Collection<? extends KiePackage> newPkgs );
Map<String, InternalKnowledgePackage> getPackagesMap();

void addRules( Collection<RuleImpl> rules ) throws InvalidPatternException;
void removeRules( Collection<RuleImpl> rules ) throws InvalidPatternException;

String getId();

String getContainerId();
void setContainerId(String containerId);

Map<String, Type> getGlobals();


}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.ForkJoinPool;
import java.util.function.Supplier;

import org.drools.base.RuleBase;
import org.drools.base.base.ObjectType;
import org.drools.base.definitions.InternalKnowledgePackage;
import org.drools.base.definitions.rule.impl.RuleImpl;
Expand All @@ -60,7 +61,6 @@
import org.drools.compiler.compiler.ResourceTypeDeclarationWarning;
import org.drools.compiler.kie.builder.impl.BuildContext;
import org.drools.compiler.lang.descr.CompositePackageDescr;
import org.drools.core.impl.InternalRuleBase;
import org.drools.core.impl.RuleBaseFactory;
import org.drools.drl.ast.descr.AttributeDescr;
import org.drools.drl.ast.descr.ImportDescr;
Expand Down Expand Up @@ -941,7 +941,7 @@ public KieBase newKnowledgeBase(KieBaseConfiguration conf) {
}
throw new IllegalArgumentException("Could not parse knowledge. See the logs for details.");
}
InternalRuleBase kbase = RuleBaseFactory.newRuleBase(conf);
RuleBase kbase = RuleBaseFactory.newRuleBase(conf);
kbase.addPackages(asList(getPackages()));
return KnowledgeBaseFactory.newKnowledgeBase(kbase);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@
import java.util.ArrayList;
import java.util.Collection;

import org.drools.base.definitions.InternalKnowledgePackage;
import org.drools.base.definitions.rule.impl.RuleImpl;
import org.drools.base.RuleBase;
import org.drools.compiler.builder.impl.AssetFilter;
import org.drools.compiler.compiler.PackageRegistry;
import org.drools.core.impl.InternalRuleBase;
import org.drools.base.definitions.InternalKnowledgePackage;
import org.drools.base.definitions.rule.impl.RuleImpl;
import org.drools.drl.ast.descr.PackageDescr;
import org.drools.drl.ast.descr.RuleDescr;
import org.kie.internal.builder.ResourceChange;

public class ReteCompiler extends AbstractPackageCompilationPhase {
private final AssetFilter assetFilter;
private InternalRuleBase kBase;
private RuleBase kBase;

public ReteCompiler(PackageRegistry pkgRegistry, PackageDescr packageDescr, InternalRuleBase kBase, AssetFilter assetFilter) {
public ReteCompiler(PackageRegistry pkgRegistry, PackageDescr packageDescr, RuleBase kBase, AssetFilter assetFilter) {
super(pkgRegistry, packageDescr);
this.kBase = kBase;
this.assetFilter = assetFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
import org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl;
import org.drools.compiler.kproject.models.KieBaseModelImpl;
import org.drools.core.RuleBaseConfiguration;
import org.drools.core.impl.InternalRuleBase;
import org.drools.base.definitions.InternalKnowledgePackage;
import org.drools.base.definitions.impl.KnowledgePackageImpl;
import org.drools.core.impl.RuleBaseFactory;
import org.drools.io.ResourceConfigurationImpl;
import org.drools.kiesession.rulebase.InternalKnowledgeBase;
Expand Down Expand Up @@ -69,6 +70,7 @@
import org.kie.util.maven.support.ReleaseIdImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.drools.base.RuleBase;

import static org.kie.internal.builder.KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration;

Expand Down Expand Up @@ -220,7 +222,7 @@ public InternalKnowledgeBase createKieBase(KieBaseModelImpl kBaseModel, KieProje
((RuleBaseConfiguration)conf).setClassLoader(cl);
}

InternalRuleBase kBase = RuleBaseFactory.newRuleBase(kBaseModel.getName(), conf);
RuleBase kBase = RuleBaseFactory.newRuleBase(kBaseModel.getName(), conf);
kBase.addPackages( pkgs );
return KnowledgeBaseFactory.newKnowledgeBase(kBase);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import javax.management.ObjectName;

import org.drools.base.RuleBase;
import org.drools.compiler.builder.InternalKnowledgeBuilder;
import org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl;
import org.drools.compiler.kie.builder.MaterializedLambda;
Expand All @@ -41,7 +42,6 @@
import org.drools.compiler.management.KieContainerMonitor;
import org.drools.core.SessionConfiguration;
import org.drools.core.impl.InternalKieContainer;
import org.drools.core.impl.InternalRuleBase;
import org.drools.core.management.DroolsManagementAgent;
import org.drools.core.management.DroolsManagementAgent.CBSKey;
import org.drools.core.reteoo.RuntimeComponentFactory;
Expand Down Expand Up @@ -735,10 +735,10 @@ public void dispose() {
Set<DroolsManagementAgent.CBSKey> cbskeys = new HashSet<>();
if ( isMBeanOptionEnabled() ) {
for (Entry<String, KieSession> kv : kSessions.entrySet()) {
cbskeys.add(new DroolsManagementAgent.CBSKey(containerId, ((InternalRuleBase) kv.getValue().getKieBase()).getId(), kv.getKey()));
cbskeys.add(new DroolsManagementAgent.CBSKey(containerId, ((RuleBase) kv.getValue().getKieBase()).getId(), kv.getKey()));
}
for (Entry<String, StatelessKieSession> kv : statelessKSessions.entrySet()) {
cbskeys.add(new DroolsManagementAgent.CBSKey(containerId, ((InternalRuleBase) kv.getValue().getKieBase()).getId(), kv.getKey()));
cbskeys.add(new DroolsManagementAgent.CBSKey(containerId, ((RuleBase) kv.getValue().getKieBase()).getId(), kv.getKey()));
}
}

Expand All @@ -753,7 +753,7 @@ public void dispose() {
DroolsManagementAgent.getInstance().unregisterKnowledgeSessionBean(c);
}
for (KieBase kb : kBases.values()) {
DroolsManagementAgent.getInstance().unregisterKnowledgeBase((InternalRuleBase) kb);
DroolsManagementAgent.getInstance().unregisterKnowledgeBase((RuleBase) kb);
}
DroolsManagementAgent.getInstance().unregisterMBeansFromOwner(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;

import org.drools.base.RuleBase;
import org.drools.base.common.RuleBasePartitionId;
Expand Down Expand Up @@ -80,7 +78,6 @@ public interface InternalRuleBase extends RuleBase {

Set<String> getEntryPointIds();

String getId();

RuleBasePartitionId createNewPartitionId();
boolean isPartitioned();
Expand All @@ -99,7 +96,6 @@ public interface InternalRuleBase extends RuleBase {

FactHandleFactory newFactHandleFactory(long id, long counter) throws IOException;

Map<String, Type> getGlobals();

int getNodeCount();
int getMemoryCount();
Expand All @@ -120,11 +116,6 @@ public interface InternalRuleBase extends RuleBase {

Class<?> registerAndLoadTypeDefinition( String className, byte[] def ) throws ClassNotFoundException;

InternalKnowledgePackage[] getPackages();
InternalKnowledgePackage getPackage(String name);
Future<KiePackage> addPackage(KiePackage pkg );
void addPackages( Collection<? extends KiePackage> newPkgs );
Map<String, InternalKnowledgePackage> getPackagesMap();

ClassFieldAccessorCache getClassFieldAccessorCache();

Expand All @@ -141,9 +132,6 @@ public interface InternalRuleBase extends RuleBase {

void processAllTypesDeclaration( Collection<InternalKnowledgePackage> pkgs );

void addRules( Collection<RuleImpl> rules ) throws InvalidPatternException;
void removeRules( Collection<RuleImpl> rules ) throws InvalidPatternException;

default void beforeIncrementalUpdate(KieBaseUpdate kieBaseUpdate) { }
default void afterIncrementalUpdate(KieBaseUpdate kieBaseUpdate) { }

Expand All @@ -160,8 +148,6 @@ default void afterIncrementalUpdate(KieBaseUpdate kieBaseUpdate) { }

ReleaseId getResolvedReleaseId();
void setResolvedReleaseId(ReleaseId currentReleaseId);
String getContainerId();
void setContainerId(String containerId);

RuleUnitDescriptionRegistry getRuleUnitDescriptionRegistry();
boolean hasUnits();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import javax.management.ObjectName;
import javax.management.StandardMBean;

import org.drools.base.RuleBase;
import org.drools.core.common.InternalWorkingMemory;
import org.drools.core.impl.InternalRuleBase;
import org.drools.core.reteoo.RuntimeComponentFactory;
import org.kie.api.builder.model.KieSessionModel;
import org.kie.api.event.KieRuntimeEventManager;
Expand Down Expand Up @@ -59,7 +59,7 @@ static DroolsManagementAgent getInstance() {
return DroolsManagementAgentHolder.INSTANCE;
}

static ObjectName createObjectNameFor(InternalRuleBase kbase) {
static ObjectName createObjectNameFor(RuleBase kbase) {
return DroolsManagementAgent.createObjectName(
DroolsManagementAgent.createObjectNameBy(kbase.getContainerId())
+ ",kbaseId=" + ObjectName.quote(kbase.getId())
Expand Down Expand Up @@ -101,9 +101,9 @@ static String ksessionType(KieSessionModel.KieSessionType ksessionType) {

long getNextKnowledgeSessionId();

void registerKnowledgeBase(InternalRuleBase kbase);
void registerKnowledgeBase(RuleBase kbase);

void unregisterKnowledgeBase(InternalRuleBase kbase);
void unregisterKnowledgeBase(RuleBase kbase);

void registerKnowledgeSessionUnderName(CBSKey cbsKey, KieRuntimeEventManager ksession);

Expand Down Expand Up @@ -240,15 +240,15 @@ public synchronized long getNextKnowledgeSessionId() {
}

@Override
public void registerKnowledgeBase(InternalRuleBase kbase) {
public void registerKnowledgeBase(RuleBase kbase) {
KnowledgeBaseMonitoring mbean = new KnowledgeBaseMonitoring( kbase );
registerMBean( kbase,
mbean,
mbean.getName() );
}

@Override
public void unregisterKnowledgeBase(InternalRuleBase kbase) {
public void unregisterKnowledgeBase(RuleBase kbase) {
unregisterMBeansFromOwner(kbase);
}

Expand Down Expand Up @@ -417,12 +417,12 @@ public long getNextKnowledgeSessionId() {
}

@Override
public void registerKnowledgeBase(InternalRuleBase kbase) {
public void registerKnowledgeBase(RuleBase kbase) {

}

@Override
public void unregisterKnowledgeBase(InternalRuleBase kbase) {
public void unregisterKnowledgeBase(RuleBase kbase) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;

import org.drools.base.RuleBase;
import org.drools.core.impl.InternalRuleBase;
import org.drools.core.reteoo.EntryPointNode;
import org.drools.core.reteoo.ObjectTypeNode;
Expand Down Expand Up @@ -114,8 +115,8 @@ public class KnowledgeBaseMonitoring
// ************************************************************************************************

// Constructor
public KnowledgeBaseMonitoring(InternalRuleBase kbase) {
this.kbase = kbase;
public KnowledgeBaseMonitoring(RuleBase kbase) {
this.kbase = (InternalRuleBase) kbase;
this.name = DroolsManagementAgent.createObjectNameFor(kbase);

initOpenMBeanInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
package org.drools.kiesession.rulebase;

import org.drools.core.impl.KnowledgeBaseImpl;
import org.drools.core.impl.InternalRuleBase;
import org.kie.api.KieBaseConfiguration;
import org.kie.internal.conf.CompositeBaseConfiguration;
import org.drools.base.RuleBase;

public class KnowledgeBaseFactory {

Expand All @@ -37,7 +37,7 @@ public static InternalKnowledgeBase newKnowledgeBase(String kbaseId, KieBaseConf
return newKnowledgeBase(new KnowledgeBaseImpl(kbaseId, (CompositeBaseConfiguration) conf));
}

public static InternalKnowledgeBase newKnowledgeBase(InternalRuleBase delegate) {
public static InternalKnowledgeBase newKnowledgeBase(RuleBase delegate) {
return new SessionsAwareKnowledgeBase(delegate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.drools.kiesession.rulebase;

import org.drools.base.RuleBase;
import org.drools.base.common.RuleBasePartitionId;
import org.drools.base.definitions.InternalKnowledgePackage;
import org.drools.base.definitions.rule.impl.RuleImpl;
Expand All @@ -32,7 +33,6 @@
import org.drools.core.common.ReteEvaluator;
import org.drools.core.impl.EnvironmentFactory;
import org.drools.core.impl.InternalKieContainer;
import org.drools.core.impl.InternalRuleBase;
import org.drools.core.impl.KieBaseUpdate;
import org.drools.core.impl.KnowledgeBaseImpl;
import org.drools.core.impl.RuleBaseFactory;
Expand Down Expand Up @@ -108,7 +108,7 @@ public SessionsAwareKnowledgeBase(KieBaseConfiguration kbaseConfiguration) {
this(RuleBaseFactory.newRuleBase(kbaseConfiguration));
}

public SessionsAwareKnowledgeBase(InternalRuleBase delegate) {
public SessionsAwareKnowledgeBase(RuleBase delegate) {
this.delegate = (KnowledgeBaseImpl) delegate;

if (this.delegate.getRuleBaseConfiguration().getSessionPoolSize() > 0) {
Expand Down

0 comments on commit ce7c76f

Please sign in to comment.