use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.
the class TimerExecuteNestedActivityJobHandler method dispatchActivityTimeoutIfNeeded.
protected void dispatchActivityTimeoutIfNeeded(JobEntity timerEntity, ExecutionEntity execution, CommandContext commandContext) {
String nestedActivityId = TimerEventHandler.getActivityIdFromConfiguration(timerEntity.getJobHandlerConfiguration());
ActivityImpl boundaryEventActivity = execution.getProcessDefinition().findActivity(nestedActivityId);
ActivityBehavior boundaryActivityBehavior = boundaryEventActivity.getActivityBehavior();
if (boundaryActivityBehavior instanceof BoundaryEventActivityBehavior) {
BoundaryEventActivityBehavior boundaryEventActivityBehavior = (BoundaryEventActivityBehavior) boundaryActivityBehavior;
if (boundaryEventActivityBehavior.isInterrupting()) {
dispatchExecutionTimeOut(timerEntity, execution, commandContext);
}
}
}
use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.
the class TimerCatchIntermediateEventJobHandler method execute.
public void execute(JobEntity job, String configuration, ExecutionEntity execution, CommandContext commandContext) {
String nestedActivityId = TimerEventHandler.getActivityIdFromConfiguration(configuration);
ActivityImpl intermediateEventActivity = execution.getProcessDefinition().findActivity(nestedActivityId);
if (intermediateEventActivity == null) {
throw new ActivitiException("Error while firing timer: intermediate event activity " + nestedActivityId + " not found");
}
try {
if (commandContext.getEventDispatcher().isEnabled()) {
commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TIMER_FIRED, job));
}
if (!execution.getActivity().getId().equals(intermediateEventActivity.getId())) {
execution.setActivity(intermediateEventActivity);
}
execution.signal(null, null);
} catch (RuntimeException e) {
LogMDC.putMDCExecution(execution);
log.error("exception during timer execution", e);
LogMDC.clear();
throw e;
} catch (Exception e) {
LogMDC.putMDCExecution(execution);
log.error("exception during timer execution", e);
LogMDC.clear();
throw new ActivitiException("exception during timer execution: " + e.getMessage(), e);
}
}
use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.
the class DefaultHistoryManager method recordSubProcessInstanceStart.
/* (non-Javadoc)
* @see org.activiti.engine.impl.history.HistoryManagerInterface#recordSubProcessInstanceStart(org.activiti.engine.impl.persistence.entity.ExecutionEntity, org.activiti.engine.impl.persistence.entity.ExecutionEntity)
*/
@Override
public void recordSubProcessInstanceStart(ExecutionEntity parentExecution, ExecutionEntity subProcessInstance) {
if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity((ExecutionEntity) subProcessInstance);
ActivityImpl initialActivity = subProcessInstance.getActivity();
// Fix for ACT-1728: startActivityId not initialized with subprocess-instance
if (historicProcessInstance.getStartActivityId() == null) {
historicProcessInstance.setStartActivityId(subProcessInstance.getProcessDefinition().getInitial().getId());
initialActivity = subProcessInstance.getProcessDefinition().getInitial();
}
getDbSqlSession().insert(historicProcessInstance);
// Fire event
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null && config.getEventDispatcher().isEnabled()) {
config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
}
HistoricActivityInstanceEntity activitiyInstance = findActivityInstance(parentExecution);
if (activitiyInstance != null) {
activitiyInstance.setCalledProcessInstanceId(subProcessInstance.getProcessInstanceId());
}
// Fix for ACT-1728: start-event not recorded for subprocesses
IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator();
// Also record the start-event manually, as there is no "start" activity history listener for this
HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity();
historicActivityInstance.setId(idGenerator.getNextId());
historicActivityInstance.setProcessDefinitionId(subProcessInstance.getProcessDefinitionId());
historicActivityInstance.setProcessInstanceId(subProcessInstance.getProcessInstanceId());
historicActivityInstance.setExecutionId(subProcessInstance.getId());
historicActivityInstance.setActivityId(initialActivity.getId());
historicActivityInstance.setActivityName((String) initialActivity.getProperty("name"));
historicActivityInstance.setActivityType((String) initialActivity.getProperty("type"));
Date now = Context.getProcessEngineConfiguration().getClock().getCurrentTime();
historicActivityInstance.setStartTime(now);
getDbSqlSession().insert(historicActivityInstance);
// Fire event
if (config != null && config.getEventDispatcher().isEnabled()) {
config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstance));
}
}
}
use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.
the class JobRetryCmd method execute.
public Object execute(CommandContext commandContext) {
JobEntity job = commandContext.getJobEntityManager().findJobById(jobId);
if (job == null) {
return null;
}
ActivityImpl activity = getCurrentActivity(commandContext, job);
ProcessEngineConfiguration processEngineConfig = commandContext.getProcessEngineConfiguration();
if (activity == null || activity.getFailedJobRetryTimeCycleValue() == null) {
log.debug("activitiy or FailedJobRetryTimerCycleValue is null in job " + jobId + "'. only decrementing retries.");
job.setRetries(job.getRetries() - 1);
job.setLockOwner(null);
job.setLockExpirationTime(null);
if (job.getDuedate() == null) {
// add wait time for failed async job
job.setDuedate(calculateDueDate(commandContext, processEngineConfig.getAsyncFailedJobWaitTime(), null));
} else {
// add default wait time for failed job
job.setDuedate(calculateDueDate(commandContext, processEngineConfig.getDefaultFailedJobWaitTime(), job.getDuedate()));
}
} else {
String failedJobRetryTimeCycle = activity.getFailedJobRetryTimeCycleValue();
try {
DurationHelper durationHelper = new DurationHelper(failedJobRetryTimeCycle, processEngineConfig.getClock());
job.setLockOwner(null);
job.setLockExpirationTime(null);
job.setDuedate(durationHelper.getDateAfter());
if (job.getExceptionMessage() == null) {
// is it the first exception
log.debug("Applying JobRetryStrategy '" + failedJobRetryTimeCycle + "' the first time for job " + job.getId() + " with " + durationHelper.getTimes() + " retries");
// then change default retries to the ones configured
job.setRetries(durationHelper.getTimes());
} else {
log.debug("Decrementing retries of JobRetryStrategy '" + failedJobRetryTimeCycle + "' for job " + job.getId());
}
job.setRetries(job.getRetries() - 1);
} catch (Exception e) {
throw new ActivitiException("failedJobRetryTimeCylcle has wrong format:" + failedJobRetryTimeCycle, exception);
}
}
if (exception != null) {
job.setExceptionMessage(exception.getMessage());
job.setExceptionStacktrace(getExceptionStacktrace());
}
// Dispatch both an update and a retry-decrement event
ActivitiEventDispatcher eventDispatcher = commandContext.getEventDispatcher();
if (eventDispatcher.isEnabled()) {
eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, job));
eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_RETRIES_DECREMENTED, job));
}
if (processEngineConfig.isAsyncExecutorEnabled() == false) {
JobExecutor jobExecutor = processEngineConfig.getJobExecutor();
JobAddedNotification messageAddedNotification = new JobAddedNotification(jobExecutor);
TransactionContext transactionContext = commandContext.getTransactionContext();
transactionContext.addTransactionListener(TransactionState.COMMITTED, messageAddedNotification);
}
return null;
}
use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.
the class JobRetryCmd method getCurrentActivity.
private ActivityImpl getCurrentActivity(CommandContext commandContext, JobEntity job) {
String type = job.getJobHandlerType();
ActivityImpl activity = null;
if (TimerExecuteNestedActivityJobHandler.TYPE.equals(type) || TimerCatchIntermediateEventJobHandler.TYPE.equals(type)) {
ExecutionEntity execution = fetchExecutionEntity(commandContext, job.getExecutionId());
if (execution != null) {
activity = execution.getProcessDefinition().findActivity(job.getJobHandlerConfiguration());
}
} else if (TimerStartEventJobHandler.TYPE.equals(type)) {
DeploymentManager deploymentManager = commandContext.getProcessEngineConfiguration().getDeploymentManager();
if (TimerEventHandler.hasRealActivityId(job.getJobHandlerConfiguration())) {
ProcessDefinitionEntity processDefinition = deploymentManager.findDeployedProcessDefinitionById(job.getProcessDefinitionId());
String activityId = TimerEventHandler.getActivityIdFromConfiguration(job.getJobHandlerConfiguration());
activity = processDefinition.findActivity(activityId);
} else {
String processId = job.getJobHandlerConfiguration();
if (job instanceof TimerEntity) {
processId = TimerEventHandler.getActivityIdFromConfiguration(job.getJobHandlerConfiguration());
}
ProcessDefinitionEntity processDefinition = null;
if (job.getTenantId() != null && job.getTenantId().length() > 0) {
processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKeyAndTenantId(processId, job.getTenantId());
} else {
processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKey(processId);
}
if (processDefinition != null) {
activity = processDefinition.getInitial();
}
}
} else if (AsyncContinuationJobHandler.TYPE.equals(type)) {
ExecutionEntity execution = fetchExecutionEntity(commandContext, job.getExecutionId());
if (execution != null) {
activity = execution.getActivity();
}
} else {
// nop, because activity type is not supported
}
return activity;
}
Aggregations