Introduction
The Scheduling component makes it easy to schedule jobs that are executed at configured intervals or dates. The component is based on the Quartz framework, and adds a whiteboard style approach to registering jobs.
How to use
Creating jobs
Creating jobs is very easy. An OSGi service implementing the org.quartz.Job interface must be published. The scheduling is configured using annotations defined in the org.amdatu.scheduling.api bundle. In the following example a job is registered to execute every 50 milliseconds, repeating 5 times.
package org.amdatu.scheduling.quartz.example.job;
import org.amdatu.scheduling.Job;
import org.amdatu.scheduling.annotations.RepeatCount;
import org.amdatu.scheduling.annotations.RepeatInterval;
import org.amdatu.scheduling.quartz.example.api.MessageStore;
@RepeatCount(5)
@RepeatInterval(period=RepeatInterval.MILLISECOND, value = 50)
public class ExampleAmdatuJobAnnotations implements Job {
private MessageStore m_messageStore;
@Override
public void execute() {
m_messageStore.addMessage("[ANNOTATIONS AMDATU JOB] Message at " + System.currentTimeMillis());
}
}
More examples can be found on BitBucket.
Scheduling syntax
There are several annotations available to easily schedule jobs at specific times and dates.
Check the org.amdatu.scheduling.annotations
and org.amdatu.scheduling.annotations.timeinterval
packages for details.
Some examples are listed below.
There are two categories of annotations:
-
Schedule at specific time / dates
-
Schedule at intervals
//Run every 5 minutes, repeat forever
@RepeatInterval(period=RepeatInterval.MINUTE, value = 5)
@RepeatForever
//Run every 5 minutes, repeat twice
@RepeatInterval(period=RepeatInterval.MINUTE, value = 5)
@RepeatCount(2)
//Run every day at a quarter past noon
@Cron("0 15 12 * * ?")
Components
Amdatu Scheduling provides the following components:
Bundle |
Required |
Description |
org.amdatu.scheduling.api |
yes |
API bundle containing the Amdatu Scheduling annotations |
org.amdatu.scheduling.quartz |
yes |
Quartz based implementation of Amdatu Scheduling |
Of course each individual component may be replaced by your own implementation based on the API if this suits your needs better.
Dependencies
The following table provides an overview of the required and optional dependencies for Amdatu Scheduling:
Bundle |
Required |
Description |
org.apache.felix.dependencymanager |
yes |
Apache Felix Dependency Manager is used internally by all Amdatu components |
Resources
Tools |
Location |
Source Code |
|
Issue Tracking |
|
Continuous Build |
https://bitbucket.org/amdatu/amdatu-scheduling/addon/pipelines/home |