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

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

public class QuartzScheduler
extends Object
implements Scheduler

The quartz based implementation of the scheduler.


Field Summary
protected  org.osgi.service.component.ComponentContext context
          The component context.
protected static String DEFAULT_QUARTZ_JOB_GROUP
           
protected  org.slf4j.Logger logger
          Default log.
protected static String PREFIX
           
protected static String QUARTZ_SCHEDULER_NAME
           
protected  List<org.apache.sling.commons.scheduler.impl.QuartzScheduler.Registration> registeredJobs
          List of registrations while this service is not activated yet.
protected  org.quartz.Scheduler scheduler
          Theq quartz scheduler.
protected  ThreadPool threadPool
           
protected  ThreadPoolManager threadPoolManager
           
 
Fields inherited from interface org.apache.sling.commons.scheduler.Scheduler
PROPERTY_SCHEDULER_CONCURRENT, PROPERTY_SCHEDULER_EXPRESSION, PROPERTY_SCHEDULER_NAME, PROPERTY_SCHEDULER_PERIOD
 
Constructor Summary
QuartzScheduler()
           
 
Method Summary
protected  void activate(org.osgi.service.component.ComponentContext ctx)
          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.
protected  void bindJob(org.osgi.framework.ServiceReference ref)
          Bind a new job.
protected  void bindTask(org.osgi.framework.ServiceReference ref)
          Bind a new task.
protected  void checkJob(Object job)
          Check the job object, either runnable or job is allowed
protected  org.quartz.JobDetail createJobDetail(String name, org.quartz.JobDataMap jobDataMap)
          Create the job detail.
protected  void deactivate(org.osgi.service.component.ComponentContext ctx)
          Deactivate this component.
protected  void dispose(org.quartz.Scheduler s)
          Dispose the quartz scheduler
 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 beed 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.
protected  org.quartz.Scheduler init()
          Initialize the quartz scheduler
protected  org.quartz.JobDataMap initDataMap(String jobName, Object job, Map<String,Serializable> config, boolean concurrent)
          Initialize the data map for the job executor.
 void removeJob(String name)
          Remove a scheduled job by name.
protected  void scheduleJob(String name, Object job, Map<String,Serializable> config, org.quartz.Trigger trigger, boolean canRunConcurrently)
          Add a job to the scheduler
protected  void unbindJob(org.osgi.framework.ServiceReference ref)
          Unbind a job.
protected  void unbindTask(org.osgi.framework.ServiceReference ref)
          Unbind a task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.slf4j.Logger logger
Default log.


DEFAULT_QUARTZ_JOB_GROUP

protected static final String DEFAULT_QUARTZ_JOB_GROUP
See Also:
Constant Field Values

PREFIX

protected static final String PREFIX
See Also:
Constant Field Values

QUARTZ_SCHEDULER_NAME

protected static final String QUARTZ_SCHEDULER_NAME
See Also:
Constant Field Values

scheduler

protected volatile org.quartz.Scheduler scheduler
Theq quartz scheduler.


registeredJobs

protected final List<org.apache.sling.commons.scheduler.impl.QuartzScheduler.Registration> registeredJobs
List of registrations while this service is not activated yet.


context

protected volatile org.osgi.service.component.ComponentContext context
The component context.


threadPoolManager

protected ThreadPoolManager threadPoolManager

threadPool

protected ThreadPool threadPool
Constructor Detail

QuartzScheduler

public QuartzScheduler()
Method Detail

activate

protected void activate(org.osgi.service.component.ComponentContext ctx)
                 throws Exception
Activate this component. Start the scheduler.

Parameters:
ctx - The component context.
Throws:
Exception

deactivate

protected void deactivate(org.osgi.service.component.ComponentContext ctx)
Deactivate this component. Stop the scheduler.

Parameters:
ctx - The component context.

init

protected org.quartz.Scheduler init()
                             throws org.quartz.SchedulerException
Initialize the quartz scheduler

Returns:
Return the new scheduler instance.
Throws:
org.quartz.SchedulerException

dispose

protected void dispose(org.quartz.Scheduler s)
Dispose the quartz scheduler

Parameters:
s - The scheduler.

scheduleJob

protected void scheduleJob(String name,
                           Object job,
                           Map<String,Serializable> config,
                           org.quartz.Trigger trigger,
                           boolean canRunConcurrently)
                    throws org.quartz.SchedulerException
Add a job to the scheduler

Parameters:
name - The name of the job to add (or null)
Tje - jopb
trigger - a Trigger
canRunConcurrently - whether this job can be run concurrently
Throws:
org.quartz.SchedulerException - thrown in case of errors

initDataMap

protected org.quartz.JobDataMap initDataMap(String jobName,
                                            Object job,
                                            Map<String,Serializable> config,
                                            boolean concurrent)
Initialize the data map for the job executor.

Parameters:
jobName -
job -
config -
concurent -
Returns:

createJobDetail

protected org.quartz.JobDetail createJobDetail(String name,
                                               org.quartz.JobDataMap jobDataMap)
Create the job detail.

Parameters:
name -
jobDataMap -
Returns:

checkJob

protected void checkJob(Object job)
                 throws IllegalArgumentException
Check the job object, either runnable or job is allowed

Throws:
IllegalArgumentException

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 beed 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 beed 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)

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 beed 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 beed 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 code 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)

bindJob

protected void bindJob(org.osgi.framework.ServiceReference ref)
Bind a new job.

Parameters:
ref -
Throws:
Exception

unbindJob

protected void unbindJob(org.osgi.framework.ServiceReference ref)
Unbind a job.

Parameters:
ref -

bindTask

protected void bindTask(org.osgi.framework.ServiceReference ref)
Bind a new task.

Parameters:
ref -
Throws:
Exception

unbindTask

protected void unbindTask(org.osgi.framework.ServiceReference ref)
Unbind a task.

Parameters:
ref -


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