Search in sources :

Example 11 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class DefaultJobManager method moveJobToSuspendedJob.

@Override
public SuspendedJobEntity moveJobToSuspendedJob(AbstractJobEntity job) {
    SuspendedJobEntity suspendedJob = createSuspendedJobFromOtherJob(job);
    processEngineConfiguration.getSuspendedJobEntityManager().insert(suspendedJob);
    if (job instanceof TimerJobEntity) {
        processEngineConfiguration.getTimerJobEntityManager().delete((TimerJobEntity) job);
    } else if (job instanceof JobEntity) {
        processEngineConfiguration.getJobEntityManager().delete((JobEntity) job);
    }
    return suspendedJob;
}
Also used : DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) AbstractJobEntity(org.activiti.engine.impl.persistence.entity.AbstractJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Example 12 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class DestroyScopeOperation method deleteAllScopeJobs.

private void deleteAllScopeJobs(ExecutionEntity scopeExecution, TimerJobEntityManager timerJobEntityManager) {
    Collection<TimerJobEntity> timerJobsForExecution = timerJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
    for (TimerJobEntity job : timerJobsForExecution) {
        timerJobEntityManager.delete(job);
    }
    JobEntityManager jobEntityManager = commandContext.getJobEntityManager();
    Collection<JobEntity> jobsForExecution = jobEntityManager.findJobsByExecutionId(scopeExecution.getId());
    for (JobEntity job : jobsForExecution) {
        jobEntityManager.delete(job);
    }
    SuspendedJobEntityManager suspendedJobEntityManager = commandContext.getSuspendedJobEntityManager();
    Collection<SuspendedJobEntity> suspendedJobsForExecution = suspendedJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
    for (SuspendedJobEntity job : suspendedJobsForExecution) {
        suspendedJobEntityManager.delete(job);
    }
    DeadLetterJobEntityManager deadLetterJobEntityManager = commandContext.getDeadLetterJobEntityManager();
    Collection<DeadLetterJobEntity> deadLetterJobsForExecution = deadLetterJobEntityManager.findJobsByExecutionId(scopeExecution.getId());
    for (DeadLetterJobEntity job : deadLetterJobsForExecution) {
        deadLetterJobEntityManager.delete(job);
    }
}
Also used : DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) TimerJobEntityManager(org.activiti.engine.impl.persistence.entity.TimerJobEntityManager) JobEntityManager(org.activiti.engine.impl.persistence.entity.JobEntityManager) DeadLetterJobEntityManager(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntityManager) SuspendedJobEntityManager(org.activiti.engine.impl.persistence.entity.SuspendedJobEntityManager) DeadLetterJobEntityManager(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntityManager) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) SuspendedJobEntityManager(org.activiti.engine.impl.persistence.entity.SuspendedJobEntityManager) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity)

Example 13 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class TimerUtil method createTimerEntityForTimerEventDefinition.

/**
 * The event definition on which the timer is based.
 *
 * Takes in an optional execution, if missing the {@link NoExecutionVariableScope} will be used (eg Timer start event)
 */
