1. Introduction

This plugin allows your Griffon application to schedule jobs to be executed using a specified interval or cron expression. The underlying system uses the Quartz Scheduler.

Griffon version: 2.12.0

2. Usage

The following sections describe how you may use this plugin in a project.

2.1. Configuration

Jobs can be automatically configured and started upon application startup by annotating them with @Scheduled and @ServiceProviderFor as shown in the following example

package com.acme;

import org.kordamp.jipsy.ServiceProviderFor;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
@ServiceProviderFor(Job.class)
@Scheduled(cronExpression = "0/2 * * * * ?")
public class HelloWorldJob implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        System.out.println("Job well done!");
    }
}

Jobs defined in this way can participate in Dependency Injection. You may also obtain a reference to the org.quartz.Scheduler instance and manually schedule a Job.

3. Build Configuration

3.1. Gradle

You have two options for configuring this plugin: automatic and manual.

3.1.1. Automatic

As long as the project has the org.codehaus.griffon.griffon plugin applied to it you may include the following snippet in build.gradle

dependencies {
    griffon 'org.codehaus.griffon.plugins:griffon-quartz-plugin:1.1.0'
}

The griffon plugin will take care of the rest given its configuration.

3.1.2. Manual

You will need to configure any of the following blocks depending on your setup

dependencies {
    compile 'org.codehaus.griffon.plugins:griffon-quartz-core:1.1.0'
}

3.2. Maven

First configure the griffon-quartz-plugin BOM in your POM file, by placing the following snippet before the <build> element

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.griffon.plugins</groupId>
            <artifactId>griffon-quartz-plugin</artifactId>
            <version>1.1.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Next configure dependencies as required by your particular setup

<dependency>
    <groupId>org.codehaus.griffon.plugins</groupId>
    <artifactId>griffon-quartz-core</artifactId>
</dependency>

4. Modules

The following sections display all bindings per module. Use this information to successfully override a binding on your own modules or to troubleshoot a module binding if the wrong type has been applied by the Griffon runtime.

4.1. Quartz

Module name: quartz

bind(Scheduler.class)
    .toProvider(SchedulerProvider.class)
    .asSingleton();

bind(JobFactory.class)
    .to(InjectorAwareJobFactory.class)
    .asSingleton();

bind(GriffonAddon.class)
    .to(QuartzAddon.class)
    .asSingleton();