public JobHandle scheduleJob(Job job, JobContext ctx, Trigger trigger) { Date date = trigger.hasNextFireTime(); if (date != null) { JDKJobHandle jobHandle = new JDKJobHandle(idCounter.getAndIncrement()); TimerJobInstance jobInstance = jobFactoryManager.createTimerJobInstance(job, ctx, trigger, jobHandle, this); jobHandle.setTimerJobInstance((TimerJobInstance) jobInstance); internalSchedule((TimerJobInstance) jobInstance); return jobHandle; } else { return null; } }
public void internalSchedule(TimerJobInstance timerJobInstance) { Date date = timerJobInstance.getTrigger().hasNextFireTime(); Callable<Void> item = (Callable<Void>) timerJobInstance; JDKJobHandle jobHandle = (JDKJobHandle) timerJobInstance.getJobHandle(); long then = date.getTime(); long now = System.currentTimeMillis(); ScheduledFuture<Void> future = null; if (then >= now) { future = scheduler.schedule(item, then - now, TimeUnit.MILLISECONDS); } else { future = scheduler.schedule(item, 0, TimeUnit.MILLISECONDS); } jobHandle.setFuture(future); jobFactoryManager.addTimerJobInstance(timerJobInstance); }
public Collection<TimerJobInstance> getTimerJobInstances(int id) { return jobFactoryManager.getTimerJobInstances(); }
public boolean removeJob(JobHandle jobHandle) { jobHandle.setCancel(true); JDKJobHandle jdkJobHandle = (JDKJobHandle) jobHandle; jobFactoryManager.removeTimerJobInstance(jdkJobHandle.getTimerJobInstance()); return this.scheduler.remove((Runnable) jdkJobHandle.getFuture()); }