@Service(value=Scheduler.class, serviceFactory=true) public class SchedulerServiceFactory extends Object implements Scheduler
PROPERTY_SCHEDULER_CONCURRENT, PROPERTY_SCHEDULER_EXPRESSION, PROPERTY_SCHEDULER_IMMEDIATE, PROPERTY_SCHEDULER_NAME, PROPERTY_SCHEDULER_PERIOD, PROPERTY_SCHEDULER_RUN_ON, PROPERTY_SCHEDULER_TIMES, VALUE_RUN_ON_LEADER, VALUE_RUN_ON_SINGLE| Constructor and Description |
|---|
SchedulerServiceFactory() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
activate(org.osgi.service.component.ComponentContext ctx) |
void |
addJob(String name,
Object job,
Map<String,Serializable> config,
String schedulingExpression,
boolean canRunConcurrently)
/**
Schedule a time based job.
|
void |
addPeriodicJob(String name,
Object job,
Map<String,Serializable> config,
long period,
boolean canRunConcurrently)
Schedule a periodic job.
|
void |
addPeriodicJob(String name,
Object job,
Map<String,Serializable> config,
long period,
boolean canRunConcurrently,
boolean startImmediate)
Schedule a periodic job.
|
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)
Fire a job immediately and only once.
|
boolean |
fireJob(Object job,
Map<String,Serializable> config,
int times,
long period)
Fire a job immediately more than once.
|
void |
fireJobAt(String name,
Object job,
Map<String,Serializable> config,
Date date)
Fire a job once at a specific date
Note that if a job with the same name has already been added, the old job is cancelled and this new job replaces
the old job.
|
boolean |
fireJobAt(String name,
Object job,
Map<String,Serializable> config,
Date date,
int times,
long period)
Fire a job once at a specific date, several times with a given interval.
|
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)
Remove a scheduled job by name.
|
boolean |
schedule(Object job,
ScheduleOptions options)
Schedule a job based on the options.
|
boolean |
unschedule(String jobName)
Remove a scheduled job by name.
|
@Activate protected void activate(org.osgi.service.component.ComponentContext ctx)
public boolean schedule(Object job, ScheduleOptions options)
SchedulerJob or a Runnable. The options have to be created
by one of the provided methods from this scheduler.schedule in interface Schedulerjob - The job to execute (either Job or Runnable).options - Required options defining how to schedule the jobScheduler.schedule(java.lang.Object, org.apache.sling.commons.scheduler.ScheduleOptions)public boolean unschedule(String jobName)
Schedulerunschedule in interface Schedulertrue if the job existed and could be stopped, false otherwise.Scheduler.unschedule(java.lang.String)public ScheduleOptions NOW()
SchedulerNOW in interface SchedulerScheduler.NOW()public ScheduleOptions NOW(int times, long period)
SchedulerNOW in interface Schedulertimes - 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).Scheduler.NOW(int, long)public ScheduleOptions AT(Date date)
SchedulerAT in interface Schedulerdate - The date this job should be run.Scheduler.AT(java.util.Date)public ScheduleOptions AT(Date date, int times, long period)
SchedulerAT in interface Schedulerdate - 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).Scheduler.AT(java.util.Date, int, long)public ScheduleOptions EXPR(String expression)
SchedulerEXPR in interface Schedulerexpression - The cron exceptionScheduler.EXPR(java.lang.String)public void addJob(String name, Object job, Map<String,Serializable> config, String schedulingExpression, boolean canRunConcurrently) throws Exception
ScheduleraddJob in interface Schedulername - 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.Scheduler.addJob(java.lang.String, java.lang.Object, java.util.Map, java.lang.String, boolean)public void addPeriodicJob(String name, Object job, Map<String,Serializable> config, long period, boolean canRunConcurrently) throws Exception
ScheduleraddPeriodicJob in interface Schedulername - 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.Scheduler.addPeriodicJob(java.lang.String, java.lang.Object, java.util.Map, long, boolean)public void addPeriodicJob(String name, Object job, Map<String,Serializable> config, long period, boolean canRunConcurrently, boolean startImmediate) throws Exception
ScheduleraddPeriodicJob in interface Schedulername - 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.Scheduler.addPeriodicJob(java.lang.String, java.lang.Object, java.util.Map, long, boolean, boolean)public void fireJob(Object job, Map<String,Serializable> config) throws Exception
SchedulerfireJob in interface Schedulerjob - 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.Scheduler.fireJob(java.lang.Object, java.util.Map)public boolean fireJob(Object job, Map<String,Serializable> config, int times, long period)
SchedulerfireJob in interface Schedulerjob - 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.Scheduler.fireJob(java.lang.Object, java.util.Map, int, long)public void fireJobAt(String name, Object job, Map<String,Serializable> config, Date date) throws Exception
SchedulerfireJobAt in interface Schedulername - 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.Scheduler.fireJobAt(java.lang.String, java.lang.Object, java.util.Map, java.util.Date)public boolean fireJobAt(String name, Object job, Map<String,Serializable> config, Date date, int times, long period)
SchedulerfireJobAt in interface Schedulername - 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.Scheduler.fireJobAt(java.lang.String, java.lang.Object, java.util.Map, java.util.Date, int, long)public void removeJob(String name) throws NoSuchElementException
SchedulerremoveJob in interface Schedulername - The name of the job.NoSuchElementException - If the job is not scheduled.Copyright © 2007–2015 The Apache Software Foundation. All rights reserved.