Search in sources :

Example 76 with ActivityImpl

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);
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) BoundaryEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior) BoundaryEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior) ActivityBehavior(org.activiti.engine.impl.pvm.delegate.ActivityBehavior)

Example 77 with ActivityImpl

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);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ActivitiException(org.activiti.engine.ActivitiException)

Example 78 with ActivityImpl

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));
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) HistoricActivityInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) IdGenerator(org.activiti.engine.impl.cfg.IdGenerator) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) Date(java.util.Date)

Example 79 with ActivityImpl

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;
}
Also used : JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) ActivitiException(org.activiti.engine.ActivitiException) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) DurationHelper(org.activiti.engine.impl.calendar.DurationHelper) JobExecutor(org.activiti.engine.impl.jobexecutor.JobExecutor) TransactionContext(org.activiti.engine.impl.cfg.TransactionContext) JobAddedNotification(org.activiti.engine.impl.jobexecutor.JobAddedNotification) ActivitiException(org.activiti.engine.ActivitiException) ActivitiEventDispatcher(org.activiti.engine.delegate.event.ActivitiEventDispatcher)

Example 80 with ActivityImpl

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;
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) DeploymentManager(org.activiti.engine.impl.persistence.deploy.DeploymentManager) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Aggregations

ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)87 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)15 ActivitiException (org.activiti.engine.ActivitiException)14 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)13 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)11 TransitionImpl (org.activiti.engine.impl.pvm.process.TransitionImpl)9 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)8 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)7 ArrayList (java.util.ArrayList)6 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)6 ProcessDefinitionImpl (org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl)6 List (java.util.List)5 EventDefinition (org.activiti.bpmn.model.EventDefinition)4 StartEvent (org.activiti.bpmn.model.StartEvent)4 IOSpecification (org.activiti.engine.impl.bpmn.data.IOSpecification)4 ActivityBehavior (org.activiti.engine.impl.pvm.delegate.ActivityBehavior)4 HashMap (java.util.HashMap)3 BpmnModel (org.activiti.bpmn.model.BpmnModel)3 IntermediateCatchEvent (org.activiti.bpmn.model.IntermediateCatchEvent)3 PvmProcessDefinition (org.activiti.engine.impl.pvm.PvmProcessDefinition)3