use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.
the class IntermediateThrowCompensationEventActivityBehavior method execute.
@Override
public void execute(ActivityExecution execution) throws Exception {
final String activityRef = compensateEventDefinition.getActivityRef();
ExecutionEntity scopeExecution = ScopeUtil.findScopeExecutionForScope((ExecutionEntity) execution, (ActivityImpl) execution.getActivity());
List<CompensateEventSubscriptionEntity> eventSubscriptions;
if (activityRef != null) {
eventSubscriptions = scopeExecution.getCompensateEventSubscriptions(activityRef);
} else {
eventSubscriptions = scopeExecution.getCompensateEventSubscriptions();
}
if (eventSubscriptions.isEmpty()) {
leave(execution);
} else {
// TODO: implement async (waitForCompletion=false in bpmn)
ScopeUtil.throwCompensationEvent(eventSubscriptions, execution, false);
}
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.
the class ParallelMultiInstanceBehavior method leave.
/**
* Called when the wrapped {@link ActivityBehavior} calls the
* {@link AbstractBpmnActivityBehavior#leave(ActivityExecution)} method.
* Handles the completion of one of the parallel instances
*/
public void leave(ActivityExecution execution) {
callActivityEndListeners(execution);
int nrOfInstances = getLoopVariable(execution, NUMBER_OF_INSTANCES);
if (nrOfInstances == 0) {
// Empty collection, just leave.
super.leave(execution);
return;
}
int loopCounter = getLoopVariable(execution, getCollectionElementIndexVariable());
int nrOfCompletedInstances = getLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES) + 1;
int nrOfActiveInstances = getLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES) - 1;
if (isExtraScopeNeeded()) {
// In case an extra scope was created, it must be destroyed first before going further
ExecutionEntity extraScope = (ExecutionEntity) execution;
execution = execution.getParent();
extraScope.remove();
}
if (execution.getParent() != null) {
// will be null in case of empty collection
setLoopVariable(execution.getParent(), NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);
setLoopVariable(execution.getParent(), NUMBER_OF_ACTIVE_INSTANCES, nrOfActiveInstances);
}
logLoopDetails(execution, "instance completed", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances);
ExecutionEntity executionEntity = (ExecutionEntity) execution;
if (executionEntity.getParent() != null) {
executionEntity.inactivate();
executionEntity.getParent().forceUpdate();
List<ActivityExecution> joinedExecutions = executionEntity.findInactiveConcurrentExecutions(execution.getActivity());
if (joinedExecutions.size() >= nrOfInstances || completionConditionSatisfied(execution)) {
// Removing all active child executions (ie because completionCondition is true)
List<ExecutionEntity> executionsToRemove = new ArrayList<ExecutionEntity>();
for (ActivityExecution childExecution : executionEntity.getParent().getExecutions()) {
if (childExecution.isActive()) {
executionsToRemove.add((ExecutionEntity) childExecution);
}
}
for (ExecutionEntity executionToRemove : executionsToRemove) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Execution {} still active, but multi-instance is completed. Removing this execution.", executionToRemove);
}
executionToRemove.inactivate();
executionToRemove.deleteCascade("multi-instance completed");
}
executionEntity.takeAll(executionEntity.getActivity().getOutgoingTransitions(), joinedExecutions);
}
} else {
super.leave(executionEntity);
}
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.
the class SubProcessActivityBehavior method execute.
public void execute(ActivityExecution execution) throws Exception {
PvmActivity activity = execution.getActivity();
ActivityImpl initialActivity = (ActivityImpl) activity.getProperty(BpmnParse.PROPERTYNAME_INITIAL);
if (initialActivity == null) {
throw new ActivitiException("No initial activity found for subprocess " + execution.getActivity().getId());
}
// initialize the template-defined data objects as variables
initializeDataObjects(execution, activity);
if (initialActivity.getActivityBehavior() != null && initialActivity.getActivityBehavior() instanceof NoneStartEventActivityBehavior) {
// embedded subprocess: only none start allowed
((ExecutionEntity) execution).setActivity(initialActivity);
Context.getCommandContext().getHistoryManager().recordActivityStart((ExecutionEntity) execution);
}
execution.executeActivity(initialActivity);
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.
the class TerminateEndEventActivityBehavior method deleteProcessInstance.
protected void deleteProcessInstance(ExecutionEntity processInstanceExecution, ActivityExecution execution, String deleteReason) {
List<ExecutionEntity> orderedExecutions = orderExecutionsRootToLeaf(processInstanceExecution);
Collections.reverse(orderedExecutions);
endAllHistoricActivities(processInstanceExecution.getId());
for (ExecutionEntity executionToDelete : orderedExecutions) {
executionToDelete.setDeleteReason(deleteReason);
executionToDelete.setEnded(true);
executionToDelete.setActive(false);
executionToDelete.setDeleteRoot(true);
executionToDelete.remove();
}
Context.getCommandContext().getHistoryManager().recordProcessInstanceEnd(processInstanceExecution.getId(), deleteReason, execution.getActivity().getId());
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.
the class AbstractBpmnActivityBehavior method createCompensateEventSubscription.
protected void createCompensateEventSubscription(ActivityExecution execution) {
String compensationHandlerId = (String) execution.getActivity().getProperty(BpmnParse.PROPERTYNAME_COMPENSATION_HANDLER_ID);
ExecutionEntity executionEntity = (ExecutionEntity) execution;
ActivityImpl compensationHandlder = executionEntity.getProcessDefinition().findActivity(compensationHandlerId);
PvmScope scopeActivitiy = compensationHandlder.getParent();
ExecutionEntity scopeExecution = ScopeUtil.findScopeExecutionForScope(executionEntity, scopeActivitiy);
CompensateEventSubscriptionEntity compensateEventSubscriptionEntity = CompensateEventSubscriptionEntity.createAndInsert(scopeExecution);
compensateEventSubscriptionEntity.setActivity(compensationHandlder);
}
Aggregations