public void registerTimer(final TimerInstance timer, String processId, Map<String, Object> params) { try { kruntime.startOperation(); timer.setId(++timerId); timer.setProcessInstanceId(-1l); timer.setSessionId(((StatefulKnowledgeSession) kruntime).getIdentifier()); timer.setActivated(new Date()); Trigger trigger = null; if (timer.getCronExpression() != null) { Date startTime = new Date(timerService.getCurrentTime() + 1000); trigger = new CronTrigger(timerService.getCurrentTime(), startTime, null, -1, timer.getCronExpression(), null, null); // cron timers are by nature repeatable timer.setPeriod(1); } else { trigger = new IntervalTrigger(timerService.getCurrentTime(), null, null, timer.getRepeatLimit(), timer.getDelay(), timer.getPeriod(), null, null); } StartProcessJobContext ctx = new StartProcessJobContext(timer, trigger, processId, params, this.kruntime); JobHandle jobHandle = this.timerService.scheduleJob(startProcessJob, ctx, trigger); timer.setJobHandle(jobHandle); timers.put(timer.getId(), timer); } finally { kruntime.endOperation(); } }
public void registerTimer(final TimerInstance timer, String processId, Map<String, Object> params) { try { kruntime.startOperation(); timer.setId(++timerId); timer.setProcessInstanceId(-1l); timer.setSessionId(((StatefulKnowledgeSession) kruntime).getIdentifier()); timer.setActivated(new Date()); Trigger trigger = null; if (timer.getCronExpression() != null) { Date startTime = new Date(timerService.getCurrentTime() + 1000); trigger = new CronTrigger(timerService.getCurrentTime(), startTime, null, -1, timer.getCronExpression(), null, null); // cron timers are by nature repeatable timer.setPeriod(1); } else { trigger = new IntervalTrigger(timerService.getCurrentTime(), null, null, timer.getRepeatLimit(), timer.getDelay(), timer.getPeriod(), null, null); } StartProcessJobContext ctx = new StartProcessJobContext(timer, trigger, processId, params, this.kruntime); JobHandle jobHandle = this.timerService.scheduleJob(startProcessJob, ctx, trigger); timer.setJobHandle(jobHandle); timers.put(timer.getId(), timer); } finally { kruntime.endOperation(); } }
@Test public void testStartProcessJobContextUniqueJobNamesAmongSessions() { // we set the same process ID StartProcessJobContext ctxA = new StartProcessJobContext(new TimerInstance(), new IntervalTrigger(), "processId", Collections.emptyMap(), createRuntime(1L, "container-1")); StartProcessJobContext ctxB = new StartProcessJobContext(new TimerInstance(), new IntervalTrigger(), "processId", Collections.emptyMap(), createRuntime(2L, "container-2")); EjbSchedulerService service = new EjbSchedulerService(); String jobNameA = service.getJobName(ctxA, 1L); String jobNameB = service.getJobName(ctxB, 1L); Assert.assertNotEquals(jobNameA, jobNameB); }