Search in sources :

Example 1 with KieBaseUpdaters

use of org.drools.compiler.kie.builder.impl.KieBaseUpdaters in project drools by kiegroup.

the class CanonicalKieModule method afterKieBaseCreationUpdate.

@Override
public void afterKieBaseCreationUpdate(String name, InternalKnowledgeBase kBase) {
    KnowledgeBuilder knowledgeBuilderForKieBase = getKnowledgeBuilderForKieBase(name);
    final List<KieBaseUpdaterOptions.OptionEntry> options;
    if (knowledgeBuilderForKieBase instanceof KnowledgeBuilderImpl) {
        // When using executable module in tests
        KnowledgeBuilderImpl knowledgeBuilderForImpl = (KnowledgeBuilderImpl) knowledgeBuilderForKieBase;
        KnowledgeBuilderConfigurationImpl builderConfiguration = knowledgeBuilderForImpl.getBuilderConfiguration();
        options = singletonList(new KieBaseUpdaterOptions.OptionEntry(AlphaNetworkCompilerOption.class, builderConfiguration.getAlphaNetworkCompilerOption()));
    } else if (resourceFileExists(getANCFile(internalKieModule.getReleaseId()))) {
        // executable model with ANC
        options = singletonList(new KieBaseUpdaterOptions.OptionEntry(AlphaNetworkCompilerOption.class, AlphaNetworkCompilerOption.LOAD));
    } else {
        // Default case when loaded from executable model kjar
        options = emptyList();
    }
    KieContainerImpl.CompositeRunnable compositeUpdater = new KieContainerImpl.CompositeRunnable();
    KieBaseUpdaters updaters = KieService.load(KieBaseUpdaters.class);
    updaters.getChildren().stream().map(kbu -> kbu.create(new KieBaseUpdatersContext(new KieBaseUpdaterOptions(options), kBase.getRete(), kBase.getRootClassLoader()))).forEach(compositeUpdater::add);
    compositeUpdater.run();
}
Also used : InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KiePath(org.kie.memorycompiler.resources.KiePath) Arrays(java.util.Arrays) ResourceChange(org.kie.internal.builder.ResourceChange) CompositeKnowledgeBuilder(org.kie.internal.builder.CompositeKnowledgeBuilder) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) ChangeType(org.kie.internal.builder.ChangeType) KieBaseUpdatersContext(org.drools.compiler.kie.builder.impl.KieBaseUpdatersContext) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) CoreComponentFactory(org.drools.core.reteoo.CoreComponentFactory) StringUtil.fileNameToClass(org.drools.modelcompiler.util.StringUtil.fileNameToClass) ReleaseId(org.kie.api.builder.ReleaseId) DependencyFilter(org.kie.util.maven.support.DependencyFilter) Collections.singletonList(java.util.Collections.singletonList) ModelComponent.areEqualInModel(org.drools.model.impl.ModelComponent.areEqualInModel) Map(java.util.Map) KieBaseUpdaterImplContext(org.drools.compiler.kie.builder.impl.KieBaseUpdaterImplContext) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) MemoryKieModule(org.drools.compiler.kie.builder.impl.MemoryKieModule) KieModuleModelImpl(org.drools.compiler.kproject.models.KieModuleModelImpl) Predicate(java.util.function.Predicate) KieProject(org.drools.compiler.kie.builder.impl.KieProject) KieBaseModelImpl(org.drools.compiler.kproject.models.KieBaseModelImpl) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Process(org.kie.api.definition.process.Process) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) KieBaseUpdaters(org.drools.compiler.kie.builder.impl.KieBaseUpdaters) Set(java.util.Set) Results(org.kie.api.builder.Results) KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieJarChangeSet(org.drools.compiler.kie.util.KieJarChangeSet) Collectors(java.util.stream.Collectors) KieBaseUpdaterOptions(org.drools.compiler.kie.builder.impl.KieBaseUpdaterOptions) Drools(org.drools.core.util.Drools) CanonicalKieBaseUpdater(org.drools.modelcompiler.builder.CanonicalKieBaseUpdater) InvocationTargetException(java.lang.reflect.InvocationTargetException) ResourceConfiguration(org.kie.api.io.ResourceConfiguration) UncheckedIOException(java.io.UncheckedIOException) Resource(org.kie.api.io.Resource) List(java.util.List) Stream(java.util.stream.Stream) BuildContext(org.drools.compiler.kie.builder.impl.BuildContext) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) StringUtils(org.drools.core.util.StringUtils) KieBaseConfiguration(org.kie.api.KieBaseConfiguration) KnowledgeBuilderFactory(org.kie.internal.builder.KnowledgeBuilderFactory) PomModel(org.kie.util.maven.support.PomModel) ModelSourceClass.getProjectModelClassNameNameWithReleaseId(org.drools.modelcompiler.builder.ModelSourceClass.getProjectModelClassNameNameWithReleaseId) HashMap(java.util.HashMap) ResourceType(org.kie.api.io.ResourceType) AlphaNetworkCompilerOption(org.kie.internal.builder.conf.AlphaNetworkCompilerOption) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) IoUtils(org.drools.core.util.IoUtils) ResourceProvider(org.drools.wiring.api.ResourceProvider) FileKieModule(org.drools.compiler.kie.builder.impl.FileKieModule) KieBaseUpdater(org.drools.compiler.kie.builder.impl.KieBaseUpdater) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) NamedModelItem(org.drools.model.NamedModelItem) KieServices(org.kie.api.KieServices) Message(org.kie.api.builder.Message) KiePackage(org.kie.api.definition.KiePackage) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) Model(org.drools.model.Model) Iterator(java.util.Iterator) InternalResource(org.drools.core.io.internal.InternalResource) KieService(org.kie.api.internal.utils.KieService) ResourceChangeSet(org.kie.internal.builder.ResourceChangeSet) KnowledgeBuilderConfiguration(org.kie.internal.builder.KnowledgeBuilderConfiguration) AbstractKieModule.checkStreamMode(org.drools.compiler.kie.builder.impl.AbstractKieModule.checkStreamMode) IOException(java.io.IOException) DroolsAssemblerContext(org.drools.compiler.builder.DroolsAssemblerContext) ResultsImpl(org.drools.compiler.kie.builder.impl.ResultsImpl) GeneratedFact(org.drools.core.factmodel.GeneratedFact) File(java.io.File) ZipKieModule(org.drools.compiler.kie.builder.impl.ZipKieModule) KieBaseBuilder(org.drools.modelcompiler.builder.KieBaseBuilder) Collectors.toList(java.util.stream.Collectors.toList) KieModuleModel(org.kie.api.builder.model.KieModuleModel) ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) Comparator(java.util.Comparator) ResourceType.determineResourceType(org.kie.api.io.ResourceType.determineResourceType) Collections(java.util.Collections) InputStream(java.io.InputStream) KieBaseUpdaterOptions(org.drools.compiler.kie.builder.impl.KieBaseUpdaterOptions) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) KieBaseUpdaters(org.drools.compiler.kie.builder.impl.KieBaseUpdaters) CompositeKnowledgeBuilder(org.kie.internal.builder.CompositeKnowledgeBuilder) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KieBaseUpdatersContext(org.drools.compiler.kie.builder.impl.KieBaseUpdatersContext) AlphaNetworkCompilerOption(org.kie.internal.builder.conf.AlphaNetworkCompilerOption) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1