• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java InternalKieModule类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.drools.compiler.kie.builder.impl.InternalKieModule的典型用法代码示例。如果您正苦于以下问题:Java InternalKieModule类的具体用法?Java InternalKieModule怎么用?Java InternalKieModule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InternalKieModule类属于org.drools.compiler.kie.builder.impl包,在下文中一共展示了InternalKieModule类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createKJar

import org.drools.compiler.kie.builder.impl.InternalKieModule; //导入依赖的package包/类
public static byte[] createKJar(ReleaseId releaseId, List<String> drls) {
    KieServices kieServices = KieServices.Factory.get();
    KieFileSystem kfs = kieServices.newKieFileSystem();
    kfs.generateAndWritePomXML(releaseId);
    drls.forEach(drl -> kfs.write("src/main/resources/" + drl.hashCode() + ".drl", drl));
    KieBuilder kb = kieServices.newKieBuilder(kfs).buildAll();
    if (kb.getResults().hasMessages(Message.Level.ERROR)) {
        for (Message result : kb.getResults().getMessages()) {
            System.out.println(result.getText());
        }
        return null;
    }
    InternalKieModule kieModule = (InternalKieModule) kieServices.getRepository().getKieModule(releaseId);
    byte[] jar = kieModule.getBytes();
    return jar;
}
 
开发者ID:barrykalok,项目名称:spring-boot-drools-example,代码行数:17,代码来源:RuleEngineUtil.java


示例2: setupClasspathKmoduleBuilder

import org.drools.compiler.kie.builder.impl.InternalKieModule; //导入依赖的package包/类
private static RuntimeEnvironmentBuilder setupClasspathKmoduleBuilder(KieContainer kieContainer,
                                                                      String kbaseName,
                                                                      String ksessionName) {
    if (StringUtils.isEmpty(kbaseName)) {
        KieBaseModel defaultKBaseModel = ((KieContainerImpl)kieContainer).getKieProject().getDefaultKieBaseModel();
        if (defaultKBaseModel != null) {
            kbaseName = defaultKBaseModel.getName();
        } else {
            kbaseName = DEFAULT_KBASE_NAME;
        }
    }
    InternalKieModule module = (InternalKieModule) ((KieContainerImpl)kieContainer).getKieModuleForKBase(kbaseName);
    if (module == null) {
        throw new IllegalStateException("Cannot find kbase with name " + kbaseName);
    }
    KieBase kbase = kieContainer.getKieBase(kbaseName);

    return getDefault()
            .knowledgeBase(kbase)
            .classLoader(kieContainer.getClassLoader())
            .registerableItemsFactory(new KModuleRegisterableItemsFactory(kieContainer, ksessionName));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:23,代码来源:PatchedRuntimeEnvironmentBuilder.java


示例3: setupClasspathKmoduleBuilder

import org.drools.compiler.kie.builder.impl.InternalKieModule; //导入依赖的package包/类
private static RuntimeEnvironmentBuilder setupClasspathKmoduleBuilder(KieContainer kieContainer, String kbaseName, String ksessionName) {
    if (StringUtils.isEmpty(kbaseName)) {
        KieBaseModel defaultKBaseModel = ((KieContainerImpl)kieContainer).getKieProject().getDefaultKieBaseModel();
        if (defaultKBaseModel != null) {
            kbaseName = defaultKBaseModel.getName();
        } else {
            kbaseName = DEFAULT_KBASE_NAME;
        }
    }
    InternalKieModule module = (InternalKieModule)((KieContainerImpl)kieContainer).getKieModuleForKBase(kbaseName);
    if (module == null) {
        throw new IllegalStateException("Cannot find kbase with name " + kbaseName);
    }
    KieBase kbase = kieContainer.getKieBase(kbaseName);

    return getDefault().knowledgeBase(kbase).classLoader(kieContainer.getClassLoader())
        .registerableItemsFactory(new KModuleRegisterableItemsFactory(kieContainer, ksessionName));
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:19,代码来源:PatchedRuntimeEnvironmentBuilder.java


示例4: initKieJar

import org.drools.compiler.kie.builder.impl.InternalKieModule; //导入依赖的package包/类
/** 
 * 初始化一个kjar:把原有的drl包含进新建的kjar中 
 * 
 * @param ks 
 * @param releaseId 
 * @return 
 * @throws IOException 
 */  
public static InternalKieModule initKieJar(KieServices ks, ReleaseId releaseId) throws IOException {  
    KieFileSystem kfs = createKieFileSystemWithKProject(ks, true);  
    kfs.writePomXML(getPom(releaseId));  
    for (File file : getRuleFiles()) {  
        kfs.write("src/main/resources/" + file.getName(),  
                ResourceFactory.newClassPathResource(RULES_PATH + File.separator + file.getName(), "UTF-8"));  
    }  
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);  
    if (!kieBuilder.buildAll().getResults().getMessages().isEmpty()) {  
        throw new IllegalStateException("Error creating KieBuilder.");  
    }  
    return (InternalKieModule) kieBuilder.getKieModule();  
}
 
开发者ID:lansheng228,项目名称:kie-dynamic-rule,代码行数:22,代码来源:DroolsUtils.java


示例5: createKieJar

import org.drools.compiler.kie.builder.impl.InternalKieModule; //导入依赖的package包/类
public static InternalKieModule createKieJar(KieServices ks, ReleaseId releaseId, ResourceWrapper resourceWrapper) {  
    KieFileSystem kfs = createKieFileSystemWithKProject(ks, true);  
    kfs.writePomXML(getPom(releaseId));  
    kfs.write("src/main/resources/" + resourceWrapper.getTargetResourceName(), resourceWrapper.getResource());  
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);  
    if (!kieBuilder.getResults().getMessages().isEmpty()) {  
        System.out.println(kieBuilder.getResults().getMessages());  
        throw new IllegalStateException("Error creating KieBuilder.");  
    }  
    return (InternalKieModule) kieBuilder.getKieModule();  
}
 
