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

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

Introduction

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

Prototype

@Override
    public void afterPropertiesSet() 

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.  co 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:eu.trentorise.game.managers.QuartzTaskManager.java

public void createTask(GameTask task, String gameId) {
    try {/*from  ww  w .  j  av a 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());
    }
}