Class ClusterTaskScheduler

java.lang.Object
io.meeds.spring.kernel.ClusterTaskScheduler
All Implemented Interfaces:
org.springframework.scheduling.TaskScheduler

public class ClusterTaskScheduler extends Object implements org.springframework.scheduling.TaskScheduler
Runs a scheduled method once per cluster. The method names this scheduler, @Scheduled(cron = "...", scheduler = ClusterTaskScheduler.NAME), and the scheduler registers it as a job of the kernel's job scheduler, whose store the nodes of a cluster share: every node registers the same job, the store fires each of its triggers on one node, and that node runs its own copy of the method. A scheduled method that names no scheduler runs on every node.

The job is named after the method, so that every node registers the same one, and belongs to JobSchedulerService.RUNTIME_JOB_GROUP, which the job scheduler keeps when a node restarts. A cron expression is read as Spring reads it; a fixed delay runs at a fixed rate, one run at a time.

The job outlives its method: a version that removes or renames a method naming this scheduler ships an upgrade plugin that removes its job, removeJob(new JobInfo("<class>.<method>", JobSchedulerService.RUNTIME_JOB_GROUP, null)); a job no node declares is otherwise fired again once and reported at each of its runs.

A run missed while no node was up follows Quartz's misfire policy, not Spring's: a cron late by more than the store's misfire threshold fires once as soon as a node can; a fixed rate skips the runs it missed and goes on at the next time of its schedule. That includes its first run, which counts from the first registration of the method in the cluster's store: a stored job keeps its times while its period is unchanged, so a later change of its initial delay has no effect. A node that starts Quartz later than that time plus the misfire threshold runs the method first at the next time of its schedule, at most one period later.

  • Field Details

    • NAME

      public static final String NAME
      The name of the scheduler, which a scheduled method gives as its scheduler.
      See Also:
  • Constructor Details

    • ClusterTaskScheduler

      public ClusterTaskScheduler(Supplier<org.exoplatform.services.scheduler.JobSchedulerService> jobSchedulerService)
      Parameters:
      jobSchedulerService - the kernel's job scheduler, looked up when a method is registered, so that a context with no scheduled method naming this scheduler starts without it
  • Method Details

    • schedule

      public ScheduledFuture<?> schedule(Runnable task, org.springframework.scheduling.Trigger trigger)
      Specified by:
      schedule in interface org.springframework.scheduling.TaskScheduler
    • scheduleAtFixedRate

      public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Instant startTime, Duration period)
      Specified by:
      scheduleAtFixedRate in interface org.springframework.scheduling.TaskScheduler
    • scheduleAtFixedRate

      public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Duration period)
      Specified by:
      scheduleAtFixedRate in interface org.springframework.scheduling.TaskScheduler
    • scheduleWithFixedDelay

      public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Instant startTime, Duration delay)
      Specified by:
      scheduleWithFixedDelay in interface org.springframework.scheduling.TaskScheduler
    • scheduleWithFixedDelay

      public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Duration delay)
      Specified by:
      scheduleWithFixedDelay in interface org.springframework.scheduling.TaskScheduler
    • schedule

      public ScheduledFuture<?> schedule(Runnable task, Instant startTime)
      Specified by:
      schedule in interface org.springframework.scheduling.TaskScheduler