/** * Inserts the current process */ @Override public void insertProcess() { WorkflowProcessInstance process = (WorkflowProcessInstance) ksession.getProcessInstance(this.processInstanceId); ksession.insert(process); }
@Override public void setProcessVariable(String name, Object value) { WorkflowProcessInstance process = (WorkflowProcessInstance) ksession.getProcessInstance(this.processInstanceId); process.setVariable(name, value); }
private void signalEventToProcesses(Event event, StatefulKnowledgeSession session, Set<Long> processIds) { for (Long pid : processIds) { ProcessInstance processInstance = session.getProcessInstance(pid); if (processInstance == null) { LOGGER.warn("processInstance with ID {} not found, maybe it already terminated", pid); } else { processInstance.signalEvent(event.getClass().getSimpleName(), event); } } }
@Override public void waitForFlowToFinish(long id) throws InterruptedException, WorkflowException { StatefulKnowledgeSession session = getSessionForCurrentContext(); synchronized (session) { while (session.getProcessInstance(id) != null) { session.wait(); } } }
@Override public int getNodeInstancesSize() { return ((WorkflowProcessInstance) ksession.getProcessInstance(this.processInstanceId)).getNodeInstances().size(); }
@Override public int getProcessState() { WorkflowProcessInstance process = (WorkflowProcessInstance) ksession.getProcessInstance(this.processInstanceId); return process.getState(); }
@Override public void waitForFlowToFinishIndefinitely(long id) throws InterruptedException, WorkflowException { StatefulKnowledgeSession session = getSessionForCurrentContext(); synchronized (session) { while (session.getProcessInstance(id) != null) { session.wait(); } } }
public ProcessInstance execute(Context context) { StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession(); if (processInstanceId == null) { return null; } return ksession.getProcessInstance(processInstanceId); }
@Override public boolean waitForFlowToFinish(long id, long timeout) throws InterruptedException, WorkflowException { StatefulKnowledgeSession session = getSessionForCurrentContext(); long endTime = System.currentTimeMillis() + timeout; synchronized (session) { while (session.getProcessInstance(id) != null && timeout > 0) { session.wait(timeout); timeout = endTime - System.currentTimeMillis(); } } return !getRunningFlows().contains(id); }
@Override public boolean waitForFlowToFinish(long id, long timeout) throws InterruptedException, WorkflowException { StatefulKnowledgeSession session = getSessionForCurrentContext(); long endTime = System.currentTimeMillis() + timeout; synchronized (session) { while (session.getProcessInstance(id) != null && timeout > 0) { session.wait(timeout); timeout = endTime - System.currentTimeMillis(); } } return !getRunningFlows().contains(id); }
public static void abortProcessInstance(String processInstanceIdString) { StatefulKnowledgeSession session = getSession(); Long processInstanceId = new Long(processInstanceIdString); if ( session.getProcessInstance(processInstanceId) != null) { session.abortProcessInstance(processInstanceId); } else { throw new IllegalArgumentException("Could not find process instance " + processInstanceId); } }
@Override public ProcessBag getProcessBagForInstance(long instanceId) { StatefulKnowledgeSession session = getSessionForCurrentContext(); ProcessInstance instance = session.getProcessInstance(instanceId); if (instance == null || !(instance instanceof WorkflowProcessInstance)) { throw new IllegalArgumentException("Process instance with id " + instanceId + " not found"); } return (ProcessBag) ((WorkflowProcessInstance) instance).getVariable("processBag"); }
@Override public ProcessBag getProcessBagForInstance(long instanceId) { StatefulKnowledgeSession session = getSessionForCurrentContext(); ProcessInstance instance = session.getProcessInstance(instanceId); if (instance == null || !(instance instanceof WorkflowProcessInstance)) { throw new IllegalArgumentException("Process instance with id " + instanceId + " not found"); } return (ProcessBag) ((WorkflowProcessInstance) instance).getVariable("processBag"); }
@SuppressWarnings("deprecation") // will be removed in 3.0 (OPENENGSB-2789) private void signalEventToProcesses(Event event, StatefulKnowledgeSession session, Set<Long> processIds) { for (Long pid : processIds) { ProcessInstance processInstance = session.getProcessInstance(pid); if (processInstance == null) { LOGGER.warn("processInstance with ID {} not found, maybe it already terminated", pid); } else { processInstance.signalEvent(event.getType(), event); } } }
public int getProcessState() { StatefulKnowledgeSession ksession = this.getKnowledgeSession(); try { WorkflowProcessInstance process = (WorkflowProcessInstance) ksession.getProcessInstance(this.processInstanceId); return process.getState(); } finally { ksession.dispose(); } }
public Object execute(Context context) { StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession(); if (processInstanceId == -1) { ksession.signalEvent(eventType, event); } else { ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId); if (processInstance != null) { processInstance.signalEvent(eventType, event); } } return null; }
@Override public String getCurrentNodeName() { WorkflowProcessInstance process = (WorkflowProcessInstance) ksession.getProcessInstance(this.processInstanceId); long nodeId = process.getNodeInstances().iterator().next().getNodeId(); return ((WorkflowProcess) this.kbase.getProcess(this.processId)).getNode(nodeId).getName(); }
public Object getProcessVariable(String name) { StatefulKnowledgeSession ksession = this.getKnowledgeSession(); try{ WorkflowProcessInstance process = (WorkflowProcessInstance) ksession.getProcessInstance(this.processInstanceId); return process.getVariable(name); } finally{ ksession.dispose(); } }
public void setProcessVariable(String name, Object value) { StatefulKnowledgeSession ksession = this.getKnowledgeSession(); WorkflowProcessInstance process = (WorkflowProcessInstance) ksession.getProcessInstance(this.processInstanceId); process.setVariable(name, value); ksession.dispose(); }
public static Collection<NodeInstance> getActiveNodeInstances(long processInstanceId) { ProcessInstance processInstance = getSession().getProcessInstance(processInstanceId); if (processInstance != null){ ((ProcessInstanceImpl)processInstance).setProcess(getSession().getKnowledgeBase().getProcess(processInstance.getProcessId())); Collection<NodeInstance> activeNodes = ((WorkflowProcessInstance)processInstance).getNodeInstances(); activeNodes.addAll(collectActiveNodeInstances(activeNodes)); return activeNodes; } return null; }