本文整理汇总了Java中org.drools.KnowledgeBase.newStatefulKnowledgeSession方法的典型用法代码示例。如果您正苦于以下问题:Java KnowledgeBase.newStatefulKnowledgeSession方法的具体用法?Java KnowledgeBase.newStatefulKnowledgeSession怎么用?Java KnowledgeBase.newStatefulKnowledgeSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.drools.KnowledgeBase
的用法示例。
在下文中一共展示了KnowledgeBase.newStatefulKnowledgeSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// go !
PI pi = new PI();
pi.setIterStrategy(PI.IterStrategySetting.ballardMethod.getStrategy());
ksession.insert(pi);
ksession.fireAllRules();
System.out.println("PI: " + pi.getPi());
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
示例2: main
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// go !
Employ emp = new Employ();
emp.setEduInfo("master");
emp.setResume("tech");
emp.setAnnualExam("good");
emp.setAwardPunish("award");
ksession.insert(emp);
ksession.startProcess("myrules.salary");
ksession.fireAllRules();
System.out.println("Basic Salary: " + emp.getBasicSalary());
System.out.println("Duty Salary: " + emp.getDutySalary());
System.out.println("Bonus : " + emp.getBonus());
System.out.println("rate : " + emp.getPercent());
System.out.printf("Total Salary: %.0f" , emp.getTotalSalary());
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
示例3: main
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// go !
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
ksession.insert(message);
ksession.fireAllRules();
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
示例4: executeViewRule
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
@Override
public boolean executeViewRule(ServiceContext context, Long ruleId, BaseObject<?> baseObject) {
EntityRuleDO rule = entityRuleDAO.getById(ruleId);
if (rule != null) {
KnowledgeBase knowlegeBase = getKnowlegeBase(Lists.newArrayList(rule));
StatefulKnowledgeSession session = knowlegeBase.newStatefulKnowledgeSession();
for (Permission permission : userService.findAvailablePermissions(context)) {
session.insert(permission);
}
List<ValidationError> errorList = Lists.newArrayList();
session.setGlobal("errorList", errorList);
session.insert(baseObject);
session.fireAllRules();
session.dispose();
return errorList.isEmpty();
}
return true;
}
示例5: AbstractDroolsEngine
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public AbstractDroolsEngine(KnowledgeBuilder kbuilder, Object[] globals,
Environment env, KnowledgeBaseConfiguration config,
SessionConfiguration sessionConf, String changesetPath,
Boolean hasKnowledgeAgent) {
KnowledgeBase kbase = createKBase(kbuilder, config);
if (hasKnowledgeAgent) {
createKnowledgeAgent(kbase, "MyKAgent");
wm = (ReteooStatefulSession) ((KnowledgeBaseImpl) kagent
.getKnowledgeBase()).ruleBase.newStatefulSession(
(SessionConfiguration) sessionConf, env);
ksession = new StatefulKnowledgeSessionImpl(wm, kagent
.getKnowledgeBase());
} else {
ksession = kbase.newStatefulKnowledgeSession(sessionConf, env);
}
for (Object global : globals) {
ksession.setGlobal(global.getClass().getSimpleName(), global);
}
}
示例6: getStatefulKnowledgeSession
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public static StatefulKnowledgeSession getStatefulKnowledgeSession(String path) {
KnowledgeBase kbase;
StatefulKnowledgeSession ksession;
KnowledgeRuntimeLogger logger;
try {
kbase = readKnowledgeBase(path);
ksession = kbase.newStatefulKnowledgeSession();
logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
logger.close();
if(ksession != null) {
return ksession;
} else { return null; }
} catch(Throwable t) {
System.out.println("X:\tErr in DroolsTools: cannot read knowlegde base\n\t"+t.getMessage());
//t.printStackTrace();
return null;
}
}
示例7: crearSesionConConfiguracionStandard
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public void crearSesionConConfiguracionStandard(KnowledgeBuilder kbuilder){
KnowledgeBaseConfiguration kbaseconfiguration = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
// kbaseconfiguration.setProperty(AssertBehaviorOption.PROPERTY_NAME, "equality");
System.out.println("\n\n\n\n");
System.out.println("\nLISTADO DE LAS PROPIEDADES UTILIZADAS PARA LA CONFIGURACION DEL MOTOR DEL AGENTE " + this.agent.getIdentAgente() + "......\n");
System.out.println("----------------------------------------------------------------");
System.out.println("AssertBehaviorOption->" + kbaseconfiguration.getProperty(org.drools.conf.AssertBehaviorOption.PROPERTY_NAME));
System.out.println("EventProcessingOption->" + kbaseconfiguration.getProperty(org.drools.conf.EventProcessingOption.PROPERTY_NAME));
System.out.println("IndexLeftBetaMemoryOption->" + kbaseconfiguration.getProperty(org.drools.conf.IndexLeftBetaMemoryOption.PROPERTY_NAME));
System.out.println("IndexRightBetaMemoryOption->" + kbaseconfiguration.getProperty(org.drools.conf.IndexRightBetaMemoryOption.PROPERTY_NAME));
System.out.println("LogicalOverrideOption->" + kbaseconfiguration.getProperty(org.drools.conf.LogicalOverrideOption.PROPERTY_NAME));
System.out.println("MaintainTMSOption->" + kbaseconfiguration.getProperty(org.drools.conf.MaintainTMSOption.PROPERTY_NAME));
System.out.println("MBeansOption->" + kbaseconfiguration.getProperty(org.drools.conf.MBeansOption.PROPERTY_NAME));
System.out.println("MultithreadEvaluationOption->" + kbaseconfiguration.getProperty(org.drools.conf.MultithreadEvaluationOption.PROPERTY_NAME));
System.out.println("RemoveIdentitiesOption->" + kbaseconfiguration.getProperty(org.drools.conf.RemoveIdentitiesOption.PROPERTY_NAME));
System.out.println("SequentialAgendaOption->" + kbaseconfiguration.getProperty(org.drools.conf.SequentialAgendaOption.PROPERTY_NAME));
System.out.println("SequentialOption->" + kbaseconfiguration.getProperty(org.drools.conf.SequentialOption.PROPERTY_NAME));
System.out.println("ShareAlphaNodesOption->" + kbaseconfiguration.getProperty(org.drools.conf.ShareAlphaNodesOption.PROPERTY_NAME));
System.out.println("ShareBetaNodesOption->" + kbaseconfiguration.getProperty(org.drools.conf.ShareBetaNodesOption.PROPERTY_NAME));
System.out.println("----------------------------------------------------------------\n\n\n\n");
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseconfiguration);
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
if(kSesion != null)kSesion.dispose();
kSesion = kbase.newStatefulKnowledgeSession();
entrypoint = kSesion.getWorkingMemoryEntryPoint("DEFAULT");
}
示例8: main
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// go !
Employ emp = new Employ();
emp.setEduInfo("master");
emp.setResume("tech");
emp.setAnnualExam("good");
emp.setAwardPunish("award");
ksession.insert(emp);
ksession.startProcess("ruleflow.salary");
ksession.fireAllRules();
System.out.println("Basic Salary: " + emp.getBasicSalary());
System.out.println("Duty Salary: " + emp.getDutySalary());
System.out.println("Bonus : " + emp.getBonus());
System.out.println("rate : " + emp.getPercent());
System.out.printf("Total Salary: %.0f" , emp.getTotalSalary());
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
示例9: createStatefulKnowledgeSession
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
/**
* Creates the stateful knowledge session.
*
* @return the stateful knowledge session
*/
StatefulKnowledgeSession createStatefulKnowledgeSession() {
StatefulKnowledgeSession session = null;
try {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
final String casRules = guvnorService
.getVersionedRulesFromPackage();
kbuilder.add(
ResourceFactory.newByteArrayResource(casRules.getBytes()),
ResourceType.DRL);
final KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (final KnowledgeBuilderError error : errors) {
logger.error(error.toString());
}
}
final KnowledgeBase knowledgeBase = KnowledgeBaseFactory
.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
session = knowledgeBase.newStatefulKnowledgeSession();
session.setGlobal("ruleExecutionContainer",
new RuleExecutionContainer());
} catch (final Exception e) {
logger.error(e.toString(), e);
}
return session;
}
示例10: execute
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
@Override
public void execute(DelegateExecution execution) {
ProcessDefinition processDefinition = ProcessDefinitionUtil.getProcessDefinition(execution.getProcessDefinitionId());
String deploymentId = processDefinition.getDeploymentId();
KnowledgeBase knowledgeBase = RulesHelper.findKnowledgeBaseByDeploymentId(deploymentId);
StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();
if (variablesInputExpressions != null) {
Iterator<Expression> itVariable = variablesInputExpressions.iterator();
while (itVariable.hasNext()) {
Expression variable = itVariable.next();
ksession.insert(variable.getValue(execution));
}
}
if (!rulesExpressions.isEmpty()) {
RulesAgendaFilter filter = new RulesAgendaFilter();
Iterator<Expression> itRuleNames = rulesExpressions.iterator();
while (itRuleNames.hasNext()) {
Expression ruleName = itRuleNames.next();
filter.addSuffic(ruleName.getValue(execution).toString());
}
filter.setAccept(!exclude);
ksession.fireAllRules(filter);
} else {
ksession.fireAllRules();
}
Collection<Object> ruleOutputObjects = ksession.getObjects();
if (ruleOutputObjects != null && !ruleOutputObjects.isEmpty()) {
Collection<Object> outputVariables = new ArrayList<>();
outputVariables.addAll(ruleOutputObjects);
execution.setVariable(resultVariable, outputVariables);
}
ksession.dispose();
leave(execution);
}
示例11: execute
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
@Override
public void execute(DelegateExecution execution) {
ActivityExecution activityExecution = (ActivityExecution) execution;
PvmProcessDefinition processDefinition = activityExecution.getActivity().getProcessDefinition();
String deploymentId = processDefinition.getDeploymentId();
KnowledgeBase knowledgeBase = RulesHelper.findKnowledgeBaseByDeploymentId(deploymentId);
StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();
if (variablesInputExpressions != null) {
Iterator<Expression> itVariable = variablesInputExpressions.iterator();
while (itVariable.hasNext()) {
Expression variable = itVariable.next();
ksession.insert(variable.getValue(execution));
}
}
if (!rulesExpressions.isEmpty()) {
RulesAgendaFilter filter = new RulesAgendaFilter();
Iterator<Expression> itRuleNames = rulesExpressions.iterator();
while (itRuleNames.hasNext()) {
Expression ruleName = itRuleNames.next();
filter.addSuffic(ruleName.getValue(execution).toString());
}
filter.setAccept(!exclude);
ksession.fireAllRules(filter);
} else {
ksession.fireAllRules();
}
Collection<Object> ruleOutputObjects = ksession.getObjects();
if (ruleOutputObjects != null && !ruleOutputObjects.isEmpty()) {
Collection<Object> outputVariables = new ArrayList<>();
outputVariables.addAll(ruleOutputObjects);
execution.setVariable(resultVariable, outputVariables);
}
ksession.dispose();
leave(activityExecution);
}
示例12: main
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// go !
ksession.fireAllRules();
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
示例13: execute
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public void execute(ActivityExecution execution) throws Exception {
PvmProcessDefinition processDefinition = execution.getActivity().getProcessDefinition();
String deploymentId = processDefinition.getDeploymentId();
KnowledgeBase knowledgeBase = RulesHelper.findKnowledgeBaseByDeploymentId(deploymentId);
StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();
if (variablesInputExpressions != null) {
Iterator<Expression> itVariable = variablesInputExpressions.iterator();
while (itVariable.hasNext()) {
Expression variable = itVariable.next();
ksession.insert(variable.getValue(execution));
}
}
if (rulesExpressions.size() > 0) {
RulesAgendaFilter filter = new RulesAgendaFilter();
Iterator<Expression> itRuleNames = rulesExpressions.iterator();
while (itRuleNames.hasNext()) {
Expression ruleName = itRuleNames.next();
filter.addSuffic(ruleName.getValue(execution).toString());
}
filter.setAccept(!exclude);
ksession.fireAllRules(filter);
} else {
ksession.fireAllRules();
}
Collection<Object> ruleOutputObjects = ksession.getObjects();
if (ruleOutputObjects != null && ruleOutputObjects.size() > 0) {
Collection<Object> outputVariables = new ArrayList<Object>();
for (Object object : ruleOutputObjects) {
outputVariables.add(object);
}
execution.setVariable(resultVariable, outputVariables);
}
ksession.dispose();
leave(execution);
}
示例14: buildKnowledgeSession
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
public final void buildKnowledgeSession() {
if (ksession == null) {
LOG.debug("Building Drools Knowledge Session");
// initialise the rules
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
// pickup the rules file from the classpath
// this will parse and compile in one step
LOG.info("Loading rules file " + rulesFileName);
kbuilder.add( ResourceFactory.newClassPathResource( rulesFileName, QaRecommendationServiceImpl.class ),
ResourceType.DRL );
// Check the builder for errors
if ( kbuilder.hasErrors() ) {
LOG.error(kbuilder.getErrors().toString());
throw new RuntimeException( "Unable to compile \"" + rulesFileName + "\"." );
}
// add the packages to a knowledgebase (deploy the knowledge packages).
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
// set the knowledge session
ksession = kbase.newStatefulKnowledgeSession();
// set the configured message formats and advice
ksession.setGlobal("globals", globals);
}
}
示例15: createStatefulKnowledgeSession
import org.drools.KnowledgeBase; //导入方法依赖的package包/类
/**
* Creates the stateful knowledge session.
*
* @return the stateful knowledge session
*/
private StatefulKnowledgeSession createStatefulKnowledgeSession() {
StatefulKnowledgeSession session = null;
try {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
String casRules = guvnorService.getVersionedRulesFromPackage();
kbuilder.add(
ResourceFactory.newByteArrayResource(casRules.getBytes()),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
LOGGER.error(error.toString());
}
}
KnowledgeBase knowledgeBase = KnowledgeBaseFactory
.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
session = knowledgeBase.newStatefulKnowledgeSession();
session.setGlobal("ruleExecutionContainer",
new RuleExecutionContainer());
} catch (Exception e) {
LOGGER.error(e.toString(), e);
}
return session;
}