开发者ID:lansheng228,项目名称:kie-dynamic-rule,代码行数:12,代码来源:DroolsUtils.java


示例6: getModuleClassLoader

import org.drools.compiler.kie.builder.impl.InternalKieModule; //导入依赖的package包/类
public ClassLoader getModuleClassLoader(final KieModule kieModule) {

        final org.kie.api.builder.KieModule module = buildInfoService.getBuildInfo(kieModule).getKieModuleIgnoringErrors();
        ClassLoader dependenciesClassLoader = dependenciesClassLoaderCache.assertDependenciesClassLoader(kieModule);
        ClassLoader moduleClassLoader;
        if (module instanceof InternalKieModule) {
            //will always be an internal kie module
            InternalKieModule internalModule = (InternalKieModule) module;
            moduleClassLoader = new MapClassLoader(internalModule.getClassesMap(true),
                                                   dependenciesClassLoader);
        } else {
            moduleClassLoader = KieModuleMetaData.Factory.newKieModuleMetaData(module).getClassLoader();
        }
        return moduleClassLoader;
    }
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:16,代码来源:ModuleClassLoaderHelper.java


示例7: getKieContainer

import org.drools.compiler.kie.builder.impl.InternalKieModule; //导入依赖的package包/类
public KieContainer getKieContainer() {
    BuildResults results = null;

    //Kie classes are only available once built
    if (!isBuilt()) {
        results = build();
    } else {
        results = new BuildResults();
        results.addAllBuildMessages(convertMessages(kieBuilder.getResults().getMessages(),
                                                    handles));
    }
    //It's impossible to retrieve a KieContainer if the KieModule contains errors
    if (results.getErrorMessages().isEmpty()) {
        // Do not retrieve the KieContainer with KieServices.newKieContainer(releaseId) since this looks-up the KieModule to
        // create the KieContainer from KieRepository. This holds the most recent KieModule (for the ReleaseId) that was built with
        // kieBuilder.buildAll() which *may* be a KieModule created during asset validation and hence will lack many assets.
        // See https://bugzilla.redhat.com/show_bug.cgi?id=1202551
        final org.kie.api.builder.KieModule kieModule = kieBuilder.getKieModule();
        final ReleaseId releaseId = kieModule.getReleaseId();
        final org.drools.compiler.kie.builder.impl.KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieBuilder.getKieModule(),
                                                                                                   null);
        final KieContainer kieContainer = new KieContainerImpl(kieProject,
                                                               KieServices.Factory.get().getRepository(),
                                                               releaseId);
        return kieContainer;
    } else {
        return null;
    }
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:30,代码来源:Builder.java


