You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Introduction

A scheduled task job class is a Java class that implements the logic of a scheduled task.

The same job can be assigned to more than one Scheduled Task.

Implementation

A scheduled task job is a Java implementation of org.quartz.StatefulJob interface.

In order to simplify the implementation, the abstract Java class AbstractJob has been provided.

AbstractJob implements StatefulJob interface taking care by default of all the things about task information update.

This is the reason why it is strongly recommended to implement scheduled task jobs by extending AbstractJob.

A sample job has been provided below.

package org.apache.syncope.core.scheduling;

import org.quartz.JobExecutionException;
import org.apache.syncope.core.persistence.beans.SchedTask;
import org.apache.syncope.core.persistence.beans.TaskExec;

/**
 * Simple scheduled task job.
 *
 * @see SchedTask
 */
public class DemoJob extends AbstractJob {

    @Override
    protected String doExecute(final boolean dryRun)
            throws JobExecutionException {

        if (!(task instanceof SchedTask)) {
            throw new JobExecutionException("Task " + taskId + " isn't a SchedTask");
        }
        final SchedTask schedTask = (SchedTask) this.task;

        LOG.info(
            "SampleJob {} running [SchedTask {}]", (dryRun ? "dry " : ""), schedTask.getId());

        return (dryRun ? "DRY " : "") + "RUNNING";
    }

    @Override
    protected boolean hasToBeRegistered(final TaskExec execution) {
        return true;
    }
}

Deploy

A job class can be deployed:

  • at project definition time
    by adding own implementation into the overlay project, before to build Syncope.
  • at run-time
    by adding into the container classpath own implementation (container must be re-started to reload the classpath).
  • No labels