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

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

Introduction

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

Prototype

@Override
    @Nullable
    public JobDetail getObject() 

Source Link

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 {//from  www  .j  a v a  2  s  .c om
        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:eu.trentorise.game.managers.QuartzTaskManager.java

public void createTask(GameTask task, String gameId) {
    try {// ww  w  .  java  2 s  .  c  o  m

        // 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 CronTriggerFactoryBean} and {@link JobDetailFactoryBean} based on the
 * specified <code>{@link JobSchedulerConfiguration}</code>. First delete
 * job if exist and then schedule it/*w  ww.j a  v  a  2 s.c o m*/
 *
 * @param jobSchedulerConfiguration
 *            where to reade jobs to be scheduled
 * @throws SchedulerException
 *             if unable to delete and/or schedule job
 */
private void scheduleNewJob(JobSchedulerConfiguration jobSchedulerConfiguration) throws SchedulerException {
    CronTriggerFactoryBean cronTriggerBean = createCronTriggerBean(jobSchedulerConfiguration);
    if (cronTriggerBean == null) {
        return;
    }

    JobDetailFactoryBean jobDetailBean = createJobDetailBean(jobSchedulerConfiguration);
    if (jobDetailBean == null) {
        return;
    }

    deleteJob(jobSchedulerConfiguration);
    this.scheduler.scheduleJob(jobDetailBean.getObject(), cronTriggerBean.getObject());
}