Class ManagedJobScheduler
- All Implemented Interfaces:
net.solarnetwork.service.PingTest,net.solarnetwork.service.ServiceLifecycleObserver,org.osgi.service.cm.ConfigurationListener
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.solarnetwork.service.PingTest
net.solarnetwork.service.PingTest.Result -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThejobStartDelaySecondsproperty default value.static final booleanTherandomizedCronproperty default value. -
Constructor Summary
ConstructorsConstructorDescriptionManagedJobScheduler(org.osgi.framework.BundleContext bundleContext, org.springframework.scheduling.TaskScheduler taskScheduler) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigurationEvent(org.osgi.service.cm.ConfigurationEvent event) intGet the number of seconds to delay the first execution of a registered job.org.springframework.context.MessageSourceGet the message source.longbooleanGet the randomized cron flag.net.solarnetwork.service.PingTest.ResultvoidregisterJob(ManagedJob job, Map<String, ?> properties) Register a job.voidvoidvoidsetJobStartDelaySeconds(int jobStartDelaySeconds) Set the number of seconds to delay the first execution of a registered job.voidsetMessageSource(org.springframework.context.MessageSource messageSource) Set the message source.voidsetRandomizedCron(boolean randomizedCron) Set the randomized cron flag.voidunregisterJob(ManagedJob job, Map<String, ?> properties) Unregister a job.
-
Field Details
-
DEFAULT_RANDOMIZED_CRON
public static final boolean DEFAULT_RANDOMIZED_CRONTherandomizedCronproperty default value.- See Also:
-
DEFAULT_JOB_START_DELAY_SECS
public static final int DEFAULT_JOB_START_DELAY_SECSThejobStartDelaySecondsproperty default value.- See Also:
-
-
Constructor Details
-
ManagedJobScheduler
public ManagedJobScheduler(org.osgi.framework.BundleContext bundleContext, org.springframework.scheduling.TaskScheduler taskScheduler) Constructor.- Parameters:
bundleContext- the bundle contexttaskScheduler- the task scheduler- Throws:
IllegalArgumentException- if any argument is null
-
-
Method Details
-
serviceDidStartup
public void serviceDidStartup()- Specified by:
serviceDidStartupin interfacenet.solarnetwork.service.ServiceLifecycleObserver
-
serviceDidShutdown
public void serviceDidShutdown()- Specified by:
serviceDidShutdownin interfacenet.solarnetwork.service.ServiceLifecycleObserver
-
registerJob
Register a job.- Parameters:
job- the job to register and schedule for executionproperties- optional service properties
-
unregisterJob
Unregister a job.- Parameters:
job- the job to unregister and un-schedule for executionproperties- optional service properties
-
configurationEvent
public void configurationEvent(org.osgi.service.cm.ConfigurationEvent event) - Specified by:
configurationEventin interfaceorg.osgi.service.cm.ConfigurationListener
-
getPingTestId
- Specified by:
getPingTestIdin interfacenet.solarnetwork.service.PingTest
-
getPingTestName
- Specified by:
getPingTestNamein interfacenet.solarnetwork.service.PingTest
-
getPingTestMaximumExecutionMilliseconds
public long getPingTestMaximumExecutionMilliseconds()- Specified by:
getPingTestMaximumExecutionMillisecondsin interfacenet.solarnetwork.service.PingTest
-
performPingTest
- Specified by:
performPingTestin interfacenet.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
-