Class ManagedJobScheduler

java.lang.Object
net.solarnetwork.node.runtime.ManagedJobScheduler
All Implemented Interfaces:
net.solarnetwork.service.PingTest, net.solarnetwork.service.ServiceLifecycleObserver, org.osgi.service.cm.ConfigurationListener

public class ManagedJobScheduler extends Object implements net.solarnetwork.service.ServiceLifecycleObserver, org.osgi.service.cm.ConfigurationListener, net.solarnetwork.service.PingTest
Service to dynamically register and schedule ManagedJob instances.

This service schedules jobs that are passed to registerJob(ManagedJob, Map) with the configured TaskScheduler. Each job is expected to be backed by a ConfigurationAdmin configuration, identified by a unique pid. The pid can be provided via the job properties, using the key service.pid. This is useful for jobs created via a managed configuration factory. If no service.pid job property is provided, the SettingSpecifierProvider.getSettingUid() value provided by the job will be used as a fallback. This can be useful for directly created jobs.

A SettingSpecifierProvider service will be registered for each pid. Multiple jobs sharing the same pid are allowed. In that case, all jobs will share the same configuration but can rely on different setting keys to define different schedules. The ManagedJob.getScheduleSettingKey() defines the setting key to use, which defaults to schedule.

Version:
1.1
Author:
matt
  • Field Details

    • DEFAULT_RANDOMIZED_CRON

      public static final boolean DEFAULT_RANDOMIZED_CRON
      The randomizedCron property default value.
      See Also:
    • DEFAULT_JOB_START_DELAY_SECS

      public static final int DEFAULT_JOB_START_DELAY_SECS
      The jobStartDelaySeconds property default value.
      See Also:
  • Constructor Details

    • ManagedJobScheduler

      public ManagedJobScheduler(org.osgi.framework.BundleContext bundleContext, org.springframework.scheduling.TaskScheduler taskScheduler)
      Constructor.
      Parameters:
      bundleContext - the bundle context
      taskScheduler - the task scheduler
      Throws:
      IllegalArgumentException - if any argument is null
  • Method Details

    • serviceDidStartup

      public void serviceDidStartup()
      Specified by:
      serviceDidStartup in interface net.solarnetwork.service.ServiceLifecycleObserver
    • serviceDidShutdown

      public void serviceDidShutdown()
      Specified by:
      serviceDidShutdown in interface net.solarnetwork.service.ServiceLifecycleObserver
    • registerJob

      public void registerJob(ManagedJob job, Map<String,?> properties)
      Register a job.
      Parameters:
      job - the job to register and schedule for execution
      properties - optional service properties
    • unregisterJob

      public void unregisterJob(ManagedJob job, Map<String,?> properties)
      Unregister a job.
      Parameters:
      job - the job to unregister and un-schedule for execution
      properties - optional service properties
    • configurationEvent

      public void configurationEvent(org.osgi.service.cm.ConfigurationEvent event)
      Specified by:
      configurationEvent in interface org.osgi.service.cm.ConfigurationListener
    • getPingTestId

      public String getPingTestId()
      Specified by:
      getPingTestId in interface net.solarnetwork.service.PingTest
    • getPingTestName

      public String getPingTestName()
      Specified by:
      getPingTestName in interface net.solarnetwork.service.PingTest
    • getPingTestMaximumExecutionMilliseconds

      public long getPingTestMaximumExecutionMilliseconds()
      Specified by:
      getPingTestMaximumExecutionMilliseconds in interface net.solarnetwork.service.PingTest
    • performPingTest

      public net.solarnetwork.service.PingTest.Result performPingTest() throws Exception
      Specified by:
      performPingTest in interface net.solarnetwork.service.PingTest
      Throws:
      Exception
    • isRandomizedCron

      public boolean isRandomizedCron()
      Get the randomized cron flag.
      Returns:
      true to randomize the second property of jobs using cron schedules; defaults to DEFAULT_RANDOMIZED_CRON
    • setRandomizedCron

      public void setRandomizedCron(boolean randomizedCron)
      Set the randomized cron flag.
      Parameters:
      randomizedCron - true to randomize the second property of jobs using cron schedules
    • getMessageSource

      public org.springframework.context.MessageSource getMessageSource()
      Get the message source.
      Returns:
      the message source
    • setMessageSource

      public void setMessageSource(org.springframework.context.MessageSource messageSource)
      Set the message source.
      Parameters:
      messageSource - the message source to set
    • getJobStartDelaySeconds

      public int getJobStartDelaySeconds()
      Get the number of seconds to delay the first execution of a registered job.
      Returns:
      the number of seconds to delay the first execution of a registered job; defaults to DEFAULT_JOB_START_DELAY_SECS
    • setJobStartDelaySeconds

      public void setJobStartDelaySeconds(int jobStartDelaySeconds)
      Set the number of seconds to delay the first execution of a registered job.
      Parameters:
      jobStartDelaySeconds - the number of seconds to delay the first execution of a registered job