use of org.drools.modelcompiler.CanonicalKieModule in project drools by kiegroup.
the class BuildtimeUtil method generateKJarFromKieBuilder.
public static void generateKJarFromKieBuilder(final KieBuilder kieBuilder, final boolean useCanonicalModel) throws IOException {
final ReleaseId releaseId = kieBuilder.getKieModule().getReleaseId();
final InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModule();
final File kjarFile = bytesToTempFile(releaseId, kieModule.getBytes(), ".jar");
final KieModule zipKieModule;
if (useCanonicalModel) {
zipKieModule = new CanonicalKieModule(releaseId, kieModule.getKieModuleModel(), kjarFile);
} else {
zipKieModule = new ZipKieModule(releaseId, kieModule.getKieModuleModel(), kjarFile);
}
KieServices.get().getRepository().addKieModule(zipKieModule);
}
use of org.drools.modelcompiler.CanonicalKieModule in project drools by kiegroup.
the class BuildFromKJarBenchmark method buildKnowledge.
@Benchmark
public KieBase buildKnowledge(final Blackhole eater) {
final KieModule zipKieModule = type.useRuleModel ? new CanonicalKieModule(releaseId, kieModuleModel, kjarFiles.getJarFile(), kjarFiles.getKnowledgeFiles()) : new ZipKieModule(releaseId, kieModuleModel, kjarFiles.getJarFile());
kieRepository.addKieModule(zipKieModule);
if (eater != null) {
eater.consume(zipKieModule);
}
return kieServices.newKieContainer(releaseId).getKieBase();
}
use of org.drools.modelcompiler.CanonicalKieModule in project drools by kiegroup.
the class CanonicalKieBaseUpdater method run.
@Override
public void run() {
CanonicalKieModule oldKM = (CanonicalKieModule) ctx.currentKM;
CanonicalKieModule newKM = (CanonicalKieModule) ctx.newKM;
List<RuleImpl> rulesToBeRemoved;
List<RuleImpl> rulesToBeAdded;
if (ctx.modifyingUsedClass) {
// remove all ObjectTypeNodes for the modified classes
for (Class<?> cls : ctx.modifiedClasses) {
clearInstancesOfModifiedClass(cls);
}
rulesToBeRemoved = getAllRulesInKieBase(oldKM, ctx.currentKieBaseModel);
rulesToBeAdded = getAllRulesInKieBase(newKM, ctx.newKieBaseModel);
} else {
newKM.setModuleClassLoader(((CanonicalKieModule) ctx.currentKM).getModuleClassLoader());
CanonicalKiePackages newPkgs = newKM.getKiePackages(ctx.newKieBaseModel);
rulesToBeRemoved = new ArrayList<>();
rulesToBeAdded = new ArrayList<>();
for (ResourceChangeSet changeSet : ctx.cs.getChanges().values()) {
if (!isPackageInKieBase(ctx.newKieBaseModel, changeSet.getResourceName())) {
continue;
}
InternalKnowledgePackage oldKpkg = ctx.kBase.getPackage(changeSet.getResourceName());
InternalKnowledgePackage kpkg = (InternalKnowledgePackage) newPkgs.getKiePackage(changeSet.getResourceName());
for (ResourceChange change : changeSet.getChanges()) {
String changedItemName = change.getName();
if (change.getChangeType() == ChangeType.UPDATED || change.getChangeType() == ChangeType.REMOVED) {
if (change.getType() == ResourceChange.Type.GLOBAL) {
ctx.kBase.removeGlobal(changedItemName);
} else {
rulesToBeRemoved.add(oldKpkg.getRule(changedItemName));
}
}
if (change.getChangeType() == ChangeType.UPDATED || change.getChangeType() == ChangeType.ADDED) {
if (change.getType() == ResourceChange.Type.GLOBAL) {
try {
ctx.kBase.addGlobal(changedItemName, kpkg.getTypeResolver().resolveType(kpkg.getGlobals().get(changedItemName)));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
} else {
rulesToBeAdded.add(kpkg.getRule(changedItemName));
}
}
}
}
}
ctx.kBase.removeRules(rulesToBeRemoved);
ctx.kBase.addRules(rulesToBeAdded);
}
use of org.drools.modelcompiler.CanonicalKieModule in project drools by kiegroup.
the class KieBaseUtil method generateKieModuleForCanonicalModel.
private static void generateKieModuleForCanonicalModel(KieBuilder kieBuilder) {
KieServices ks = KieServices.get();
ReleaseId releaseId = kieBuilder.getKieModule().getReleaseId();
InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModule();
File kjarFile = FileUtil.bytesToTempKJARFile(releaseId, kieModule.getBytes(), ".jar");
KieModule zipKieModule = new CanonicalKieModule(releaseId, KieUtil.getDefaultKieModuleModel(ks), kjarFile);
ks.getRepository().addKieModule(zipKieModule);
}
use of org.drools.modelcompiler.CanonicalKieModule in project drools by kiegroup.
the class KieUtil method buildAndInstallKieModuleIntoRepo.
public static KieModule buildAndInstallKieModuleIntoRepo(final KieBaseTestConfiguration kieBaseTestConfiguration, final ReleaseId releaseId, final KieModuleModel kieModuleModel, final Resource... resources) {
final KieServices kieServices = KieServices.Factory.get();
final KieFileSystem fileSystem = getKieFileSystemWithKieModule(kieModuleModel, releaseId, resources);
final KieBuilder builder = getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, fileSystem, true);
KieModule kieModule = builder.getKieModule();
if (kieBaseTestConfiguration.useCanonicalModel()) {
final File kjarFile = FileUtil.bytesToTempKJARFile(releaseId, ((InternalKieModule) kieModule).getBytes(), ".jar");
kieModule = new CanonicalKieModule(releaseId, kieModuleModel, kjarFile);
}
kieServices.getRepository().addKieModule(kieModule);
return kieModule;
}
Aggregations