public static TimerJobEntity createTimerEntityForTimerEventDefinition(TimerEventDefinition timerEventDefinition, boolean isInterruptingTimer, ExecutionEntity executionEntity, String jobHandlerType, String jobHandlerConfig) {
    ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
    String businessCalendarRef = null;
    Expression expression = null;
    ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();
    // ACT-1415: timer-declaration on start-event may contain expressions NOT
    // evaluating variables but other context, evaluating should happen nevertheless
    VariableScope scopeForExpression = executionEntity;
    if (scopeForExpression == null) {
        scopeForExpression = NoExecutionVariableScope.getSharedInstance();
    }
    if (StringUtils.isNotEmpty(timerEventDefinition.getTimeDate())) {
        businessCalendarRef = DueDateBusinessCalendar.NAME;
        expression = expressionManager.createExpression(timerEventDefinition.getTimeDate());
    } else if (StringUtils.isNotEmpty(timerEventDefinition.getTimeCycle())) {
        businessCalendarRef = CycleBusinessCalendar.NAME;
        expression = expressionManager.createExpression(timerEventDefinition.getTimeCycle());
    } else if (StringUtils.isNotEmpty(timerEventDefinition.getTimeDuration())) {
        businessCalendarRef = DurationBusinessCalendar.NAME;
        expression = expressionManager.createExpression(timerEventDefinition.getTimeDuration());
    }
    if (StringUtils.isNotEmpty(timerEventDefinition.getCalendarName())) {
        businessCalendarRef = timerEventDefinition.getCalendarName();
        Expression businessCalendarExpression = expressionManager.createExpression(businessCalendarRef);
        businessCalendarRef = businessCalendarExpression.getValue(scopeForExpression).toString();
    }
    if (expression == null) {
        throw new ActivitiException("Timer needs configuration (either timeDate, timeCycle or timeDuration is needed) (" + timerEventDefinition.getId() + ")");
    }
    BusinessCalendar businessCalendar = processEngineConfiguration.getBusinessCalendarManager().getBusinessCalendar(businessCalendarRef);
    String dueDateString = null;
    Date duedate = null;
    Object dueDateValue = expression.getValue(scopeForExpression);
    if (dueDateValue instanceof String) {
        dueDateString = (String) dueDateValue;
    } else if (dueDateValue instanceof Date) {
        duedate = (Date) dueDateValue;
    } else if (dueDateValue instanceof DateTime) {
        // JodaTime support
        duedate = ((DateTime) dueDateValue).toDate();
    } else if (dueDateValue != null) {
        throw new ActivitiException("Timer '" + executionEntity.getActivityId() + "' was not configured with a valid duration/time, either hand in a java.util.Date or a String in format 'yyyy-MM-dd'T'hh:mm:ss'");
    }
    if (duedate == null && dueDateString != null) {
        duedate = businessCalendar.resolveDuedate(dueDateString);
    }
    TimerJobEntity timer = null;
    if (duedate != null) {
        timer = Context.getCommandContext().getTimerJobEntityManager().create();
        timer.setJobType(JobEntity.JOB_TYPE_TIMER);
        timer.setRevision(1);
        timer.setJobHandlerType(jobHandlerType);
        timer.setJobHandlerConfiguration(jobHandlerConfig);
        timer.setExclusive(true);
        timer.setRetries(processEngineConfiguration.getAsyncExecutorNumberOfRetries());
        timer.setDuedate(duedate);
        if (executionEntity != null) {
            timer.setExecution(executionEntity);
            timer.setProcessDefinitionId(executionEntity.getProcessDefinitionId());
            timer.setProcessInstanceId(executionEntity.getProcessInstanceId());
            // Inherit tenant identifier (if applicable)
            if (executionEntity.getTenantId() != null) {
                timer.setTenantId(executionEntity.getTenantId());
            }
        }
    }
    if (StringUtils.isNotEmpty(timerEventDefinition.getTimeCycle())) {
        // See ACT-1427: A boundary timer with a cancelActivity='true', doesn't need to repeat itself
        boolean repeat = !isInterruptingTimer;
        // ACT-1951: intermediate catching timer events shouldn't repeat according to spec
        if (executionEntity != null) {
            FlowElement currentElement = executionEntity.getCurrentFlowElement();
            if (currentElement instanceof IntermediateCatchEvent) {
                repeat = false;
            }
        }
        if (repeat) {
            String prepared = prepareRepeat(dueDateString);
            timer.setRepeat(prepared);
        }
    }
    if (timer != null && executionEntity != null) {
        timer.setExecution(executionEntity);
        timer.setProcessDefinitionId(executionEntity.getProcessDefinitionId());
        // Inherit tenant identifier (if applicable)
        if (executionEntity.getTenantId() != null) {
            timer.setTenantId(executionEntity.getTenantId());
        }
    }
    return timer;
}
Also used : ExpressionManager(org.activiti.engine.impl.el.ExpressionManager) ActivitiException(org.activiti.engine.ActivitiException) IntermediateCatchEvent(org.activiti.bpmn.model.IntermediateCatchEvent) Date(java.util.Date) DateTime(org.joda.time.DateTime) Expression(org.activiti.engine.delegate.Expression) FlowElement(org.activiti.bpmn.model.FlowElement) DueDateBusinessCalendar(org.activiti.engine.impl.calendar.DueDateBusinessCalendar) CycleBusinessCalendar(org.activiti.engine.impl.calendar.CycleBusinessCalendar) DurationBusinessCalendar(org.activiti.engine.impl.calendar.DurationBusinessCalendar) BusinessCalendar(org.activiti.engine.impl.calendar.BusinessCalendar) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) VariableScope(org.activiti.engine.delegate.VariableScope) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope)

