public boolean isActive() { Boolean active = (Boolean) kruntime.getEnvironment().get("Active"); if (active == null) { return true; } return active.booleanValue(); }
protected boolean useTimerSLATracking() { String mode = (String) getKnowledgeRuntime().getEnvironment().get("SLATimerMode"); if (mode == null) { return true; } return Boolean.parseBoolean(mode); }
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; }
protected boolean actAsWaitState() { Object asWaitState = getProcessInstance().getKnowledgeRuntime().getEnvironment().get(ACT_AS_WAIT_STATE_PROPERTY); if (asWaitState != null) { return Boolean.parseBoolean(asWaitState.toString()); } return false; }
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; }
@Override public ProcessInstance getProcessInstance(CorrelationKey correlationKey) { ProcessPersistenceContext context = ((ProcessPersistenceContextManager) this.kruntime.getEnvironment() .get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER )) .getProcessPersistenceContext(); Long processInstanceId = context.getProcessInstanceByCorrelationKey(correlationKey); if (processInstanceId == null) { return null; } return getProcessInstance(processInstanceId); }
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()); } } }
protected ExecutionErrorHandler getExecutionErrorHandler() { ExecutionErrorManager errorManager = (ExecutionErrorManager) getProcessInstance().getKnowledgeRuntime().getEnvironment().get(EnvironmentName.EXEC_ERROR_MANAGER); if (errorManager == null) { return new NoOpExecutionErrorHandler(); } return errorManager.getHandler(); }
public NodeInstance getNodeInstance(final Node node) { Node actualNode = node; // async continuation handling if (node instanceof AsyncEventNode) { actualNode = ((AsyncEventNode) node).getActualNode(); } else if (useAsync(node)) { actualNode = new AsyncEventNode(node); } NodeInstanceFactory conf = NodeInstanceFactoryRegistry.getInstance(getKnowledgeRuntime().getEnvironment()).getProcessNodeInstanceFactory(actualNode); if (conf == null) { throw new IllegalArgumentException("Illegal node type: " + node.getClass()); } NodeInstanceImpl nodeInstance = (NodeInstanceImpl) conf.getNodeInstance(actualNode, this, this); if (nodeInstance == null) { throw new IllegalArgumentException("Illegal node type: " + node.getClass()); } if (((NodeInstanceImpl) nodeInstance).isInversionOfControl()) { getKnowledgeRuntime().insert(nodeInstance); } return nodeInstance; }
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; }
private void startProcessWithParamsAndTrigger(String processId, Map<String, Object> params, String type, boolean dispose) { RuntimeManager manager = (RuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER); if (manager != null) { org.kie.api.runtime.manager.Context<?> context = ProcessInstanceIdContext.get(); String caseId = (String) kruntime.getEnvironment().get(EnvironmentName.CASE_ID); if (caseId != null) { context = CaseContext.get(caseId); } RuntimeEngine runtime = manager.getRuntimeEngine(context); KieSession ksession = runtime.getKieSession(); try { ksession.execute(new StartProcessWithTypeCommand(processId, params, type)); } finally { if (dispose) { manager.disposeRuntimeEngine(runtime); } } } else { startProcess( processId, params, type ); } }
public Integer execute(Context context) { SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession(); ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime .getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER); ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext(); List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal"); return processInstancesToSignalList.size(); } });
public Integer execute(Context context) { SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession(); ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime .getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER); ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext(); List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal"); return processInstancesToSignalList.size(); } });
public Integer execute(Context context) { SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession(); ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime .getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER); ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext(); List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal"); return processInstancesToSignalList.size(); } });
protected TimerInstance createTimerInstance(Timer timer, InternalKnowledgeRuntime kruntime) { TimerInstance timerInstance = new TimerInstance(); if (kruntime != null && kruntime.getEnvironment().get("jbpm.business.calendar") != null){ BusinessCalendar businessCalendar = (BusinessCalendar) kruntime.getEnvironment().get("jbpm.business.calendar"); String delay = timer.getDelay(); timerInstance.setDelay(businessCalendar.calculateBusinessTimeAsDuration(delay)); if (timer.getPeriod() == null) { timerInstance.setPeriod(0); } else { String period = timer.getPeriod(); timerInstance.setPeriod(businessCalendar.calculateBusinessTimeAsDuration(period)); } } else { configureTimerInstance(timer, timerInstance); } timerInstance.setTimerId(timer.getId()); return timerInstance; }
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(); } }
public void addProcessInstance(ProcessInstance processInstance, CorrelationKey correlationKey) { ProcessInstanceInfo processInstanceInfo = new ProcessInstanceInfo( processInstance, this.kruntime.getEnvironment() ); ProcessPersistenceContext context = ((ProcessPersistenceContextManager) this.kruntime.getEnvironment() .get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER )) .getProcessPersistenceContext(); processInstanceInfo = (ProcessInstanceInfo) context.persist( processInstanceInfo ); ((org.jbpm.process.instance.ProcessInstance) processInstance).setId( processInstanceInfo.getId() ); processInstanceInfo.updateLastReadDate(); // generate correlation key if not given which is same as process instance id to keep uniqueness if (correlationKey == null) { correlationKey = new CorrelationKeyInfo(); ((CorrelationKeyInfo)correlationKey).addProperty(new CorrelationPropertyInfo(null, processInstanceInfo.getId().toString())); ((org.jbpm.process.instance.ProcessInstance) processInstance).getMetaData().put("CorrelationKey", correlationKey); } CorrelationKeyInfo correlationKeyInfo = (CorrelationKeyInfo) correlationKey; correlationKeyInfo.setProcessInstanceId(processInstanceInfo.getId()); context.persist(correlationKeyInfo); internalAddProcessInstance(processInstance); EventManagerProvider.getInstance().get().create(getInstanceViewFor(processInstance)); }
public void removeProcessInstance(ProcessInstance processInstance) { ProcessPersistenceContext context = ((ProcessPersistenceContextManager) this.kruntime.getEnvironment().get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER )).getProcessPersistenceContext(); ProcessInstanceInfo processInstanceInfo = (ProcessInstanceInfo) context.findProcessInstanceInfo( processInstance.getId() ); if ( processInstanceInfo != null ) { context.remove( processInstanceInfo ); } internalRemoveProcessInstance(processInstance); EventManagerProvider.getInstance().get().delete(getInstanceViewFor(processInstance)); }
protected Environment getEnvironment(JobContext jobContext) { JobContext ctxorig = jobContext; if (ctxorig instanceof SelfRemovalJobContext) { ctxorig = ((SelfRemovalJobContext) ctxorig).getJobContext(); } // first attempt to get knowledge runtime's environment if job context is a process one if (ctxorig instanceof ProcessJobContext) { return ((ProcessJobContext) ctxorig).getKnowledgeRuntime().getEnvironment(); } else { // next if we have manager set use it to get ksession's environment of active RuntimeEngine // while running this there must be an active RuntimeEngine present if (manager != null) { RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(getProcessInstancId(ctxorig))); return engine.getKieSession().getEnvironment(); } else { // last resort use the runtime environment's environment template return environment.getEnvironment(); } } }
protected TimerInstance createTimerInstance(InternalKnowledgeRuntime kruntime) { Timer timer = getTimerNode().getTimer(); TimerInstance timerInstance = new TimerInstance(); if (kruntime != null && kruntime.getEnvironment().get("jbpm.business.calendar") != null){ BusinessCalendar businessCalendar = (BusinessCalendar) kruntime.getEnvironment().get("jbpm.business.calendar"); String delay = resolveVariable(timer.getDelay()); timerInstance.setDelay(businessCalendar.calculateBusinessTimeAsDuration(delay)); if (timer.getPeriod() == null) { timerInstance.setPeriod(0); } else { String period = resolveVariable(timer.getPeriod()); timerInstance.setPeriod(businessCalendar.calculateBusinessTimeAsDuration(period)); } } else { configureTimerInstance(timer, timerInstance); } timerInstance.setTimerId(timer.getId()); return timerInstance; }