当前位置: 首页>>代码示例>>Java>>正文


Java KnowledgeAgentFactory.newKnowledgeAgent方法代码示例

本文整理汇总了Java中org.drools.agent.KnowledgeAgentFactory.newKnowledgeAgent方法的典型用法代码示例。如果您正苦于以下问题:Java KnowledgeAgentFactory.newKnowledgeAgent方法的具体用法?Java KnowledgeAgentFactory.newKnowledgeAgent怎么用?Java KnowledgeAgentFactory.newKnowledgeAgent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.drools.agent.KnowledgeAgentFactory的用法示例。


在下文中一共展示了KnowledgeAgentFactory.newKnowledgeAgent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readKnowledgeBase

import org.drools.agent.KnowledgeAgentFactory; //导入方法依赖的package包/类
protected KnowledgeBase readKnowledgeBase() {
    if (knowledgeBasesCache.containsKey(task.getId())) {
        return knowledgeBasesCache.get(task.getId()).getKnowledgeBase();
    }

    // Creating agent with default KnowledgeAgentConfiguration for scanning files and directories
    KnowledgeAgent kAgent = KnowledgeAgentFactory.newKnowledgeAgent("Knowledge agent for task#" + task.getId());

    // Adding resources for observing by KnowledgeAgent and creating KnowledgeBase.
    // Current version of api (5.0.1) does not implement adding resources from KnowledgeBase,
    // that was mentioned in api documentation (may be bug in source code).
    // So, we use other aproach for configuring KnowledgeAgent
    // Now agent interface allowes defining resources and directories for observing
    // only through ChangeSet from Resource (usually xml config file)
    // We create needed configuration dynamically as string
    // from task parameters information
    kAgent.applyChangeSet(new ByteArrayResource(createChangeSetStringFromTaskParameters().getBytes()));

    // Cache agent for further usage without recreation
    knowledgeBasesCache.put(task.getId(), kAgent);
    // Start scanning services for automatical updates of cached agents
    startRulesScannerIfNeeded();

    return kAgent.getKnowledgeBase();
}
 
开发者ID:maxdelo77,项目名称:replyit-master-3.2-final,代码行数:26,代码来源:RulesBaseTask.java

示例2: createKnowledgeAgent

import org.drools.agent.KnowledgeAgentFactory; //导入方法依赖的package包/类
/**
 * Creates a KnowledgeAgent for loading the RuleBase changes dynamically
 * 
 * @param kbase
 * @param correlatorId
 */
protected void createKnowledgeAgent(KnowledgeBase kbase, String engineName) {
	Properties agentProps = new Properties();
	agentProps.setProperty("drools.agent.scanResources", "true");
	agentProps.setProperty("drools.agent.monitorChangeSetEvents", "true");
	agentProps.setProperty("drools.agent.scanDirectories", "true");

	kagent = KnowledgeAgentFactory.newKnowledgeAgent(engineName, kbase,
			KnowledgeAgentFactory
					.newKnowledgeAgentConfiguration(agentProps));
}
 
开发者ID:MusesProject,项目名称:MusesServer,代码行数:17,代码来源:AbstractDroolsEngine.java

示例3: checkConfiguration

import org.drools.agent.KnowledgeAgentFactory; //导入方法依赖的package包/类
/**
 * <p>
 * Check if all fields are initialized properly.
 * </p>
 * <p>
 * In this class, this method will check if the servicePeriodSplitDates contains null.
 * </p>
 * 
 * @throws OPMConfigurationException if any needed field is not
 * initialized properly.
 * @since 1.1 OPM - Rules Engine - Scenarios Conversion 2 - Deduction Update Assembly
 */
@Override
@PostConstruct
public void checkConfiguration() {
    super.checkConfiguration();
    if (this.entityManager == null) {
        throw new OPMConfigurationException("entityManager cannot be null.");
    }
    if (servicePeriodSplitDates != null) {
        for (Date date : servicePeriodSplitDates) {
            if (date == null) {
                throw new OPMConfigurationException("Items in servicePeriodSplitDates list cannot be null.");
            }
        }
    }
    if (this.deductionTableTemplate == null) {
        throw new OPMConfigurationException("deductionTableTemplate cannot be null.");
    }
    try {
        // Generate deduction table
        this.generateDeductionTable();

        // Initialize knowledge agent
        KnowledgeAgentConfiguration config = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
        // We have to set the newInstance property to false so that the knowledge base changes can be reflected
        config.setProperty("drools.agent.newInstance", "false"); 
        KnowledgeAgent knowledgeAgent = KnowledgeAgentFactory.newKnowledgeAgent("deductionKnowledgeAgent", config);
        
        // Substitute the classpath resource location with the file system resource location
        String changeSet = ServiceHelper.inputStreamToString(
                ResourceFactory.newClassPathResource("deduction-change-set.xml").getInputStream());
        changeSet = changeSet.replace("classpath:rules/deduction_table.xls",
                "file:" + this.deductionTableTemplate.getDecisionTableFile());
        knowledgeAgent.applyChangeSet(ResourceFactory.newByteArrayResource(changeSet.getBytes("utf-8")));
        this.setKnowledgeAgent(knowledgeAgent);
    } catch (IOException e) {
        throw new OPMConfigurationException("Failed to initialize KnowledgeAgent.");
    }
}
 