示例8: createSolverFactory

import org.drools.compiler.kie.builder.impl.InternalKieModule; //导入依赖的package包/类
private ValidationMessage createSolverFactory(final Path resourcePath,
                                              final KieProject kieWorkbenchProject,
                                              final boolean runSolver) {
    final InternalKieModule kieModule = (InternalKieModule) buildInfoService.getBuildInfo(kieWorkbenchProject).getKieModuleIgnoringErrors();
    final org.drools.compiler.kie.builder.impl.KieProject kieProject = new KieModuleKieProject(kieModule,
                                                                                               null);
    final KieContainer kieContainer = new KieContainerImpl(kieProject,
                                                           KieServices.Factory.get().getRepository());

    try {

        final String solverConfigResource = getSolverConfigResource(resourcePath,
                                                                    kieWorkbenchProject);

        SolverFactory<Object> solverFactory = SolverFactory.createFromKieContainerXmlResource(kieContainer,
                                                                                              solverConfigResource);

        if (runSolver) {
            String projectName = resolveProjectName(resourcePath);
            if (!SMOKE_TEST_SUPPORTED_PROJECTS.contains(projectName)) {
                throw new IllegalStateException("Running a smoke test for project (" + projectName + ") is not supported.");
            }

            solverFactory.getSolverConfig().getTerminationConfig().shortenTimeMillisSpentLimit(SMOKE_TEST_MILLISECONDS_SPENT_LIMIT);
            if (solverFactory.getSolverConfig().getScoreDirectorFactoryConfig().getKsessionName() == null) {
                solverFactory.getSolverConfig().getScoreDirectorFactoryConfig().setKsessionName(kieProject.getDefaultKieSession().getName());
            }
            Solver<Object> solver = solverFactory.buildSolver();

            XStreamSolutionImporter solutionImporter = new XStreamSolutionImporter(kieContainer.getClassLoader());
            Object solution = solutionImporter.read(getClass().getClassLoader().getResourceAsStream("org/optaplanner/workbench/screens/solver/backend/server/solution/" + projectName + ".xml"));

            solver.solve(solution);
        } else {
            solverFactory.buildSolver();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return make(e,
                    resourcePath);
    }

    return null;
}
 
开发者ID:kiegroup,项目名称:optaplanner-wb,代码行数:45,代码来源:SolverValidator.java


示例9: compileAndLoadKieJarMetadataAllResourcesPackagedJar

import org.drools.compiler.kie.builder.impl.InternalKieModule; //导入依赖的package包/类
@Test
public void compileAndLoadKieJarMetadataAllResourcesPackagedJar() throws Exception {
    /**
     * If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
     * */
    String alternateSettingsAbsPath = new File("src/test/settings.xml").getAbsolutePath();
    //compile and install
    Path tmpRoot = Files.createTempDirectory("repo");
    //NIO creation and copy content
    Path temp = Files.createDirectories(Paths.get(tmpRoot.toString(),
                                                  "dummy"));
    TestUtil.copyTree(Paths.get("target/test-classes/kjar-2-all-resources"),
                      temp);
    //end NIO

    AFCompiler compiler = KieMavenCompilerFactory.getCompiler(
            KieDecorator.KIE_AND_LOG_AFTER);

    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(temp);
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(),
                                                           info,
                                                           new String[]{MavenCLIArgs.INSTALL, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath},
                                                           new HashMap<>(),
                                                           Boolean.TRUE);
    KieCompilationResponse res = (KieCompilationResponse) compiler.compileSync(req);

    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(),
                                                  "KieMetadataTest.compileAndLoadKieJarMetadataAllResourcesPackagedJar");
    }

    if (res.getErrorMessage().isPresent()) {
        logger.info("Error:" + res.getErrorMessage().get());
    }

    Assert.assertTrue(res.isSuccessful());

    Optional<KieModuleMetaInfo> metaDataOptional = res.getKieModuleMetaInfo();
    Assert.assertTrue(metaDataOptional.isPresent());
    KieModuleMetaInfo kieModuleMetaInfo = metaDataOptional.get();
    Assert.assertNotNull(kieModuleMetaInfo);

    Map<String, Set<String>> rulesBP = kieModuleMetaInfo.getRulesByPackage();
    Assert.assertEquals(rulesBP.size(),
                        8);
    Map<String, TypeMetaInfo> typesMI = kieModuleMetaInfo.getTypeMetaInfos();
    Assert.assertEquals(typesMI.size(),
                        35);

    Optional<KieModule> kieModuleOptional = res.getKieModule();
    Assert.assertTrue(kieModuleOptional.isPresent());

    Assert.assertTrue(res.getProjectDependencies().isPresent());
    Assert.assertTrue(res.getProjectDependencies().get().size() == 5);
    KieModule kModule = kieModuleOptional.get();

    KieModuleMetaData kieModuleMetaData = new KieModuleMetaDataImpl((InternalKieModule) kModule,
                                                                    res.getProjectDependencies().get());
    Assert.assertNotNull(kieModuleMetaData);
    //comment if you want read the log file after the test run
    TestUtil.rm(tmpRoot.toFile());
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:63,代码来源:KieMetadataTest.java


