|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Scheduler
A scheduler to schedule time/cron based jobs.
A job is an object that is executed/fired by the scheduler. The object
should either implement the Job interface or the Runnable
interface.
A job can be scheduled either by creating a ScheduleOptions instance
through one of the scheduler methods and then calling schedule(Object, ScheduleOptions)
or
by using the whiteboard pattern and registering a Runnable service with either
the PROPERTY_SCHEDULER_EXPRESSION or PROPERTY_SCHEDULER_PERIOD
property. Services registered by the whiteboard pattern can by default run concurrently,
which usually is not wanted. Therefore it is advisable to also set the
PROPERTY_SCHEDULER_CONCURRENT property with Boolean.FALSE.
| Field Summary | |
|---|---|
static String |
PROPERTY_SCHEDULER_CONCURRENT
Name of the configuration property to define if the job can be run concurrently. |
static String |
PROPERTY_SCHEDULER_EXPRESSION
Name of the configuration property to define the cron expression for a job. |
static String |
PROPERTY_SCHEDULER_IMMEDIATE
Name of the configuration property to define if a periodically job should be scheduled immediate. |
static String |
PROPERTY_SCHEDULER_NAME
Name of the configuration property to define the job name. |
static String |
PROPERTY_SCHEDULER_PERIOD
Name of the configuration property to define the period for a job. |
static String |
PROPERTY_SCHEDULER_RUN_ON
Name of the configuration property to define the instances this job should run on. |
static String |
VALUE_RUN_ON_LEADER
Value for PROPERTY_SCHEDULER_RUN_ON to run the job on the leader only. |
static String |
VALUE_RUN_ON_SINGLE
Value for PROPERTY_SCHEDULER_RUN_ON to run the job on a single instance only. |
| Method Summary | |
|---|---|
void |
addJob(String name,
Object job,
Map<String,Serializable> config,
String schedulingExpression,
boolean canRunConcurrently)
Deprecated. Use schedule(Object, ScheduleOptions) instead. |
void |
addPeriodicJob(String name,
Object job,
Map<String,Serializable> config,
long period,
boolean canRunConcurrently)
Deprecated. Use schedule(Object, ScheduleOptions) instead. |
void |
addPeriodicJob(String name,
Object job,
Map<String,Serializable> config,
long period,
boolean canRunConcurrently,
boolean startImmediate)
Deprecated. Use schedule(Object, ScheduleOptions) instead. |
ScheduleOptions |
AT(Date date)
Create a schedule options to fire a job once at a specific date |
ScheduleOptions |
AT(Date date,
int times,
long period)
Create a schedule options to fire a job period starting at a specific date |
ScheduleOptions |
EXPR(String expression)
Create a schedule options to schedule the job based on the expression |
void |
fireJob(Object job,
Map<String,Serializable> config)
Deprecated. Use schedule(Object, ScheduleOptions) instead. |
boolean |
fireJob(Object job,
Map<String,Serializable> config,
int times,
long period)
Deprecated. Use schedule(Object, ScheduleOptions) instead. |
void |
fireJobAt(String name,
Object job,
Map<String,Serializable> config,
Date date)
Deprecated. Use schedule(Object, ScheduleOptions) instead. |
boolean |
fireJobAt(String name,
Object job,
Map<String,Serializable> config,
Date date,
int times,
long period)
Deprecated. Use schedule(Object, ScheduleOptions) instead. |
ScheduleOptions |
NOW()
Create a schedule options to fire a job immediately and only once. |
ScheduleOptions |
NOW(int times,
long period)
Create a schedule options to fire a job immediately more than once. |
void |
removeJob(String name)
Deprecated. Use unschedule(String) instead. |
boolean |
schedule(Object job,
ScheduleOptions options)
Schedule a job based on the options. |
boolean |
unschedule(String jobName)
Remove a scheduled job by name. |
| Field Detail |
|---|
static final String PROPERTY_SCHEDULER_PERIOD
static final String PROPERTY_SCHEDULER_IMMEDIATE
static final String PROPERTY_SCHEDULER_EXPRESSION
static final String PROPERTY_SCHEDULER_CONCURRENT
static final String PROPERTY_SCHEDULER_NAME
static final String PROPERTY_SCHEDULER_RUN_ON
VALUE_RUN_ON_LEADER : the job is only run on the leader
- constant VALUE_RUN_ON_SINGLE : the job is only run on a single instance in a cluster. This is
basically the same as VALUE_RUN_ON_LEADER but it's not further specified which
single instance is used.
Default is to start the job on all instances. This property needs to be of type String
or String[].
If no topology information is available (= no Apache Sling Discovery Implementation active)
this option is ignored, and the job is run on all instances.
static final String VALUE_RUN_ON_LEADER
PROPERTY_SCHEDULER_RUN_ON to run the job on the leader only.
static final String VALUE_RUN_ON_SINGLE
PROPERTY_SCHEDULER_RUN_ON to run the job on a single instance only.
| Method Detail |
|---|
boolean schedule(Object job,
ScheduleOptions options)
Job or a Runnable. The options have to be created
by one of the provided methods from this scheduler.
job - The job to execute (either Job or Runnable).options - Required options defining how to schedule the job
NOW(),
NOW(int, long),
AT(Date),
AT(Date, int, long),
EXPR(String)boolean unschedule(String jobName)
name - The name of the job.
true if the job existed and could be stopped, false otherwise.ScheduleOptions NOW()
ScheduleOptions NOW(int times,
long period)
times - The number of times this job should be started (must be higher than 1 or
-1 for endless)period - Every period seconds this job is started (must be at higher than 0).ScheduleOptions AT(Date date)
date - The date this job should be run.
ScheduleOptions AT(Date date,
int times,
long period)
date - The date this job should be run.times - The number of times this job should be started (must be higher than 1 or
-1 for endless)period - Every period seconds this job is started (must be at higher than 0).ScheduleOptions EXPR(String expression)
expression - The cron exception
@Deprecated
void addJob(String name,
Object job,
Map<String,Serializable> config,
String schedulingExpression,
boolean canRunConcurrently)
throws Exception
schedule(Object, ScheduleOptions) instead.
name - The name of the job - or null. If no name is specified it can't be cancelled.job - The job to execute (either Job or Runnable).config - An optional configuration object - this configuration is only passed to the job the job implements Job.schedulingExpression - The time specification using a scheduling expression.canRunConcurrently - Whether this job can run even if previous scheduled runs are still running.
IllegalArgumentException - If the scheduling expression can't be parsed or if the job has not the correct type.
Exception - If the job can't be scheduled.
@Deprecated
void addPeriodicJob(String name,
Object job,
Map<String,Serializable> config,
long period,
boolean canRunConcurrently)
throws Exception
schedule(Object, ScheduleOptions) instead.
name - The name of the job - or null. If no name is specified it can't be cancelled.job - The job to execute (either Job or Runnable).config - An optional configuration object - this configuration is only passed to the job the job implements Job.period - Every period seconds this job is started.canRunConcurrently - Whether this job can run even if previous scheduled runs are still running.
IllegalArgumentException - If the job has not the correct type.
Exception - If the job can't be scheduled.
@Deprecated
void addPeriodicJob(String name,
Object job,
Map<String,Serializable> config,
long period,
boolean canRunConcurrently,
boolean startImmediate)
throws Exception
schedule(Object, ScheduleOptions) instead.
name - The name of the job - or null. If no name is specified it can't be cancelled.job - The job to execute (either Job or Runnable).config - An optional configuration object - this configuration is only passed to the job the job implements Job.period - Every period seconds this job is started.canRunConcurrently - Whether this job can run even if previous scheduled runs are still running.startImmediate - Whether to start the job immediately for the first time or wait for the period to expire.
IllegalArgumentException - If the job has not the correct type.
Exception - If the job can't be scheduled.
@Deprecated
void fireJob(Object job,
Map<String,Serializable> config)
throws Exception
schedule(Object, ScheduleOptions) instead.
job - The job to execute (either Job or Runnable).config - An optional configuration object - this configuration is only passed to the job the job implements Job.
IllegalArgumentException - If the job has not the correct type.
Exception - If the job can't be scheduled.
@Deprecated
boolean fireJob(Object job,
Map<String,Serializable> config,
int times,
long period)
schedule(Object, ScheduleOptions) instead.
job - The job to execute (either Job or Runnable).config - An optional configuration object - this configuration is only passed to the job the job implements Job.times - The number of times this job should be started (must be higher than 1)period - Every period seconds this job is started.
IllegalArgumentException - If the job has not the correct type.
@Deprecated
void fireJobAt(String name,
Object job,
Map<String,Serializable> config,
Date date)
throws Exception
schedule(Object, ScheduleOptions) instead.
name - The name of the job - or null. If no name is specified it can't be cancelled.job - The job to execute (either Job or Runnable).config - An optional configuration object - this configuration is only passed to the job the job implements Job.date - The date this job should be run.
IllegalArgumentException - If the job has not the correct type.
Exception - If the job can't be scheduled.
@Deprecated
boolean fireJobAt(String name,
Object job,
Map<String,Serializable> config,
Date date,
int times,
long period)
schedule(Object, ScheduleOptions) instead.
name - The name of the job - or null. If no name is specified it can't be cancelled.job - The job to execute (either Job or Runnable).config - An optional configuration object - this configuration is only passed to the job the job implements Job.date - The date this job should be run.times - The number of times this job should be started (must be higher than 1)period - Every period seconds this job is started.
IllegalArgumentException - If the job has not the correct type.
@Deprecated
void removeJob(String name)
throws NoSuchElementException
unschedule(String) instead.
name - The name of the job.
NoSuchElementException - If the job is not scheduled.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||