org.apache.sling.commons.scheduler
Interface Scheduler

All Known Implementing Classes:
QuartzScheduler

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.


Field Summary
static java.lang.String PROPERTY_SCHEDULER_CONCURRENT
          Name of the configuration property to define if the job can be run concurrently.
static java.lang.String PROPERTY_SCHEDULER_EXPRESSION
          Name of the configuration property to define the cron expression for a job.
static java.lang.String PROPERTY_SCHEDULER_IMMEDIATE
          Name of the configuration property to define if a periodically job should be scheduled immediate.
static java.lang.String PROPERTY_SCHEDULER_NAME
          Name of the configuration property to define the job name.
static java.lang.String PROPERTY_SCHEDULER_PERIOD
          Name of the configuration property to define the period for a job.
 
Method Summary
 void addJob(java.lang.String name, java.lang.Object job, java.util.Map<java.lang.String,java.io.Serializable> config, java.lang.String schedulingExpression, boolean canRunConcurrently)
          Schedule a time based job.
 void addPeriodicJob(java.lang.String name, java.lang.Object job, java.util.Map<java.lang.String,java.io.Serializable> config, long period, boolean canRunConcurrently)
          Schedule a periodic job.
 void addPeriodicJob(java.lang.String name, java.lang.Object job, java.util.Map<java.lang.String,java.io.Serializable> config, long period, boolean canRunConcurrently, boolean startImmediate)
          Schedule a periodic job.
 void fireJob(java.lang.Object job, java.util.Map<java.lang.String,java.io.Serializable> config)
          Fire a job immediately and only once.
 boolean fireJob(java.lang.Object job, java.util.Map<java.lang.String,java.io.Serializable> config, int times, long period)
          Fire a job immediately more than once.
 void fireJobAt(java.lang.String name, java.lang.Object job, java.util.Map<java.lang.String,java.io.Serializable> config, java.util.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(java.lang.String name, java.lang.Object job, java.util.Map<java.lang.String,java.io.Serializable> config, java.util.Date date, int times, long period)
          Fire a job once at a specific date, several times with a given interval.
 void removeJob(java.lang.String name)
          Remove a scheduled job by name.
 

Field Detail

PROPERTY_SCHEDULER_PERIOD

static final java.lang.String PROPERTY_SCHEDULER_PERIOD
Name of the configuration property to define the period for a job. The period is expressed in seconds. This property needs to be of type Long.

See Also:
Constant Field Values

PROPERTY_SCHEDULER_IMMEDIATE

static final java.lang.String PROPERTY_SCHEDULER_IMMEDIATE
Name of the configuration property to define if a periodically job should be scheduled immediate. Default is to not startup immediate, the job is started the first time after the period has expired. This property needs to be of type Boolean.

Since:
2.2.0 .
See Also:
Constant Field Values

PROPERTY_SCHEDULER_EXPRESSION

static final java.lang.String PROPERTY_SCHEDULER_EXPRESSION
Name of the configuration property to define the cron expression for a job.

See Also:
Constant Field Values

PROPERTY_SCHEDULER_CONCURRENT

static final java.lang.String PROPERTY_SCHEDULER_CONCURRENT
Name of the configuration property to define if the job can be run concurrently.

See Also:
Constant Field Values

PROPERTY_SCHEDULER_NAME

static final java.lang.String PROPERTY_SCHEDULER_NAME
Name of the configuration property to define the job name.

See Also:
Constant Field Values
Method Detail

addJob

void addJob(java.lang.String name,
            java.lang.Object job,
            java.util.Map<java.lang.String,java.io.Serializable> config,
            java.lang.String schedulingExpression,
            boolean canRunConcurrently)
            throws java.lang.Exception
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.

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:
java.lang.IllegalArgumentException - If the scheduling expression can't be parsed or if the job has not the correct type.
java.lang.Exception - If the job can't be scheduled.

addPeriodicJob

void addPeriodicJob(java.lang.String name,
                    java.lang.Object job,
                    java.util.Map<java.lang.String,java.io.Serializable> config,
                    long period,
                    boolean canRunConcurrently)
                    throws java.lang.Exception
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.

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:
java.lang.IllegalArgumentException - If the job has not the correct type.
java.lang.Exception - If the job can't be scheduled.

addPeriodicJob

void addPeriodicJob(java.lang.String name,
                    java.lang.Object job,
                    java.util.Map<java.lang.String,java.io.Serializable> config,
                    long period,
                    boolean canRunConcurrently,
                    boolean startImmediate)
                    throws java.lang.Exception
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.

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:
java.lang.IllegalArgumentException - If the job has not the correct type.
java.lang.Exception - If the job can't be scheduled.
Since:
2.2

fireJob

void fireJob(java.lang.Object job,
             java.util.Map<java.lang.String,java.io.Serializable> config)
             throws java.lang.Exception
Fire a job immediately and only once.

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:
java.lang.IllegalArgumentException - If the job has not the correct type.
java.lang.Exception - If the job can't be scheduled.

fireJob

boolean fireJob(java.lang.Object job,
                java.util.Map<java.lang.String,java.io.Serializable> config,
                int times,
                long period)
Fire a job immediately more than once.

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.
Throws:
java.lang.IllegalArgumentException - If the job has not the correct type.
Since:
2.1

fireJobAt

void fireJobAt(java.lang.String name,
               java.lang.Object job,
               java.util.Map<java.lang.String,java.io.Serializable> config,
               java.util.Date date)
               throws java.lang.Exception
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.

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:
java.lang.IllegalArgumentException - If the job has not the correct type.
java.lang.Exception - If the job can't be scheduled.

fireJobAt

boolean fireJobAt(java.lang.String name,
                  java.lang.Object job,
                  java.util.Map<java.lang.String,java.io.Serializable> config,
                  java.util.Date date,
                  int times,
                  long period)
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.

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 code could be added, false otherwise.
Throws:
java.lang.IllegalArgumentException - If the job has not the correct type.
Since:
2.1

removeJob

void removeJob(java.lang.String name)
               throws java.util.NoSuchElementException
Remove a scheduled job by name.

Parameters:
name - The name of the job.
Throws:
java.util.NoSuchElementException - If the job is not scheduled.


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