Example usage for org.springframework.scheduling.quartz JobDetailFactoryBean setJobClass

List of usage examples for org.springframework.scheduling.quartz JobDetailFactoryBean setJobClass

Introduction

In this page you can find the example usage for org.springframework.scheduling.quartz JobDetailFactoryBean setJobClass.

Prototype

public void setJobClass(Class<? extends Job> jobClass) 

Source Link

Document

Specify the job's implementation class.

Usage

From source file:com.wiiyaya.provider.main.utils.BatchHelper.java

private static JobDetail getJobDetail(Batch task) {
    JobDetailFactoryBean jobDetailFactoryBean = new JobDetailFactoryBean();

    jobDetailFactoryBean.setBeanName(task.getTaskName());
    try {/*w w w. ja  v a 2s.c o  m*/
        jobDetailFactoryBean
                .setJobClass(jobDetailFactoryBean.getClass().getClassLoader().loadClass(task.getTaskClass()));
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    jobDetailFactoryBean.setDurability(true);

    // Map<String, Integer> map = new HashMap<>();
    // map.put("timeout", new Integer(5));
    // jobDetailFactoryBean.setJobDataAsMap(map);

    jobDetailFactoryBean.afterPropertiesSet();

    return jobDetailFactoryBean.getObject();
}

From source file:mg.jerytodik.scheduler.config.JeryTodikSchedulerConfig.java

@Bean
public JobDetailFactoryBean jobDetail() {

    JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
    jobDetailFactory.setJobClass(JerytodikResourcesArchiverJob.class);
    jobDetailFactory.setDescription("Invocation du job d'archivage de ressources ...");
    jobDetailFactory.setDurability(true);

    return jobDetailFactory;
}

From source file:jp.classmethod.aws.brian.config.QuartzConfiguration.java

@Bean
public JobDetailFactoryBean brianQuartzJob() {
    JobDetailFactoryBean jobDetailFactoryBean = new JobDetailFactoryBean();
    jobDetailFactoryBean.setJobClass(BrianQuartzJobBean.class);
    jobDetailFactoryBean.setGroup("DEFAULT");
    jobDetailFactoryBean.setName("brianQuartzJob");
    jobDetailFactoryBean.setDurability(true);
    return jobDetailFactoryBean;
}

From source file:eu.trentorise.game.managers.QuartzTaskManager.java

public void createTask(GameTask task, String gameId) {
    try {/* w w w.j a  v a  2  s.c  om*/

        // start the scheduler
        // init in postcontruct not possible cause circolar reference of
        // gameCtx
        if (!scheduler.isStarted()) {
            init();
        }

        GameContext ctx = createGameCtx(gameId, task);
        // check scheduler context data
        if (!scheduler.getContext().containsKey(ctx.getGameRefId() + ":" + task.getName())) {
            scheduler.getContext().put(ctx.getGameRefId() + ":" + task.getName(), ctx);
            logger.debug("Added gameCtx {} to scheduler ctx", ctx.getGameRefId() + ":" + task.getName());
        }
        if (!scheduler.getContext().containsKey(task.getName())) {
            scheduler.getContext().put(task.getName(), task);
            logger.debug("Added {} task to scheduler ctx", task.getName());
        }

        // schedule task
        if (!scheduler.checkExists(new JobKey(task.getName(), ctx.getGameRefId()))
                && !scheduler.checkExists(new TriggerKey(task.getName(), ctx.getGameRefId()))) {
            JobDetailFactoryBean jobFactory = new JobDetailFactoryBean();
            jobFactory.setJobClass(GameJobQuartz.class);
            Map<String, Object> jobdata = new HashMap<String, Object>();
            jobdata.put("taskName", task.getName());
            jobdata.put("gameId", ctx.getGameRefId());
            jobFactory.setName(task.getName());
            jobFactory.setGroup(ctx.getGameRefId());
            jobFactory.setJobDataAsMap(jobdata);
            jobFactory.afterPropertiesSet();
            JobDetail job = jobFactory.getObject();

            CronTriggerFactoryBean triggerFactory = new CronTriggerFactoryBean();
            String cronExpression = task.getSchedule().getCronExpression();
            // fix for version 2.2.1 of CronTrigger
            triggerFactory.setCronExpression(fixCronExpression(cronExpression));
            triggerFactory.setName(task.getName());
            triggerFactory.setGroup(ctx.getGameRefId());
            triggerFactory.setJobDetail(job);
            triggerFactory.afterPropertiesSet();
            Trigger trigger = triggerFactory.getObject();
            scheduler.scheduleJob(job, trigger);
            logger.info("Created and started job task {} in group {}", task.getName(), ctx.getGameRefId());
        } else {
            logger.info("Job task {} in group {} already exists", task.getName(), ctx.getGameRefId());
        }

    } catch (Exception e) {
        logger.error(e.getMessage());
    }
}

From source file:org.libreplan.importers.SchedulerManager.java

/**
 * Creates {@link JobDetailFactoryBean} from the specified
 * <code>{@link JobSchedulerConfiguration}</code>
 *
 * @param jobSchedulerConfiguration/*  w  w w.ja va2s. com*/
 *            configuration to create <code>JobDetailFactoryBean</>
 * @return the created <code>JobDetailFactoryBean</code> or null if unable to it
 */
private JobDetailFactoryBean createJobDetailBean(JobSchedulerConfiguration jobSchedulerConfiguration) {
    JobDetailFactoryBean jobDetailBean = new JobDetailFactoryBean();

    Class<?> jobClass = getJobClass(jobSchedulerConfiguration.getJobClassName());
    if (jobClass == null) {
        return null;
    }

    jobDetailBean.setName(jobSchedulerConfiguration.getJobName());
    jobDetailBean.setGroup(jobSchedulerConfiguration.getJobGroup());
    jobDetailBean.setJobClass(jobClass);

    Map<String, Object> jobDataAsMap = new HashMap<>();
    jobDataAsMap.put("applicationContext", applicationContext);
    jobDetailBean.setJobDataAsMap(jobDataAsMap);

    return jobDetailBean;
}