本文整理汇总了Java中org.drools.runtime.StatefulKnowledgeSession.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java StatefulKnowledgeSession.dispose方法的具体用法?Java StatefulKnowledgeSession.dispose怎么用?Java StatefulKnowledgeSession.dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.drools.runtime.StatefulKnowledgeSession
的用法示例。
在下文中一共展示了StatefulKnowledgeSession.dispose方法的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: 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: executeStatefulRules
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
protected void executeStatefulRules(StatefulKnowledgeSession session, List context) {
handlers = new Hashtable<Object, FactHandle>();
for (Object o : context) {
if (o != null) {
LOG.debug("inserting object " + o);
handlers.put(o, session.insert(o));
} else {
LOG.warn("Attempted to insert a NULL object into the working memeory");
}
}
session.fireAllRules();
session.dispose();
handlers.clear();
handlers = null;
}
示例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: getProcessVariable
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
public Object getProcessVariable(long taskId,String variableName){
Task task=this.getTask(taskId);
StatefulKnowledgeSession session=this.bpmService.getSession(task.getSessionId());
try{
RuleFlowProcessInstance pi=(RuleFlowProcessInstance)session.getProcessInstance(task.getProcessInstanceId());
return pi.getVariable(variableName);
}finally{
session.dispose();
}
}
示例11: startProcess
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
public synchronized ProcessInstance startProcess(String processId) {
StatefulKnowledgeSession ksession = this.bpmService.createSession();
try {
Map<String, Object> map = this.initProcessVariables(null);
ProcessInstance processInstance = ksession.startProcess(processId,map);
return processInstance;
} finally {
ksession.dispose();
}
}
示例12: abortProcessInstance
import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
public synchronized void abortProcessInstance(long processInstanceId) {
StatefulKnowledgeSession ksession = this.bpmService.createSession();
try {
ksession.abortProcessInstance(processInstanceId);
} finally {
ksession.dispose();
}
}
示例13: 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);
}
示例14: 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);
}
示例15: 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);
}