public boolean isActive() { Boolean active = (Boolean) kruntime.getEnvironment().get("Active"); if (active == null) { return true; } return active.booleanValue(); }
ByteArrayInputStream bais = new ByteArrayInputStream( processInstanceByteArray ); MarshallerReaderContext context = new MarshallerReaderContext( bais, (InternalKnowledgeBase) kruntime.getKieBase(), null, null, context.wm = ((StatefulKnowledgeSessionImpl) kruntime).getInternalWorkingMemory(); processInstance = marshaller.readProcessInstance(context); ((WorkflowProcessInstanceImpl) processInstance).setPersisted(false); if (readOnly) { ((WorkflowProcessInstanceImpl) processInstance).disconnect(); ((WorkflowProcessInstanceImpl) processInstance).internalSetStartDate(this.startDate); return processInstance;
public void cancel() { super.cancel(); if (getSubProcessNode() == null || !getSubProcessNode().isIndependent()) { ProcessInstance processInstance = null; InternalKnowledgeRuntime kruntime = ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime(); RuntimeManager manager = (RuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER); if (manager != null) { try { org.kie.api.runtime.manager.Context<?> context = ProcessInstanceIdContext.get(processInstanceId); String caseId = (String) kruntime.getEnvironment().get(EnvironmentName.CASE_ID); if (caseId != null) { context = CaseContext.get(caseId); } RuntimeEngine runtime = manager.getRuntimeEngine(context); KieRuntime managedkruntime = (KieRuntime) runtime.getKieSession(); processInstance = (ProcessInstance) managedkruntime.getProcessInstance(processInstanceId); } catch (SessionNotFoundException e) { // in case no session is found for parent process let's skip signal for process instance completion } } else { processInstance = (ProcessInstance) kruntime.getProcessInstance(processInstanceId); } if (processInstance != null) { processInstance.setState(ProcessInstance.STATE_ABORTED); } } }
@Override public ProcessInstance createProcessInstance(String processId, CorrelationKey correlationKey, Map<String, Object> parameters) { try { kruntime.startOperation(); final Process process = kruntime.getKieBase().getProcess( processId ); if ( process == null ) { throw new IllegalArgumentException( "Unknown process ID: " + processId ); } return startProcess( process, correlationKey, parameters ); } finally { kruntime.endOperation(); } }
public void initStartTimers() { KieBase kbase = kruntime.getKieBase(); Collection<Process> processes = kbase.getProcesses(); for (Process process : processes) { RuleFlowProcess p = (RuleFlowProcess) process; List<StartNode> startNodes = p.getTimerStart(); if (startNodes != null && !startNodes.isEmpty()) { kruntime.queueWorkingMemoryAction(new RegisterStartTimerAction(p.getId(), startNodes, this.timerManager)); } } }
public TimerInstance configureSLATimer(String slaDueDateExpression) { // setup SLA if provided slaDueDateExpression = resolveVariable(slaDueDateExpression); if (slaDueDateExpression == null || slaDueDateExpression.trim().isEmpty()) { logger.debug("Sla due date expression resolved to no value '{}'", slaDueDateExpression); return null; } logger.debug("SLA due date is set to {}", slaDueDateExpression); InternalKnowledgeRuntime kruntime = getKnowledgeRuntime(); long duration = -1; if (kruntime != null && kruntime.getEnvironment().get("jbpm.business.calendar") != null){ BusinessCalendar businessCalendar = (BusinessCalendar) kruntime.getEnvironment().get("jbpm.business.calendar"); duration = businessCalendar.calculateBusinessTimeAsDuration(slaDueDateExpression); } else { duration = DateTimeUtils.parseDuration(slaDueDateExpression); } TimerInstance timerInstance = new TimerInstance(); timerInstance.setId(-1); timerInstance.setDelay(duration); timerInstance.setPeriod(0); if (useTimerSLATracking()) { ((InternalProcessRuntime)kruntime.getProcessRuntime()).getTimerManager().registerTimer(timerInstance, this); } return timerInstance; }
InternalKnowledgeRuntime kruntime = getKnowledgeRuntime(); InternalProcessRuntime processRuntime = (InternalProcessRuntime) kruntime.getProcessRuntime(); processRuntime.getProcessEventSupport().fireBeforeProcessCompleted(this, kruntime); processRuntime.getTimerManager().cancelTimer(this.slaTimerId); logger.debug("SLA Timer {} has been canceled", this.slaTimerId); removeEventListeners(); processRuntime.getProcessInstanceManager().removeProcessInstance(this); processRuntime.getProcessEventSupport().fireAfterProcessCompleted(this, kruntime); if (isSignalCompletion()) { RuntimeManager manager = (RuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER); if (getParentProcessInstanceId() > 0 && manager != null) { try { org.kie.api.runtime.manager.Context<?> context = ProcessInstanceIdContext.get(getParentProcessInstanceId()); String caseId = (String) kruntime.getEnvironment().get(EnvironmentName.CASE_ID); if (caseId != null) { context = CaseContext.get(caseId);
protected boolean useAsync(final Node node) { if (!(node instanceof EventSubProcessNode) && (node instanceof ActionNode || node instanceof StateBasedNode || node instanceof EndNode)) { boolean asyncMode = Boolean.parseBoolean((String)node.getMetaData().get("customAsync")); if (asyncMode) { return asyncMode; } return Boolean.parseBoolean((String)getProcessInstance().getKnowledgeRuntime().getEnvironment().get("AsyncMode")); } return false; }
= (ProcessPersistenceContextManager) getKnowledgeRuntime().getEnvironment().get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER ); ProcessPersistenceContext context = contextManager.getProcessPersistenceContext(); List<Long> processInstancesToSignalList = context.getProcessInstancesWaitingForEvent(actualSignalType); RuntimeManager runtimeManager = ((RuntimeManager)getKnowledgeRuntime().getEnvironment().get("RuntimeManager")); ExecutorService executorService = (ExecutorService) getKnowledgeRuntime().getEnvironment().get("ExecutorService"); if (runtimeManager != null && executorService != null) { getKnowledgeRuntime().getProcessInstance( id ); } catch (IllegalStateException e) {
protected boolean useAsync(final Node node) { if (!(node instanceof EventSubProcessNode) && (node instanceof ActionNode || node instanceof StateBasedNode || node instanceof EndNode)) { boolean asyncMode = Boolean.parseBoolean((String)node.getMetaData().get("customAsync")); if (asyncMode) { return asyncMode; } return Boolean.parseBoolean((String)getKnowledgeRuntime().getEnvironment().get("AsyncMode")); } return false; }
Map<String, Object> parameters) { ProcessInstance processInstance = (ProcessInstance) createProcessInstance(); processInstance.setKnowledgeRuntime( kruntime ); processInstance.setProcess( process ); processInstance.getMetaData().put("CorrelationKey", correlationKey); InternalRuntimeManager manager = (InternalRuntimeManager) kruntime.getEnvironment().get("RuntimeManager"); if (manager != null) { processInstance.setDeploymentId(manager.getIdentifier()); ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessInstanceManager() .addProcessInstance( processInstance, correlationKey );
public void internalTrigger(final NodeInstance from, String type) { super.internalTrigger(from, type); if (getNodeInstanceContainer().getNodeInstance(getId()) == null) { return; addWorkItemListener(); String deploymentId = (String) getProcessInstance().getKnowledgeRuntime().getEnvironment().get(EnvironmentName.DEPLOYMENT_ID); ((WorkItem) workItem).setDeploymentId(deploymentId); ((WorkItem) workItem).setNodeInstanceId(this.getId()); ((WorkItem) workItem).setNodeId(getNodeId()); if (isInversionOfControl()) { ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime() .update(((ProcessInstance) getProcessInstance()).getKnowledgeRuntime().getFactHandle(this), this); } else { try { ((WorkItemManager) ((ProcessInstance) getProcessInstance()) .getKnowledgeRuntime().getWorkItemManager()).internalExecuteWorkItem( (org.drools.core.process.instance.WorkItem) workItem); } catch (WorkItemHandlerNotFoundException wihnfe) { getProcessInstance().setState(ProcessInstance.STATE_ABORTED); throw wihnfe; } catch (ProcessWorkItemHandlerException handlerException) {
public void internalTrigger(final NodeInstance from, String type) { super.internalTrigger(from, type); if (getNodeInstanceContainer().getNodeInstance(getId()) == null) { return; processId = processId.replace("#{" + replacement.getKey() + "}", replacement.getValue()); KieBase kbase = ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime().getKieBase(); String caseId = (String) kruntime.getEnvironment().get(EnvironmentName.CASE_ID); if (caseId != null) { context = CaseContext.get(caseId); if (((WorkflowProcessInstanceImpl)getProcessInstance()).getCorrelationKey() != null) { businessKeys.add(((WorkflowProcessInstanceImpl)getProcessInstance()).getCorrelationKey()); businessKeys.add(processId); businessKeys.add(String.valueOf(System.currentTimeMillis())); this.processInstanceId = processInstance.getId(); ((ProcessInstanceImpl) processInstance).setMetaData("ParentProcessInstanceId", getProcessInstance().getId()); ((ProcessInstanceImpl) processInstance).setMetaData("ParentNodeInstanceId", getUniqueId()); ((ProcessInstanceImpl) processInstance).setMetaData("ParentNodeId", getSubProcessNode().getUniqueId()); ((ProcessInstanceImpl) processInstance).setParentProcessInstanceId(getProcessInstance().getId()); ((ProcessInstanceImpl) processInstance).setSignalCompletion(getSubProcessNode().isWaitForCompletion());
public ProcessInstance getProcessInstance(long id, boolean readOnly) { InternalRuntimeManager manager = (InternalRuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER); if (manager != null) { manager.validate((KieSession) kruntime, ProcessInstanceIdContext.get(id)); TransactionManager txm = (TransactionManager) this.kruntime.getEnvironment().get( EnvironmentName.TRANSACTION_MANAGER ); org.jbpm.process.instance.ProcessInstance processInstance = null; processInstance = (org.jbpm.process.instance.ProcessInstance) this.processInstances.get(id); if (processInstance != null) { if (((WorkflowProcessInstanceImpl) processInstance).isPersisted() && !readOnly) { ProcessPersistenceContextManager ppcm = (ProcessPersistenceContextManager) this.kruntime.getEnvironment().get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER ); ppcm.beginCommandScopedEntityManager(); ProcessPersistenceContext context = ppcm.getProcessPersistenceContext(); = (ProcessPersistenceContextManager) this.kruntime.getEnvironment().get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER ); ppcm.beginCommandScopedEntityManager(); processInstanceInfo.getProcessInstance(kruntime, this.kruntime.getEnvironment(), readOnly); if (!readOnly) { processInstanceInfo.updateLastReadDate(); Process process = kruntime.getKieBase().getProcess( processInstance.getProcessId() ); if ( process == null ) { throw new IllegalArgumentException( "Could not find process " + processInstance.getProcessId() ); if ( processInstance.getKnowledgeRuntime() == null ) { Long parentProcessInstanceId = (Long) ((ProcessInstanceImpl) processInstance).getMetaData().get("ParentProcessInstanceId"); if (parentProcessInstanceId != null) { kruntime.getProcessInstance(parentProcessInstanceId);
public void internalTrigger(final NodeInstance from, String type) { super.internalTrigger(from, type); ExecutorService executorService = (ExecutorService) getProcessInstance().getKnowledgeRuntime().getEnvironment().get("ExecutorService"); if (executorService != null) { RuntimeManager runtimeManager = ((RuntimeManager)getProcessInstance().getKnowledgeRuntime().getEnvironment().get("RuntimeManager")); CommandContext ctx = new CommandContext(); ctx.setData("deploymentId", runtimeManager.getIdentifier()); ctx.setData("processInstanceId", getProcessInstance().getId()); ctx.setData("Signal", getEventType()); ctx.setData("Event", null); executorService.scheduleRequest(AsyncSignalEventCommand.class.getName(), ctx); Node node = getNode(); if (node != null) { String uniqueId = (String) node.getMetaData().get("UniqueId"); if( uniqueId == null ) { uniqueId = ((NodeImpl) node).getUniqueId(); } ((WorkflowProcessInstanceImpl) getProcessInstance()).getIterationLevels().remove(getNode().getMetaData().get("UniqueId")); } } else { logger.warn("No async executor service found continuing as sync operation..."); // if there is no executor service available move as sync node triggerCompleted(); } }
private void validate() { InternalRuntimeManager manager = (InternalRuntimeManager) getKnowledgeRuntime().getEnvironment().get("RuntimeManager"); if (manager != null) { // check if process instance is owned by the same manager as the one owning ksession if (hasDeploymentId() && !manager.getIdentifier().equals(getDeploymentId())) { throw new IllegalStateException("Process instance " + getId() + " is owned by another deployment " + getDeploymentId() + " != " + manager.getIdentifier()); } } }
Node node = getNode(); if (node != null) { String uniqueId = (String) node.getMetaData().get("UniqueId"); if( uniqueId == null ) { uniqueId = ((NodeImpl) node).getUniqueId(); ((WorkflowProcessInstanceImpl) processInstance).addCompletedNodeId(uniqueId); ((WorkflowProcessInstanceImpl) processInstance).getIterationLevels().remove(uniqueId); if ((getNodeInstanceContainer().getNodeInstance(getId()) == null) || (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE)) { return; throw new IllegalArgumentException( "Uncontrolled flow node could not find at least one valid outgoing connection " + getNode().getName() ); connections = node.getOutgoingConnections(type); hidden = true; InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime(); if (!hidden) { ((InternalProcessRuntime) kruntime.getProcessRuntime()) .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime); .nodeInstanceCompleted(this, type); if (!hidden) { ((InternalProcessRuntime) kruntime.getProcessRuntime()) .getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
protected boolean useTimerSLATracking() { String mode = (String) getKnowledgeRuntime().getEnvironment().get("SLATimerMode"); if (mode == null) { return true; } return Boolean.parseBoolean(mode); }
protected boolean actAsWaitState() { Object asWaitState = getProcessInstance().getKnowledgeRuntime().getEnvironment().get(ACT_AS_WAIT_STATE_PROPERTY); if (asWaitState != null) { return Boolean.parseBoolean(asWaitState.toString()); } return false; }
@Override public Void execute(org.kie.api.runtime.Context context) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); ksession.getEnvironment().set("Active", false); InternalProcessRuntime processRuntime = ((InternalKnowledgeRuntime) ksession).getProcessRuntime(); ((ProcessRuntimeImpl) processRuntime).removeProcessEventListeners(); return null; } });