Skip to content

Commit

Permalink
[DROOLS-1583] remove redundant methods and review locks on KnowledgeB…
Browse files Browse the repository at this point in the history
…aseImpl (apache#1315)
  • Loading branch information
mariofusco committed Jun 9, 2017
1 parent c999f53 commit efae52f
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 1,107 deletions.
Expand Up @@ -36,6 +36,7 @@
import java.util.Set; import java.util.Set;
import java.util.Stack; import java.util.Stack;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier; import java.util.function.Supplier;


import org.drools.compiler.compiler.AnnotationDeclarationError; import org.drools.compiler.compiler.AnnotationDeclarationError;
Expand Down Expand Up @@ -1148,8 +1149,7 @@ private Map<String, RuleBuildContext> preProcessRules(PackageDescr packageDescr,
} }


if (needsRemoval) { if (needsRemoval) {
try { kBase.enqueueModification( () -> {
this.kBase.lock();
for( org.kie.api.definition.rule.Rule rule : pkg.getRules() ) { for( org.kie.api.definition.rule.Rule rule : pkg.getRules() ) {
if (filterAcceptsRemoval( ResourceChange.Type.RULE, rule.getPackageName(), rule.getName() ) ) { if (filterAcceptsRemoval( ResourceChange.Type.RULE, rule.getPackageName(), rule.getName() ) ) {
this.kBase.removeRule(pkg, pkg.getRule(rule.getName())); this.kBase.removeRule(pkg, pkg.getRule(rule.getName()));
Expand All @@ -1169,9 +1169,7 @@ private Map<String, RuleBuildContext> preProcessRules(PackageDescr packageDescr,
if (!rulesToBeRemoved.isEmpty()) { if (!rulesToBeRemoved.isEmpty()) {
kBase.removeRules( pkg, rulesToBeRemoved ); kBase.removeRules( pkg, rulesToBeRemoved );
} }
} finally { } );
this.kBase.unlock();
}
} }
} }


Expand Down Expand Up @@ -1580,13 +1578,10 @@ public PackageRegistry newPackage(final PackageDescr packageDescr) {


// if there is a rulebase then add the package. // if there is a rulebase then add the package.
if (this.kBase != null) { if (this.kBase != null) {
// Must lock here, otherwise the assumption about addPackage/getPackage behavior below might be violated
this.kBase.lock();
try { try {
this.kBase.addPackage(pkg); pkg = (InternalKnowledgePackage) this.kBase.addPackage(pkg).get();
pkg = this.kBase.getPackage(packageDescr.getName()); } catch (InterruptedException | ExecutionException e) {
} finally { throw new RuntimeException( e );
this.kBase.unlock();
} }
} else { } else {
// the RuleBase will also initialise the // the RuleBase will also initialise the
Expand Down
Expand Up @@ -260,13 +260,8 @@ private Results update(final InternalKieModule currentKM, final ReleaseId newRel
kbasesToRemove.add( kbaseName ); kbasesToRemove.add( kbaseName );
} else { } else {
final InternalKnowledgeBase kBase = (InternalKnowledgeBase) kBaseEntry.getValue(); final InternalKnowledgeBase kBase = (InternalKnowledgeBase) kBaseEntry.getValue();
kBase.enqueueModification( new Runnable() { kBase.enqueueModification( () -> updateKBase( kBase, currentKM, newReleaseId, newKM, cs, modifiedClasses, modifyingUsedClass,
@Override unchangedResources, results, newKieBaseModel, currentKieBaseModel ) );
public void run() {
updateKBase( kBase, currentKM, newReleaseId, newKM, cs, modifiedClasses, modifyingUsedClass,
unchangedResources, results, newKieBaseModel, currentKieBaseModel);
}
} );
} }
} }


Expand Down
Expand Up @@ -182,7 +182,7 @@ public void testReload() throws Exception {
builder.getErrors().getErrors() ); builder.getErrors().getErrors() );


InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase(); InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.getGlobals().put( "map", Map.class ); kBase.addGlobal( "map", Map.class );
final KieSession workingMemory = kBase.newKieSession(); final KieSession workingMemory = kBase.newKieSession();


final HashMap map = new HashMap(); final HashMap map = new HashMap();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit efae52f

Please sign in to comment.