示例10: compileAndloadKieJarSingleMetadataWithPackagedJar

import org.drools.compiler.kie.builder.impl.InternalKieModule; //导入依赖的package包/类
@Test
public void compileAndloadKieJarSingleMetadataWithPackagedJar() throws Exception {
    /**
     * If the test fail check if the Drools core classes used, KieModuleMetaInfo and TypeMetaInfo implements Serializable
     * */
    String alternateSettingsAbsPath = new File("src/test/settings.xml").getAbsolutePath();
    Path tmpRoot = Files.createTempDirectory("repo");
    Path tmp = Files.createDirectories(Paths.get(tmpRoot.toString(),
                                                 "dummy"));
    TestUtil.copyTree(Paths.get("target/test-classes/kjar-2-single-resources"),
                      tmp);

    AFCompiler compiler = KieMavenCompilerFactory.getCompiler(KieDecorator.KIE_AFTER);

    WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri()));
    CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(),
                                                           info,
                                                           new String[]{MavenCLIArgs.INSTALL, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath},
                                                           new HashMap<>(),
                                                           Boolean.FALSE);
    KieCompilationResponse res = (KieCompilationResponse) compiler.compileSync(req);
    if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
        TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(),
                                                  "KieMetadataTest.compileAndloadKieJarSingleMetadataWithPackagedJar");
    }
    if (res.getErrorMessage().isPresent()) {
        logger.info(res.getErrorMessage().get());
    }

    Assert.assertTrue(res.isSuccessful());

    Optional<KieModuleMetaInfo> metaDataOptional = res.getKieModuleMetaInfo();
    Assert.assertTrue(metaDataOptional.isPresent());
    KieModuleMetaInfo kieModuleMetaInfo = metaDataOptional.get();
    Assert.assertNotNull(kieModuleMetaInfo);

    Map<String, Set<String>> rulesBP = kieModuleMetaInfo.getRulesByPackage();
    Assert.assertEquals(rulesBP.size(),
                        1);

    Optional<KieModule> kieModuleOptional = res.getKieModule();
    Assert.assertTrue(kieModuleOptional.isPresent());
    KieModule kModule = kieModuleOptional.get();

    Assert.assertTrue(res.getProjectDependencies().isPresent());
    Assert.assertTrue(res.getProjectDependencies().get().size() == 5);

    KieModuleMetaData kieModuleMetaData = new KieModuleMetaDataImpl((InternalKieModule) kModule,
                                                                    res.getProjectDependencies().get());

    //KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kModule); // broken
    Assert.assertNotNull(kieModuleMetaData);

    //comment if you want read the log file after the test run
    TestUtil.rm(tmpRoot.toFile());
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:57,代码来源:KieMetadataTest.java



注:本文中的org.drools.compiler.kie.builder.impl.InternalKieModule类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JCache类代码示例发布时间:2022-05-22
下一篇:
Java Node类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap