Esempio n. 1
0
  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;
    }
  }
Esempio n. 2
0
  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);
  }
Esempio n. 3
0
 public Collection<TimerJobInstance> getTimerJobInstances(int id) {
   return jobFactoryManager.getTimerJobInstances();
 }
Esempio n. 4
0
 public boolean removeJob(JobHandle jobHandle) {
   jobHandle.setCancel(true);
   JDKJobHandle jdkJobHandle = (JDKJobHandle) jobHandle;
   jobFactoryManager.removeTimerJobInstance(jdkJobHandle.getTimerJobInstance());
   return this.scheduler.remove((Runnable) jdkJobHandle.getFuture());
 }