Package org.springframework.scheduling.config

Examples of org.springframework.scheduling.config.IntervalTask


          long initialDelay = annotation.initialDelay();
          long fixedDelay = annotation.fixedDelay();
          if (fixedDelay >= 0) {
            Assert.isTrue(!processedSchedule, errorMessage);
            processedSchedule = true;
            registrar.addFixedDelayTask(new IntervalTask(runnable, fixedDelay, initialDelay));
          }
          long fixedRate = annotation.fixedRate();
          if (fixedRate >= 0) {
            Assert.isTrue(!processedSchedule, errorMessage);
            processedSchedule = true;
            registrar.addFixedRateTask(new IntervalTask(runnable, fixedRate, initialDelay));
          }
          Assert.isTrue(processedSchedule, errorMessage);
        }
      }
    });
View Full Code Here


    }

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
      taskRegistrar.setScheduler(taskScheduler());
      taskRegistrar.addFixedRateTask(new IntervalTask(
          new Runnable() {
            @Override
            public void run() {
              worker().executedByThread = Thread.currentThread().getName();
            }
View Full Code Here

      // Check fixed delay
      long fixedDelay = scheduled.fixedDelay();
      if (fixedDelay >= 0) {
        Assert.isTrue(!processedSchedule, errorMessage);
        processedSchedule = true;
        this.registrar.addFixedDelayTask(new IntervalTask(runnable, fixedDelay, initialDelay));
      }
      String fixedDelayString = scheduled.fixedDelayString();
      if (StringUtils.hasText(fixedDelayString)) {
        Assert.isTrue(!processedSchedule, errorMessage);
        processedSchedule = true;
        if (this.embeddedValueResolver != null) {
          fixedDelayString = this.embeddedValueResolver.resolveStringValue(fixedDelayString);
        }
        try {
          fixedDelay = Integer.parseInt(fixedDelayString);
        }
        catch (NumberFormatException ex) {
          throw new IllegalArgumentException(
              "Invalid fixedDelayString value \"" + fixedDelayString + "\" - cannot parse into integer");
        }
        this.registrar.addFixedDelayTask(new IntervalTask(runnable, fixedDelay, initialDelay));
      }

      // Check fixed rate
      long fixedRate = scheduled.fixedRate();
      if (fixedRate >= 0) {
        Assert.isTrue(!processedSchedule, errorMessage);
        processedSchedule = true;
        this.registrar.addFixedRateTask(new IntervalTask(runnable, fixedRate, initialDelay));
      }
      String fixedRateString = scheduled.fixedRateString();
      if (StringUtils.hasText(fixedRateString)) {
        Assert.isTrue(!processedSchedule, errorMessage);
        processedSchedule = true;
        if (this.embeddedValueResolver != null) {
          fixedRateString = this.embeddedValueResolver.resolveStringValue(fixedRateString);
        }
        try {
          fixedRate = Integer.parseInt(fixedRateString);
        }
        catch (NumberFormatException ex) {
          throw new IllegalArgumentException(
              "Invalid fixedRateString value \"" + fixedRateString + "\" - cannot parse into integer");
        }
        this.registrar.addFixedRateTask(new IntervalTask(runnable, fixedRate, initialDelay));
      }

      // Check whether we had any attribute set
      Assert.isTrue(processedSchedule, errorMessage);
    }
View Full Code Here

        new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
    @SuppressWarnings("unchecked")
    List<IntervalTask> fixedDelayTasks = (List<IntervalTask>)
        new DirectFieldAccessor(registrar).getPropertyValue("fixedDelayTasks");
    assertEquals(1, fixedDelayTasks.size());
    IntervalTask task = fixedDelayTasks.get(0);
    ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
    Object targetObject = runnable.getTarget();
    Method targetMethod = runnable.getMethod();
    assertEquals(target, targetObject);
    assertEquals("fixedDelay", targetMethod.getName());
    assertEquals(0L, task.getInitialDelay());
    assertEquals(5000L, task.getInterval());
  }
View Full Code Here

        new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
    @SuppressWarnings("unchecked")
    List<IntervalTask> fixedRateTasks = (List<IntervalTask>)
        new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
    assertEquals(1, fixedRateTasks.size());
    IntervalTask task = fixedRateTasks.get(0);
    ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
    Object targetObject = runnable.getTarget();
    Method targetMethod = runnable.getMethod();
    assertEquals(target, targetObject);
    assertEquals("fixedRate", targetMethod.getName());
    assertEquals(0L, task.getInitialDelay());
    assertEquals(3000L, task.getInterval());
  }
