@Override public Deadline persistDeadline(Deadline deadline) { check(); this.em.persist( deadline ); if( this.pessimisticLocking ) { this.em.flush(); return this.em.find(DeadlineImpl.class, deadline.getId(), LockModeType.PESSIMISTIC_WRITE ); } return deadline; }
public static void scheduleDeadlines(final List<? extends Deadline> deadlines, final long now, final long taskId, DeadlineType type, TaskDeadlinesService deadlineService) { for (Deadline deadline : deadlines) { if (!deadline.isEscalated()) { // only escalate when true - typically this would only be true // if the user is requested that the notification should never be escalated Date date = deadline.getDate(); deadlineService.schedule(taskId, deadline.getId(), date.getTime() - now, type); } } }
public void unschedule(long taskId, Deadline deadline, DeadlineType type) { Task task = persistenceContext.findTask(taskId); String deploymentId = task.getTaskData().getDeploymentId(); Deadlines deadlines = ((InternalTask)task).getDeadlines(); TimerService timerService = TimerServiceRegistry.getInstance().get(deploymentId + TimerServiceRegistry.TIMER_SERVICE_SUFFIX); if (timerService != null && timerService instanceof GlobalTimerService) { TaskDeadlineJob deadlineJob = new TaskDeadlineJob(taskId, deadline.getId(), type, deploymentId, task.getTaskData().getProcessInstanceId()); logger.debug("unscheduling timer job for deadline {} {} and task {} using timer service {}", deadlineJob.getId(), deadline.getId(), taskId, timerService); JobHandle jobHandle = jobHandles.remove(deadlineJob.getId()); if (jobHandle == null) { jobHandle = ((GlobalTimerService) timerService).buildJobHandleForContext(new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId)); } timerService.removeJob(jobHandle); // mark the deadlines so they won't be rescheduled again deadline.setEscalated(true); } }
@Override public Deadline persistDeadline(Deadline deadline) { check(); this.em.persist( deadline ); if( this.pessimisticLocking ) { this.em.flush(); return this.em.find(DeadlineImpl.class, deadline.getId(), LockModeType.PESSIMISTIC_WRITE ); } return deadline; }