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

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

Introduction

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

Prototype

public void setGroup(String group) 

Source Link

Document

Specify the job's group.

Usage

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 {/*from   w  ww  . j a  va  2s.  co 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 JobDetailFactoryBean} from the specified
 * <code>{@link JobSchedulerConfiguration}</code>
 *
 * @param jobSchedulerConfiguration/*from w w  w. j a  v a  2  s.  c o m*/
 *            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;
}