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));
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations