本文整理汇总了Java中org.drools.runtime.StatefulKnowledgeSession类的典型用法代码示例。如果您正苦于以下问题:Java StatefulKnowledgeSession类的具体用法?Java StatefulKnowledgeSession怎么用?Java StatefulKnowledgeSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StatefulKnowledgeSession类属于org.drools.runtime包,在下文中一共展示了StatefulKnowledgeSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeTask
import org.drools.runtime.StatefulKnowledgeSession; //导入依赖的package包/类
private void changeTask(long taskId,String username,StatusOperation operation,String faultMessage) {
EntityManager em=getEntityManager();
EntityTransaction trans=em.getTransaction();
try{
trans.begin();
Task task=em.find(Task.class, taskId);
if(StringUtils.isNotEmpty(faultMessage)){
task.setFaultMessage(faultMessage);
}
if(changeTaskStatus(task,operation)){
em.persist(task);
}
TaskStatus status=task.getStatus();
if(status.equals(TaskStatus.Completed) || status.equals(TaskStatus.Error) || status.equals(TaskStatus.Exited) || status.equals(TaskStatus.Obsolete) || status.equals(TaskStatus.Failed)){
StatefulKnowledgeSession session=this.bpmService.getSession(task.getSessionId());
session.getWorkItemManager().completeWorkItem(task.getWorkItemId(),null);
session.dispose();
}
trans.commit();
}catch(Exception ex){
trans.rollback();
throw new RuntimeException(ex);
}
}
示例2: 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();
}
}
示例3: getProcessInstanceVariables
import org.drools.runtime.StatefulKnowledgeSession; //导入依赖的package包/类
public synchronized Map<String, Object> getProcessInstanceVariables(
long processInstanceId) {
StatefulKnowledgeSession ksession = this.bpmService.createSession();
try {
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
if (processInstance != null) {
Map<String, Object> variables = ((WorkflowProcessInstanceImpl) processInstance)
.getVariables();
if (variables == null) {
return new HashMap<String, Object>();
}
// filter out null values
Map<String, Object> result = new HashMap<String, Object>();
for (Map.Entry<String, Object> entry : variables.entrySet()) {
if (entry.getValue() != null) {
result.put(entry.getKey(), entry.getValue());
}
}
return result;
} else {
throw new IllegalArgumentException("Could not find process instance " + processInstanceId);
}
} finally {
ksession.dispose();
}
}
示例4: setProcessInstanceVariables
import org.drools.runtime.StatefulKnowledgeSession; //导入依赖的package包/类
public void setProcessInstanceVariables(long processInstanceId,
Map<String, Object> variables) {
StatefulKnowledgeSession ksession = this.bpmService.createSession();
try {
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
if (processInstance != null) {
VariableScopeInstance variableScope = (VariableScopeInstance)
((org.jbpm.process.instance.ProcessInstance) processInstance)
.getContextInstance(VariableScope.VARIABLE_SCOPE);
if (variableScope == null) {
throw new IllegalArgumentException("Could not find variable scope for process instance " + processInstanceId);
}
for (Map.Entry<String, Object> entry: variables.entrySet()) {
variableScope.setVariable(entry.getKey(), entry.getValue());
}
} else {
throw new IllegalArgumentException("Could not find process instance " + processInstanceId);
}
} finally {
ksession.dispose();
}
}
示例5: 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();
}
}
示例6: 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();
}
}
示例7: testAssertAndExecuteClinicalFacts_Marshaller_Throws_JAXBException
import org.drools.runtime.StatefulKnowledgeSession; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testAssertAndExecuteClinicalFacts_Marshaller_Throws_JAXBException()
throws Throwable {
// Arrange
StatefulKnowledgeSession sessionMock = mock(StatefulKnowledgeSession.class);
doReturn(sessionMock).when(sut).createStatefulKnowledgeSession();
String factModelStringMock = "factModelStringMock";
when(
marshallerMock.unmarshalFromXml(FactModel.class,
factModelStringMock)).thenThrow(SimpleMarshallerException.class);
// Act
AssertAndExecuteClinicalFactsResponse response = sut
.assertAndExecuteClinicalFacts(factModelStringMock);
// Assert
assertNotNull(response);
assertNull(response.getRuleExecutionResponseContainer());
}
示例8: printFacts
import org.drools.runtime.StatefulKnowledgeSession; //导入依赖的package包/类
public static void printFacts(StatefulKnowledgeSession ksession) {
if (enabledDebugMode){
for (FactHandle f: ksession.getFactHandles()){
System.out.println(" "+ksession.getObject(f));
}
}
}
示例9: evaluateInnerProjectScopes
import org.drools.runtime.StatefulKnowledgeSession; //导入依赖的package包/类
/**
* Method to evaluate rules in inner project scopes.
* @param ksession Drools Knowledge session.
*/
private void evaluateInnerProjectScopes(StatefulKnowledgeSession ksession) {
LinkedHashMap<String, Integer> importedProjectMap = droolsVisitor.getImportedProjectMap();
Iterator<String> itr = importedProjectMap.keySet().iterator();
while (itr.hasNext()) {
String projectN = itr.next();
for (int i = 0; i < importedProjectMap.get(projectN); i++) {
ksession.getAgenda().getAgendaGroup("Group 0_" + i + projectN).setFocus();
ksession.fireAllRules();
ksession.getAgenda().getAgendaGroup("Group 2_" + i + projectN).setFocus();
ksession.fireAllRules();
}
ksession.getAgenda().getAgendaGroup("Group 2" + projectN).setFocus();
ksession.fireAllRules();
}
}
示例10: addGlobals
import org.drools.runtime.StatefulKnowledgeSession; //导入依赖的package包/类
/**
* Method to add globals.
*
* @param ksession Drools Knowledge session.
*/
private void addGlobals(StatefulKnowledgeSession ksession) {
ksession.setGlobal("cList", new ArrayList<Integer>());
ksession.setGlobal("dList", new ArrayList<String>());
ksession.setGlobal("vList", new ArrayList<String>());
ksession.setGlobal("fList", new ArrayList<String>());
ArrayList<String> definedList = (ArrayList<String>) droolsVisitor.getdList();
java.util.Set<String> tempSet = new HashSet<String>();
tempSet.addAll(definedList);
definedList.removeAll(definedList);
definedList.addAll(tempSet);
@SuppressWarnings("unchecked")
List<String> defL = (ArrayList<String>) ksession.getGlobal("dList");
for (int i = 0; i < definedList.size(); i++) {
defL.add(definedList.get(i));
}
Map<String, Integer> enumMap = new HashMap<String, Integer>();
enumMap = droolsVisitor.getEnumMap();
Iterator<String> itr = enumMap.keySet().iterator();
while (itr.hasNext()) {
String k = itr.next();
ksession.setGlobal(k, enumMap.get(k));
}
}
示例11: 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();
}
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: getStatefulKnowledgeSession
import org.drools.runtime.StatefulKnowledgeSession; //导入依赖的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;
}
}