@Override protected XpdlExecution newChildExecution() { final XpdlExecution child = new XpdlExecution(); child.xpdlInstance = this.getXpdlInstance(); child.iterationId = this.getIterationId(); return child; }
protected XpdlExecution createChildExecution(XpdlExecution parentExecution, int childId) { String executionName = parentExecution.getName() + "/" + childId; XpdlExecution childExecution = (XpdlExecution) parentExecution.createExecution(executionName); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating child execution with name " + childExecution.getName()); } return childExecution; }
protected void end(final XpdlExecution xpdlExecution) { final ActivityInstanceCurrentInfo activityInstanceCurrentInfo = new ActivityInstanceCurrentInfo( xpdlExecution.getXpdlInstance().getPackageDefinitionUUID(), xpdlExecution.getXpdlInstance().getProcessDefinitionUUID(), xpdlExecution.getXpdlInstance().getUUID(), xpdlExecution.getCurrentActivityInstanceUUID(), this.getActivityType(), this.getActivityId(), xpdlExecution.getIterationId(), xpdlExecution.getActivityInstanceId(), xpdlExecution.getScopeVariables()); ServiceEnvTool.getRecorder().recordBodyEnded(activityInstanceCurrentInfo); if (!XpdlExecution.MAIN_INSTANCE_NAME.equals(xpdlExecution.getActivityInstanceId())) { final XpdlExecution activityInstanceExecution = (XpdlExecution) xpdlExecution.destroyScope(xpdlExecution.getNode()); activityInstanceExecution.end(); final XpdlExecution parent = activityInstanceExecution.getParent(); parent.removeExecution(activityInstanceExecution); this.signal(parent, AbstractActivity.ACT_INSTANCE_FINISHED, null); } else { this.executeSplit(xpdlExecution, true); } }
@Override protected void end(XpdlExecution xpdlExecution) { xpdlExecution = (XpdlExecution) xpdlExecution.destroyScope(xpdlExecution.getNode()); xpdlExecution.end(); XpdlExecution parent = xpdlExecution.getParent(); if (parent != null) { parent.removeExecution(xpdlExecution); } } }
if (xpdlExecution.getXpdlInstance().getInstanceState().equals(InstanceState.FINISHED)) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("XPDLInstance ended : " + xpdlExecution.getXpdlInstance()); xpdlExecution.end(); XpdlExecution parent = xpdlExecution.getParent(); if (parent != null) { parent.removeExecution(xpdlExecution); ProcessInstanceUUID instanceUUID = xpdlExecution.getXpdlInstance().getUUID(); MultiInstantiator actInstantiator = ClassDataLoader.getActivityInstantiatorInstance( xpdlExecution.getXpdlInstance().getPackageDefinitionUUID(), multiInstantiationClass); try { actInstDescr = actInstantiator.execute( AccessorUtil.getQueryAPIAccessor(), instanceUUID, activityId, xpdlExecution.getIterationId()); if (actInstDescr == null) { throw new BonitaRuntimeException("MultiInstantiator execution returned null in activity " + activityId); xpdlExecution.setWaitingForActivityInstanceNb(actInstDescr.getJoinNumber()); int childId = 0; for (Object value : actInstDescr.getVariableValues()) { XpdlExecution childExec = createChildExecution(xpdlExecution, childId); childExec = (XpdlExecution) childExec.createScope(xpdlExecution.getNode()); childExec.setVariable(multiInstantiationVariable, value); childExec.setActivityInstanceId(Integer.toString(childId)); executeActivityInstance(childExec); childId++;
public void abort() { if (this.getExecutions() != null) { for (final OpenExecution child : new ArrayList<OpenExecution>(this.getExecutions())) { ((XpdlExecution) child).abort(); if (this.getCurrentActivityInstanceUUID() != null) { final AbstractActivity activity = (AbstractActivity) this.getNode().getBehaviour(); final XpdlInstance childInstance = this.getSubflowXpdlInstance(); childInstance.getRootExecution().abort(); childInstance.setInstanceState(InstanceState.ABORTED); childInstance.setExecutionToSignal(null); childInstance.getUUID(), childInstance.getParentInstance().getUUID(), childInstance.getRootExecution().getVariables(), ServiceEnvTool.getUserId()) ); this.getXpdlInstance().getPackageDefinitionUUID(), this.getXpdlInstance().getProcessDefinitionUUID(), this.getXpdlInstance().getUUID(), this.getCurrentActivityInstanceUUID(), activity.getActivityType(), activity.getActivityId(), this.getIterationId(), this.getActivityInstanceId(), this.getScopeVariables()); end(Execution.STATE_CANCELLED);
protected void executeSplit(final Execution execution, final boolean removeScope) { XpdlExecution xpdlExecution = (XpdlExecution) execution; final NodeImpl currentNode = xpdlExecution.getNode(); if (AbstractActivity.LOG.isLoggable(Level.FINE)) { AbstractActivity.LOG.fine("node = " + currentNode.getName() + " - splitType = " xpdlExecution.end(); final XpdlExecution parent = xpdlExecution.getParent(); if (parent != null) { parent.removeExecution(xpdlExecution); if ( xpdlExecution .getXpdlInstance() .getTransitionStatus(t) .getState().equals(TransitionState.READY) ) { xpdlExecution.getXpdlInstance().setTransitionState(t, TransitionState.TAKEN); transitionsToTake.add(t); xpdlExecution = (XpdlExecution) xpdlExecution.destroyScope(currentNode); xpdlExecution.setCurrentActivityInstanceUUID(null); if (transitionsToTake.size() == 0) { xpdlExecution.end(); final XpdlExecution parent = xpdlExecution.getParent(); if (parent != null) { parent.removeExecution(xpdlExecution); final NodeImpl nodeToAbort = nodeToAbortDescr.getNode();
@Override public void cancel() { if (this.getExecutions() != null) { for (final OpenExecution child : new ArrayList<OpenExecution>(this.getExecutions())) { ((XpdlExecution) child).cancel(); if (this.getCurrentActivityInstanceUUID() != null) { final AbstractActivity activity = (AbstractActivity) this.getNode().getBehaviour(); final XpdlInstance childInstance = this.getSubflowXpdlInstance(); childInstance.cancel(); break; this.getXpdlInstance().getPackageDefinitionUUID(), this.getXpdlInstance().getProcessDefinitionUUID(), this.getXpdlInstance().getUUID(), this.getCurrentActivityInstanceUUID(), activity.getActivityType(), activity.getActivityId(), this.getIterationId(), this.getActivityInstanceId(), this.getScopeVariables()); end(Execution.STATE_CANCELLED); final XpdlExecution parent = this.getParent(); if (parent != null) { parent.removeExecution(this);
@Override protected boolean executeBusinessLogic(final Execution execution) { final XpdlExecution xpdlExecution = (XpdlExecution) execution; final XpdlInstance xpdlInstance = xpdlExecution.getXpdlInstance(); xpdlInstance.setInstanceState(InstanceState.FINISHED); final Recorder recorder = ServiceEnvTool.getRecorder(); xpdlInstance.getProcessDefinitionUUID(), xpdlInstance.getUUID(), xpdlExecution.getCurrentActivityInstanceUUID(), this.getActivityType(), this.getActivityId(), xpdlExecution.getIterationId(), xpdlExecution.getActivityInstanceId(), xpdlExecution.getScopeVariables()); xpdlInstance.getUUID(), (xpdlInstance.getParentInstance() != null) ? xpdlInstance.getParentInstance().getUUID() : null, xpdlExecution.getVariables(), ServiceEnvTool.getUserId()) ); final List<ProcessParameter> processParameters = xpdlExecution.getProcessDefinition().getParameters(); if (processParameters != null) { parameterValues = new HashMap<String, Object>(); ) { final String parameterName = processParameter.getName(); parameterValues.put(parameterName, xpdlExecution.getVariable(parameterName));
private boolean executeBody(final XpdlExecution xpdlExecution) { if (this.bodyStartAutomatically()) { final ActivityInstanceCurrentInfo activityInstanceCurrentInfo = new ActivityInstanceCurrentInfo( xpdlExecution.getXpdlInstance().getPackageDefinitionUUID(), xpdlExecution.getXpdlInstance().getProcessDefinitionUUID(), xpdlExecution.getXpdlInstance().getUUID(), xpdlExecution.getCurrentActivityInstanceUUID(), this.getActivityType(), this.getActivityId(), xpdlExecution.getIterationId(), xpdlExecution.getActivityInstanceId(), xpdlExecution.getScopeVariables()); ServiceEnvTool.getRecorder().recordBodyStarted(activityInstanceCurrentInfo); } return this.executeBusinessLogic(xpdlExecution); }
protected void executeSplit(Execution execution, boolean removeScope) { XpdlExecution xpdlExecution = (XpdlExecution) execution; NodeImpl currentNode = xpdlExecution.getNode(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("node = " + currentNode.getName() + " - splitType = " + splitType + " - execution = " + execution.getName() + " no transition available. Ending execution"); xpdlExecution.end(); XpdlExecution parent = xpdlExecution.getParent(); if (parent != null) { parent.removeExecution(xpdlExecution); xpdlExecution = (XpdlExecution) xpdlExecution.destroyScope(currentNode); xpdlExecution.end(); XpdlExecution parent = xpdlExecution.getParent(); if (parent != null) { parent.removeExecution(xpdlExecution); xpdlExecution.take(t); } else { XpdlExecution childExecution = createChildExecution(xpdlExecution, childId++); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Execution " + childExecution.getName() + "is taking transition " + t); childExecution.take(t);
throw new ActivityNotFoundException(activityUUID); if (execution.hasExecution(activityId)) { execution = (XpdlExecution) execution.getExecution(activityId); if (!execution.getScopeVariables().containsKey(variableId)) { throw new VariableNotFoundException(instanceUUID, activityId, variableId); execution.setVariable(variableId, variableValue); recorder.recordActivityVariableUpdated(variableId, variableValue, execution.getXpdlInstance().getUUID(), execution.getNode().getName(), execution.getIterationId(), execution.getActivityInstanceId(), EnvTool.getUserId());
public void signal(final ActivityExecution execution, final String signal, final Map<String, Object> parameters) { final XpdlExecution xpdlExecution = (XpdlExecution) execution; if (AbstractActivity.BODY_FINISHED.equals(signal)) { this.end(xpdlExecution); } else if (AbstractActivity.ACT_INSTANCE_FINISHED.equals(signal)) { xpdlExecution.setWaitingForActivityInstanceNb(xpdlExecution.getWaitingForActivityInstanceNb() - 1); if (xpdlExecution.getWaitingForActivityInstanceNb() == 0) { if (xpdlExecution.getExecutions() != null) { for (final OpenExecution execToAbort : new ArrayList<OpenExecution>(xpdlExecution.getExecutions())) { ((XpdlExecution) execToAbort).abort(); } } this.executeSplit(xpdlExecution, false); } } else if (signal != null && this.deadlines != null) { for (final String deadline : this.deadlines) { if (deadline.equals(signal)) { Authentication.setUserId(BonitaConstants.SYSTEM_USER); // By default, a deadline does not propagate execution xpdlExecution.waitForSignal(); final String activityId = xpdlExecution.getNode().getName(); final JavaHook javaHook = new JavaHook(signal, JavaHook.Type.onDeadline, true); EngineEnvTool.getHookExecutor() .executeHook(xpdlExecution, activityId, javaHook); return; } } } }
@Override public void signal(ActivityExecution execution, String signal, Map<String, Object> signalParameters) { XpdlExecution xpdlExecution = (XpdlExecution) execution; if (SUBFLOW_SIGNAL.equals(signal)) { if (outParameters != null) { final Recorder recorder = EnvTool.getRecorder(); ProcessInstanceUUID instanceUUID = xpdlExecution.getXpdlInstance().getUUID(); String activityId = xpdlExecution.getNode().getName(); for (Map.Entry<String, String> parameter : outParameters.entrySet()) { String variableId = parameter.getValue(); Object variableValue = signalParameters.get(parameter.getKey()); execution.setVariable(variableId, variableValue); if (xpdlExecution.getXpdlInstance().getRootExecution().hasVariable(variableId)) { recorder.recordInstanceVariableUpdated(variableId, variableValue, instanceUUID, EnvTool.getUserId()); } else { recorder.recordActivityVariableUpdated(variableId, variableValue, instanceUUID, activityId, xpdlExecution.getIterationId(), xpdlExecution.getActivityInstanceId(), EnvTool.getUserId()); } } } super.signal(xpdlExecution, BODY_FINISHED, null); } else { super.signal(xpdlExecution, signal, signalParameters); } }
protected void executeActivityInstance(final XpdlExecution xpdlExecution) { xpdlExecution.setCurrentActivityInstanceUUID( ServiceEnvTool.getUUIDGenerator(). getActivityInstanceUUID(xpdlExecution.getXpdlInstance().getUUID(), this.activityId)); final Recorder recorder = ServiceEnvTool.getRecorder(); final XpdlInstance xpdlInstance = xpdlExecution.getXpdlInstance(); final ActivityInstanceCurrentInfo activityInstanceCurrentInfo = new ActivityInstanceCurrentInfo( xpdlInstance.getPackageDefinitionUUID(), xpdlInstance.getProcessDefinitionUUID(), xpdlInstance.getUUID(), xpdlExecution.getCurrentActivityInstanceUUID(), this.getActivityType(), this.getActivityId(), xpdlExecution.getIterationId(), xpdlExecution.getActivityInstanceId(), xpdlExecution.getScopeVariables()); recorder.recordEnterActivity(activityInstanceCurrentInfo); final boolean canContinue = this.executeBody(xpdlExecution); if (canContinue) { this.end(xpdlExecution); } else { xpdlExecution.waitForSignal(); } }
public void recordEnterActivity(final AbstractActivity activity, final XpdlExecution xpdlExecution) { Misc.checkArgsNotNull(activity, xpdlExecution); final NodeImpl node = xpdlExecution.getNode(); XpdlInstance instance = xpdlExecution.getXpdlInstance(); final String id = node.getName(); final PackageDefinitionUUID packageUUID = instance.getPackageDefinitionUUID(); final ProcessDefinitionUUID processUUID = instance.getProcessDefinitionUUID(); final ProcessInstanceUUID instanceUUID = instance.getUUID(); final String iterationId = xpdlExecution.getIterationId(); final String activityInstanceId = xpdlExecution.getActivityInstanceId(); final ActivityFullInstanceImpl<ActivityBody> activityRecord = new ActivityFullInstanceImpl<ActivityBody>( new ActivityInstanceUUID(instanceUUID, activity.getActivityId(), EnvTool.getRepository().getNextActivityInstanceNb(instanceUUID, activity.getActivityId())), id, packageUUID, processUUID, instanceUUID, iterationId, activityInstanceId); ActivityBody body = activity.getBody(xpdlExecution, activityRecord); activityRecord.setBody(body); ProcessFullInstance processInstance = getProcessInstance(instanceUUID); processInstance.addActivity(activityRecord); activityRecord.setVariablesBeforeReady(xpdlExecution.getScopeVariables()); }
public TaskRunTime(TaskUUID taskUUID, String nodeName, AbstractActivity abstractActivity, XpdlExecution xpdlExecution) { this.taskUUID = taskUUID; this.activityDef = abstractActivity; this.activityId = nodeName; this.xpdlExecution = xpdlExecution; this.instanceUUID = xpdlExecution.getXpdlInstance().getUUID(); this.packageUUID = xpdlExecution.getProcessDefinition().getPackageDefinitionUUID(); this.iterationId = xpdlExecution.getIterationId(); this.activityInstanceId = xpdlExecution.getActivityInstanceId(); }
private XpdlExecution getExecOnNode(XpdlExecution exec, String nodeName, String iterationId, String activityInstanceId) { Misc.checkArgsNotNull(exec, nodeName, iterationId, activityInstanceId); if (exec.getExecutions() == null || exec.getExecutions().isEmpty()) { if (exec.getNode() != null && exec.getNode().getName().equals(nodeName) && exec.getIterationId().equals(iterationId) && exec.getActivityInstanceId().equals(activityInstanceId)) { return exec; } } for (Execution child : exec.getExecutions()) { XpdlExecution found = getExecOnNode((XpdlExecution) child, nodeName, iterationId, activityInstanceId); if (found != null) { return found; } } return null; }
public void recordBodyEnded(AbstractActivity activity, XpdlExecution xpdlExecution) { Misc.checkArgsNotNull(activity, xpdlExecution); final String activityId = activity.getActivityId(); ProcessInstanceUUID instanceUUID = xpdlExecution.getXpdlInstance().getUUID(); final String iterationId = xpdlExecution.getIterationId(); final String activityInstanceId = xpdlExecution.getActivityInstanceId(); ActivityFullInstance<ActivityBody> activityInstance = getActivityInstance(instanceUUID, activityId, iterationId, activityInstanceId); ((ActivityBodyImpl)activityInstance.getBody()).setEndedDate(new Date()); }
public void signal(ActivityExecution execution, String signal, Map<String, Object> parameters) { XpdlExecution xpdlExecution = (XpdlExecution) execution; if (BODY_FINISHED.equals(signal)) { end(xpdlExecution); } else if (ACT_INSTANCE_FINISHED.equals(signal)) { xpdlExecution.setWaitingForActivityInstanceNb(xpdlExecution.getWaitingForActivityInstanceNb() - 1); if (xpdlExecution.getWaitingForActivityInstanceNb() == 0) { // TODO: cancel remaining activity instances executeSplit(xpdlExecution, false); } } else if (signal != null && deadlines != null) { for (String deadline : deadlines) { if (deadline.equals(signal)) { Authentication.setUserId("SYSTEM"); // By default, a deadline does not propagate execution xpdlExecution.waitForSignal(); String activityId = xpdlExecution.getNode().getName(); JavaHook javaHook = new JavaHook(signal, JavaHook.Type.onDeadline, true); HookExecutor.executeHook(xpdlExecution, activityId, javaHook); return; } } } }