View Full Code Here

        new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
    @SuppressWarnings("unchecked")
    List<IntervalTask> fixedRateTasks = (List<IntervalTask>)
        new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
    assertEquals(1, fixedRateTasks.size());
    IntervalTask task = fixedRateTasks.get(0);
    ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
    Object targetObject = runnable.getTarget();
    Method targetMethod = runnable.getMethod();
    assertEquals(target, targetObject);
    assertEquals("fixedRate", targetMethod.getName());
    assertEquals(1000L, task.getInitialDelay());
    assertEquals(3000L, task.getInterval());
  }
View Full Code Here

        new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
    @SuppressWarnings("unchecked")
    List<IntervalTask> fixedRateTasks = (List<IntervalTask>)
        new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
    assertEquals(2, fixedRateTasks.size());
    IntervalTask task1 = fixedRateTasks.get(0);
    ScheduledMethodRunnable runnable1 = (ScheduledMethodRunnable) task1.getRunnable();
    Object targetObject = runnable1.getTarget();
    Method targetMethod = runnable1.getMethod();
    assertEquals(target, targetObject);
    assertEquals("fixedRate", targetMethod.getName());
    assertEquals(0, task1.getInitialDelay());
    assertEquals(4000L, task1.getInterval());
    IntervalTask task2 = fixedRateTasks.get(1);
    ScheduledMethodRunnable runnable2 = (ScheduledMethodRunnable) task2.getRunnable();
    targetObject = runnable2.getTarget();
    targetMethod = runnable2.getMethod();
    assertEquals(target, targetObject);
    assertEquals("fixedRate", targetMethod.getName());
    assertEquals(2000L, task2.getInitialDelay());
    assertEquals(4000L, task2.getInterval());
  }
View Full Code Here

        new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
    @SuppressWarnings("unchecked")
    List<IntervalTask> fixedRateTasks = (List<IntervalTask>)
        new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
    assertEquals(1, fixedRateTasks.size());
    IntervalTask task = fixedRateTasks.get(0);
    ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
    Object targetObject = runnable.getTarget();
    Method targetMethod = runnable.getMethod();
    assertEquals(target, targetObject);
    assertEquals("checkForUpdates", targetMethod.getName());
    assertEquals(5000L, task.getInterval());
  }
View Full Code Here

        new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
    @SuppressWarnings("unchecked")
    List<IntervalTask> fixedDelayTasks = (List<IntervalTask>)
        new DirectFieldAccessor(registrar).getPropertyValue("fixedDelayTasks");
    assertEquals(1, fixedDelayTasks.size());
    IntervalTask task = fixedDelayTasks.get(0);
    ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
    Object targetObject = runnable.getTarget();
    Method targetMethod = runnable.getMethod();
    assertEquals(target, targetObject);
    assertEquals("fixedDelay", targetMethod.getName());
    assertEquals(1000L, task.getInitialDelay());
    assertEquals(5000L, task.getInterval());
  }
View Full Code Here

        new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
    @SuppressWarnings("unchecked")
    List<IntervalTask> fixedRateTasks = (List<IntervalTask>)
        new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
    assertEquals(1, fixedRateTasks.size());
    IntervalTask task = fixedRateTasks.get(0);
    ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
    Object targetObject = runnable.getTarget();
    Method targetMethod = runnable.getMethod();
    assertEquals(target, targetObject);
    assertEquals("fixedRate", targetMethod.getName());
    assertEquals(1000L, task.getInitialDelay());
    assertEquals(3000L, task.getInterval());
  }
View Full Code Here

TOP

Related Classes of org.springframework.scheduling.config.IntervalTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.