Example 14 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class TimerManager method getTimerDeclarations.

protected List<TimerJobEntity> getTimerDeclarations(ProcessDefinitionEntity processDefinition, Process process) {
    JobManager jobManager = Context.getCommandContext().getJobManager();
    List<TimerJobEntity> timers = new ArrayList<TimerJobEntity>();
    if (CollectionUtil.isNotEmpty(process.getFlowElements())) {
        for (FlowElement element : process.getFlowElements()) {
            if (element instanceof StartEvent) {
                StartEvent startEvent = (StartEvent) element;
                if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions())) {
                    EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
                    if (eventDefinition instanceof TimerEventDefinition) {
                        TimerEventDefinition timerEventDefinition = (TimerEventDefinition) eventDefinition;
                        TimerJobEntity timerJob = jobManager.createTimerJob(timerEventDefinition, false, null, TimerStartEventJobHandler.TYPE, TimerEventHandler.createConfiguration(startEvent.getId(), timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));
                        if (timerJob != null) {
                            timerJob.setProcessDefinitionId(processDefinition.getId());
                            if (processDefinition.getTenantId() != null) {
                                timerJob.setTenantId(processDefinition.getTenantId());
                            }
                            timers.add(timerJob);
                        }
                    }
                }
            }
        }
    }
    return timers;
}
Also used : FlowElement(org.activiti.bpmn.model.FlowElement) ArrayList(java.util.ArrayList) StartEvent(org.activiti.bpmn.model.StartEvent) JobManager(org.activiti.engine.impl.asyncexecutor.JobManager) EventDefinition(org.activiti.bpmn.model.EventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Example 15 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class BpmnActivityBehavior method dispatchJobCanceledEvents.

/**
 * dispatch job canceled event for job associated with given execution entity
 * @param activityExecution
 */
protected void dispatchJobCanceledEvents(ExecutionEntity activityExecution) {
    if (activityExecution != null) {
        List<JobEntity> jobs = activityExecution.getJobs();
        for (JobEntity job : jobs) {
            if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
                Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_CANCELED, job));
            }
        }
        List<TimerJobEntity> timerJobs = activityExecution.getTimerJobs();
        for (TimerJobEntity job : timerJobs) {
            if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
                Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_CANCELED, job));
            }
        }
    }
}
Also used : JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Aggregations

TimerJobEntity (org.activiti.engine.impl.persistence.entity.TimerJobEntity)28 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)8 SuspendedJobEntity (org.activiti.engine.impl.persistence.entity.SuspendedJobEntity)7 DeadLetterJobEntity (org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity)6 Deployment (org.activiti.engine.test.Deployment)6 AbstractJobEntity (org.activiti.engine.impl.persistence.entity.AbstractJobEntity)5 Job (org.activiti.engine.runtime.Job)5 ActivitiException (org.activiti.engine.ActivitiException)4 JobManager (org.activiti.engine.impl.asyncexecutor.JobManager)4 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)4 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)4 Date (java.util.Date)3 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 Calendar (java.util.Calendar)2 FlowElement (org.activiti.bpmn.model.FlowElement)2 VariableScope (org.activiti.engine.delegate.VariableScope)2 Page (org.activiti.engine.impl.Page)2 AcquiredTimerJobEntities (org.activiti.engine.impl.asyncexecutor.AcquiredTimerJobEntities)2 AcquireTimerJobsCmd (org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)2 NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)2