开发者ID:NASA-Tournament-Lab,项目名称:CoECI-OPM-Service-Credit-Redeposit-Deposit-Application,代码行数:51,代码来源:DeductionCalculationRuleServiceImpl.java

示例4: checkConfiguration

import org.drools.agent.KnowledgeAgentFactory; //导入方法依赖的package包/类
/**
 * <p>
 * Check if all fields are initialized properly.
 * </p>
 * 
 * @throws OPMConfigurationException if any needed field is not
 * initialized properly.
 */
@Override
@PostConstruct
public void checkConfiguration() {
    super.checkConfiguration();
    // Initialize knowledge agent
    KnowledgeAgent knowledgeAgent = KnowledgeAgentFactory.newKnowledgeAgent("deductionValidationKnowledgeAgent");
    knowledgeAgent.applyChangeSet(ResourceFactory.newClassPathResource("deduction-validation-change-set.xml"));
    this.setKnowledgeAgent(knowledgeAgent);
}
 
开发者ID:NASA-Tournament-Lab,项目名称:CoECI-OPM-Service-Credit-Redeposit-Deposit-Application,代码行数:18,代码来源:DeductionValidationRuleServiceImpl.java

示例5: checkConfiguration

import org.drools.agent.KnowledgeAgentFactory; //导入方法依赖的package包/类
/**
 * <p>
 * Check if all fields are initialized properly.
 * </p>
 * 
 * @throws OPMConfigurationException if any needed field is not
 * initialized properly.
 */
@Override
@PostConstruct
public void checkConfiguration() {
    super.checkConfiguration();
    if (this.entityManager == null) {
        throw new OPMConfigurationException("entityManager cannot be null.");
    }
    if (this.csrsInterestTemplate == null) {
        throw new OPMConfigurationException("csrsInterestTemplate cannot be null.");
    }
    if (this.csrsPeaceCorpsInterestTemplate == null) {
        throw new OPMConfigurationException("csrsPeaceCorpsInterestTemplate cannot be null.");
    }
    if (this.csrsRedepositInterestTemplate == null) {
        throw new OPMConfigurationException("csrsRedepositInterestTemplate cannot be null.");
    }
    if (this.fersInterestTemplate == null) {
        throw new OPMConfigurationException("fersInterestTemplate cannot be null.");
    }
    if (this.fersPeaceCorpsInterestTemplate == null) {
        throw new OPMConfigurationException("fersPeaceCorpsInterestTemplate cannot be null.");
    }
    if (this.fersRedepositInterestTemplate == null) {
        throw new OPMConfigurationException("fersRedepositInterestTemplate cannot be null.");
    }
    try {
        // Generate interest tables
        this.generateInterestTables();

        // Initialize knowledge agent
        KnowledgeAgentConfiguration config = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
        // We have to set the newInstance property to false so that the knowledge base changes can be reflected
        config.setProperty("drools.agent.newInstance", "false"); 
        KnowledgeAgent knowledgeAgent = KnowledgeAgentFactory.newKnowledgeAgent("interestKnowledgeAgent", config);
        
        // Substitute the classpath resource location with the file system resource location
        String changeSet = ServiceHelper.inputStreamToString(
                ResourceFactory.newClassPathResource("interest-change-set.xml").getInputStream());
        changeSet = changeSet.replace("classpath:rules/csrs_interest.xls",
                "file:" + this.csrsInterestTemplate.getDecisionTableFile());
        changeSet = changeSet.replace("classpath:rules/csrs_peacecorps_interest.xls",
                "file:" + this.csrsPeaceCorpsInterestTemplate.getDecisionTableFile());
        changeSet = changeSet.replace("classpath:rules/csrs_redeposit_interest.xls",
                "file:" + this.csrsRedepositInterestTemplate.getDecisionTableFile());
        changeSet = changeSet.replace("classpath:rules/fers_interest.xls",
                "file:" + this.fersInterestTemplate.getDecisionTableFile());
        changeSet = changeSet.replace("classpath:rules/fers_peacecorps_interest.xls",
                "file:" + this.fersPeaceCorpsInterestTemplate.getDecisionTableFile());
        changeSet = changeSet.replace("classpath:rules/fers_redeposit_interest.xls",
                "file:" + this.fersRedepositInterestTemplate.getDecisionTableFile());
        knowledgeAgent.applyChangeSet(ResourceFactory.newByteArrayResource(changeSet.getBytes("utf-8")));
        this.setKnowledgeAgent(knowledgeAgent);
    } catch (IOException e) {
        throw new OPMConfigurationException("Failed to initialize KnowledgeAgent.");
    }
}
 
开发者ID:NASA-Tournament-Lab,项目名称:CoECI-OPM-Service-Credit-Redeposit-Deposit-Application,代码行数:65,代码来源:InterestCalculationRuleServiceImpl.java


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