org.apache.sling.commons.scheduler.impl
Class QuartzScheduler

java.lang.Object
  extended by org.apache.sling.commons.scheduler.impl.QuartzScheduler
All Implemented Interfaces:
Scheduler

@Service(value=Scheduler.class)
public class QuartzScheduler
extends Object
implements Scheduler

The quartz based implementation of the scheduler.


Nested Class Summary
static class QuartzScheduler.QuartzThreadPool
           
 
Field Summary
 
Fields inherited from interface org.apache.sling.commons.scheduler.Scheduler
PROPERTY_SCHEDULER_CONCURRENT, PROPERTY_SCHEDULER_EXPRESSION, PROPERTY_SCHEDULER_IMMEDIATE, PROPERTY_SCHEDULER_NAME, PROPERTY_SCHEDULER_PERIOD, PROPERTY_SCHEDULER_RUN_ON, VALUE_RUN_ON_LEADER, VALUE_RUN_ON_SINGLE
 
Constructor Summary
QuartzScheduler()
           
 
Method Summary
protected  void activate(org.osgi.framework.BundleContext ctx, Map<String,Object> props)
          Activate this component.
 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
protected  void deactivate()
          Deactivate this component.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuartzScheduler

public QuartzScheduler()
Method Detail

activate

@Activate
protected void activate(org.osgi.framework.BundleContext ctx,
                                 Map<String,Object> props)
                 throws Exception
Activate this component. Start the scheduler.

Throws:
Exception

deactivate

@Deactivate
protected void deactivate()
Deactivate this component. Stop the scheduler.


addJob

public void addJob(String name,
                   Object job,
                   Map<String,Serializable> config,
                   String schedulingExpression,
                   boolean canRunConcurrently)
            throws org.quartz.SchedulerException
Description copied from interface: Scheduler
/** Schedule a time based job. 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.

Specified by:
addJob in interface Scheduler
Parameters:
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.
Throws:
org.quartz.SchedulerException
See Also:
Scheduler.addJob(java.lang.String, java.lang.Object, java.util.Map, java.lang.String, boolean)

addPeriodicJob

public void addPeriodicJob(String name,
                           Object job,
                           Map<String,Serializable> config,
                           long period,
                           boolean canRunConcurrently)
                    throws org.quartz.SchedulerException
Description copied from interface: Scheduler
Schedule a periodic job. The job is started the first time when the period has passed. 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.

Specified by:
addPeriodicJob in interface Scheduler
Parameters:
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.
Throws:
org.quartz.SchedulerException
See Also:
Scheduler.addPeriodicJob(java.lang.String, java.lang.Object, java.util.Map, long, boolean)

addPeriodicJob

public void addPeriodicJob(String name,
                           Object job,
                           Map<String,Serializable> config,
                           long period,
                           boolean canRunConcurrently,
                           boolean startImmediate)
                    throws org.quartz.SchedulerException
Description copied from interface: Scheduler
Schedule a periodic job. 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.

Specified by:
addPeriodicJob in interface Scheduler
Parameters:
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.
Throws:
org.quartz.SchedulerException
See Also:
Scheduler.addPeriodicJob(java.lang.String, java.lang.Object, java.util.Map, long, boolean, boolean)

fireJob

public void fireJob(Object job,
                    Map<String,Serializable> config)
             throws org.quartz.SchedulerException
Description copied from interface: Scheduler
Fire a job immediately and only once.

Specified by:
fireJob in interface Scheduler
Parameters:
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.
Throws:
org.quartz.SchedulerException
See Also:
Scheduler.fireJob(java.lang.Object, java.util.Map)

fireJobAt

public void fireJobAt(String name,
                      Object job,
                      Map<String,Serializable> config,
                      Date date)
               throws org.quartz.SchedulerException
Description copied from interface: Scheduler
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.

Specified by:
fireJobAt in interface Scheduler
Parameters:
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.
Throws:
org.quartz.SchedulerException
See Also:
Scheduler.fireJobAt(java.lang.String, java.lang.Object, java.util.Map, java.util.Date)

fireJob

public boolean fireJob(Object job,
                       Map<String,Serializable> config,
                       int times,
                       long period)
Description copied from interface: Scheduler
Fire a job immediately more than once.

Specified by:
fireJob in interface Scheduler
Parameters:
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.
Returns:
true if the code could be added, false otherwise.
See Also:
Scheduler.fireJob(java.lang.Object, java.util.Map, int, long)

fireJobAt

public boolean fireJobAt(String name,
                         Object job,
                         Map<String,Serializable> config,
                         Date date,
                         int times,
                         long period)
Description copied from interface: Scheduler
Fire a job once at a specific date, several times with a given interval. 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.

Specified by:
fireJobAt in interface Scheduler
Parameters:
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.
Returns:
true if the job could be added, false otherwise.
See Also:
Scheduler.fireJobAt(java.lang.String, java.lang.Object, java.util.Map, java.util.Date, int, long)

removeJob

public void removeJob(String name)
               throws NoSuchElementException
Description copied from interface: Scheduler
Remove a scheduled job by name.

Specified by:
removeJob in interface Scheduler
Parameters:
name - The name of the job.
Throws:
NoSuchElementException - If the job is not scheduled.
See Also:
Scheduler.removeJob(java.lang.String)

NOW

public ScheduleOptions NOW()
Description copied from interface: Scheduler
Create a schedule options to fire a job immediately and only once.

Specified by:
NOW in interface Scheduler
See Also:
Scheduler.NOW()

NOW

public ScheduleOptions NOW(int times,
                           long period)
Description copied from interface: Scheduler
Create a schedule options to fire a job immediately more than once.

Specified by:
NOW in interface Scheduler
Parameters:
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).
See Also:
Scheduler.NOW(int, long)

AT

public ScheduleOptions AT(Date date)
Description copied from interface: Scheduler
Create a schedule options to fire a job once at a specific date

Specified by:
AT in interface Scheduler
Parameters:
date - The date this job should be run.
See Also:
Scheduler.AT(java.util.Date)

AT

public ScheduleOptions AT(Date date,
                          int times,
                          long period)
Description copied from interface: Scheduler
Create a schedule options to fire a job period starting at a specific date

Specified by:
AT in interface Scheduler
Parameters:
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).
See Also:
Scheduler.AT(java.util.Date, int, long)

EXPR

public ScheduleOptions EXPR(String expression)
Description copied from interface: Scheduler
Create a schedule options to schedule the job based on the expression

Specified by:
EXPR in interface Scheduler
Parameters:
expression - The cron exception
See Also:
Scheduler.EXPR(java.lang.String)

schedule

public boolean schedule(Object job,
                        ScheduleOptions options)
Description copied from interface: Scheduler
Schedule a job based on the options. 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. The job object needs either to be a Job or a Runnable. The options have to be created by one of the provided methods from this scheduler.

Specified by:
schedule in interface Scheduler
Parameters:
job - The job to execute (either Job or Runnable).
options - Required options defining how to schedule the job
Returns:
true if the job could be added, false otherwise.
See Also:
Scheduler.schedule(java.lang.Object, org.apache.sling.commons.scheduler.ScheduleOptions)

unschedule

public boolean unschedule(String jobName)
Description copied from interface: Scheduler
Remove a scheduled job by name.

Specified by:
unschedule in interface Scheduler
Returns:
true if the job existed and could be stopped, false otherwise.
See Also:
Scheduler.unschedule(java.lang.String)


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.