Search in sources :

Example 1 with JobManager

use of org.activiti.engine.impl.asyncexecutor.JobManager in project Activiti by Activiti.

the class JobExecutorTest method testBasicJobExecutorOperation.

public void testBasicJobExecutorOperation() throws Exception {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            jobManager.execute(createTweetMessage("message-one"));
            jobManager.execute(createTweetMessage("message-two"));
            jobManager.execute(createTweetMessage("message-three"));
            jobManager.execute(createTweetMessage("message-four"));
            TimerJobEntityManager timerJobManager = commandContext.getTimerJobEntityManager();
            timerJobManager.insert(createTweetTimer("timer-one", new Date()));
            timerJobManager.insert(createTweetTimer("timer-one", new Date()));
            timerJobManager.insert(createTweetTimer("timer-two", new Date()));
            return null;
        }
    });
    GregorianCalendar currentCal = new GregorianCalendar();
    currentCal.add(Calendar.MINUTE, 1);
    processEngineConfiguration.getClock().setCurrentTime(currentCal.getTime());
    waitForJobExecutorToProcessAllJobs(50000L, 200L);
    Set<String> messages = new HashSet<String>(tweetHandler.getMessages());
    Set<String> expectedMessages = new HashSet<String>();
    expectedMessages.add("message-one");
    expectedMessages.add("message-two");
    expectedMessages.add("message-three");
    expectedMessages.add("message-four");
    expectedMessages.add("timer-one");
    expectedMessages.add("timer-two");
    assertThat(new TreeSet<String>(messages)).isEqualTo(new TreeSet<String>(expectedMessages));
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) GregorianCalendar(java.util.GregorianCalendar) JobManager(org.activiti.engine.impl.asyncexecutor.JobManager) TimerJobEntityManager(org.activiti.engine.impl.persistence.entity.TimerJobEntityManager) Date(java.util.Date) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet)

Example 2 with JobManager

use of org.activiti.engine.impl.asyncexecutor.JobManager 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 3 with JobManager

use of org.activiti.engine.impl.asyncexecutor.JobManager in project Activiti by Activiti.

the class IntermediateCatchTimerEventActivityBehavior method execute.

public void execute(DelegateExecution execution) {
    JobManager jobManager = Context.getCommandContext().getJobManager();
    // end date should be ignored for intermediate timer events.
    TimerJobEntity timerJob = jobManager.createTimerJob(timerEventDefinition, false, (ExecutionEntity) execution, TriggerTimerEventJobHandler.TYPE, TimerEventHandler.createConfiguration(execution.getCurrentActivityId(), null, timerEventDefinition.getCalendarName()));
    if (timerJob != null) {
        jobManager.scheduleTimerJob(timerJob);
    }
}
Also used : JobManager(org.activiti.engine.impl.asyncexecutor.JobManager) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Example 4 with JobManager

use of org.activiti.engine.impl.asyncexecutor.JobManager in project Activiti by Activiti.

the class BoundaryTimerEventActivityBehavior method execute.

@Override
public void execute(DelegateExecution execution) {
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    if (!(execution.getCurrentFlowElement() instanceof BoundaryEvent)) {
        throw new ActivitiException("Programmatic error: " + this.getClass() + " should not be used for anything else than a boundary event");
    }
    JobManager jobManager = Context.getCommandContext().getJobManager();
    TimerJobEntity timerJob = jobManager.createTimerJob(timerEventDefinition, interrupting, executionEntity, TriggerTimerEventJobHandler.TYPE, TimerEventHandler.createConfiguration(execution.getCurrentActivityId(), timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));
    if (timerJob != null) {
        jobManager.scheduleTimerJob(timerJob);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) JobManager(org.activiti.engine.impl.asyncexecutor.JobManager) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Example 5 with JobManager

use of org.activiti.engine.impl.asyncexecutor.JobManager in project Activiti by Activiti.

the class TimerManager method scheduleTimers.

protected void scheduleTimers(ProcessDefinitionEntity processDefinition, Process process) {
    JobManager jobManager = Context.getCommandContext().getJobManager();
    List<TimerJobEntity> timers = getTimerDeclarations(processDefinition, process);
    for (TimerJobEntity timer : timers) {
        jobManager.scheduleTimerJob(timer);
    }
}
Also used : JobManager(org.activiti.engine.impl.asyncexecutor.JobManager) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Aggregations

JobManager (org.activiti.engine.impl.asyncexecutor.JobManager)5 TimerJobEntity (org.activiti.engine.impl.persistence.entity.TimerJobEntity)4 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)1 EventDefinition (org.activiti.bpmn.model.EventDefinition)1 FlowElement (org.activiti.bpmn.model.FlowElement)1 StartEvent (org.activiti.bpmn.model.StartEvent)1 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)1 ActivitiException (org.activiti.engine.ActivitiException)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)1 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)1 TimerJobEntityManager (org.activiti.engine.impl.persistence.entity.TimerJobEntityManager)1