本文整理汇总了Java中org.drools.runtime.StatefulKnowledgeSession.insert方法的典型用法代码示例。如果您正苦于以下问题:Java StatefulKnowledgeSession.insert方法的具体用法?Java StatefulKnowledgeSession.insert怎么用?Java StatefulKnowledgeSession.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.drools.runtime.StatefulKnowledgeSession
的用法示例。
在下文中一共展示了StatefulKnowledgeSession.insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exec
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
@Override
public void exec(FrameTask ctx) {
StatefulKnowledgeSession kbsess = kb.newStatefulKnowledgeSession();
try {
// this knowledge session will be the session for all Drools rules
kbsess.insert(ctx.getTriggerEvent());
kbsess.setGlobal("DAO", ctx.getResource(IGenericPatientObjectDAO.class));
kbsess.fireAllRules();
// Harvest all the actions out of working memory
ObjectFilter frameActionFilter = new ObjectFilter() {
@Override
public boolean accept(Object object) {
return object instanceof FrameAction;
}
};
Collection<FactHandle> actions = kbsess.getFactHandles(frameActionFilter);
for (FactHandle handle : actions) {
FrameAction action = (FrameAction) kbsess.getObject(handle);
ctx.addAction(action);
}
} finally {
// clear working memory for next transaction
kbsess.dispose();
}
}
示例2: main
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的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();
}
}
示例3: main
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的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();
}
}
示例4: main
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的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();
}
}
示例5: executeViewRule
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的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;
}
示例6: performCrossFieldValidation
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
public List<ValidationError> performCrossFieldValidation(ServiceContext context,
final Map<String, String> extAttributes, Long scopeId, EntityTypeCode entityType) {
List<ValidationError> errorList = new ArrayList<>();
if (extAttributes != null) {
StatefulKnowledgeSession ksession = ruleService.getRuleSessionForScopePath(context, scopeId, entityType);
if (ksession != null) {
ksession.setGlobal("errorList", errorList);
ksession.insert(extAttributes);
ksession.fireAllRules();
ksession.dispose();
}
}
return errorList;
}
示例7: createTicketFromAlarm
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
* Called from API implemented method after successful retrieval of Alarm.
*
* @param alarm OpenNMS Model class alarm
* @return OpenNMS Ticket processed by Drools logic.
*/
protected Ticket createTicketFromAlarm(OnmsAlarm alarm) {
log().debug("createTicketFromAlarm: Processing ticket.");
// Call superclass method if the knowledge-base was not properly created.
if( m_knowledgeBase == null ) {
log().error("KnowledgeBase is NULL, creating basic ticket form alarm.");
return super.createTicketFromAlarm(alarm);
}
Ticket ticket = new Ticket();
StatefulKnowledgeSession session = m_knowledgeBase.newStatefulKnowledgeSession();
try {
// Pass the ticket as a global - the logic will fill the appropriate fields
session.setGlobal("ticket", ticket);
// Pass the alarm and the node objects
session.insert(alarm);
session.insert(alarm.getNode());
session.fireAllRules();
} finally {
session.dispose();
}
log().debug("createTicketFromAlarm: Succesfully processed ticket.");
return ticket;
}
示例8: fireMessage
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
*
* @param message
* @param rule
*/
public static Object fireMessage(Object message, String rule) {
StatefulKnowledgeSession session;
try {
session = DroolsTools.getStatefulKnowledgeSession(rule);
if(session != null) {
session.insert(message);
session.fireAllRules();
} else {
System.out.println("X:\tCannot create Session\n\t");
}
} catch(Throwable t) {
System.out.println("X:\tCannot fire Message\n\t"+t.getMessage());
}
return message;
}
示例9: waltz
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
@WebMethod
public String waltz(@WebParam(name="WaltzDTO")WaltzDTO dto) {
StatefulKnowledgeSession session = waltzKb.getKbase().newStatefulKnowledgeSession();
for (Line l : dto.getLine()) {
session.insert(l);
}
session.insert(dto.getStage());
long start = System.currentTimeMillis();
session.setGlobal( "time", start );
session.fireAllRules();
long time = System.currentTimeMillis() - start;
System.err.println( time );
session.dispose();
return "time: "+time;
}
示例10: main
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的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();
}
}
示例11: execute
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的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);
}
示例12: execute
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的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);
}
示例13: execute
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的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: executeSession
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
* executes the drools session. The method is aware of the two different
* knowledge-sessions <code>StatelessKnowledgeSession</code> and
* <code>StatefulKnowledgeSession</code> and invokes them respectively.
* @param reports the ECReports.
*/
public void executeSession(ECReports reports) {
log.debug("executing session.");
if (ksession instanceof StatelessKnowledgeSession) {
((StatelessKnowledgeSession)ksession).execute(reports);
} else if (ksession instanceof StatefulKnowledgeSession) {
StatefulKnowledgeSession sks = (StatefulKnowledgeSession) ksession;
sks.insert(reports);
sks.fireAllRules();
}
}
示例15: getRuleSessionForEntityRules
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
private StatefulKnowledgeSession getRuleSessionForEntityRules(ServiceContext context, List<EntityRuleDO> entityRuleDOs) {
KnowledgeBase kbase = getKnowlegeBase(entityRuleDOs);
if (kbase != null) {
StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
for (Permission permission : userService.findAvailablePermissions(context)) {
session.insert(permission);
}
return session;
}
return null;
}