use of org.quartz.JobBuilder in project kernel by exoplatform.
the class JobSchedulerServiceImpl method executeJob.
public void executeJob(String jname, String jgroup, JobDataMap jdatamap) throws Exception {
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(jname, getGroupName(jgroup)).startNow().build();
JobBuilder jb = JobBuilder.newJob().withIdentity(jname, getGroupName(jgroup));
JobDetail job = jdatamap == null ? jb.build() : jb.usingJobData(jdatamap).build();
scheduleJob(job, trigger);
}
use of org.quartz.JobBuilder in project Dempsy by Dempsy.
the class AbstractOutputSchedule method getJobDetail.
/**
* Gets the job detail.
*
* @param outputInvoker the output invoker
* @return the job detail
*/
protected JobDetail getJobDetail() {
JobBuilder jobBuilder = JobBuilder.newJob(OutputJob.class);
JobDetail jobDetail = jobBuilder.build();
jobDetail.getJobDataMap().put(OUTPUT_JOB_NAME, this);
return jobDetail;
}
use of org.quartz.JobBuilder in project camel by apache.
the class QuartzEndpoint method createJobDetail.
private JobDetail createJobDetail() throws Exception {
// Camel endpoint timer will assume one to one for JobDetail and Trigger, so let's use same name as trigger
String name = triggerKey.getName();
String group = triggerKey.getGroup();
Class<? extends Job> jobClass = stateful ? StatefulCamelJob.class : CamelJob.class;
LOG.debug("Creating new {}.", jobClass.getSimpleName());
JobBuilder builder = JobBuilder.newJob(jobClass).withIdentity(name, group);
if (durableJob) {
builder = builder.storeDurably();
}
if (recoverableJob) {
builder = builder.requestRecovery();
}
JobDetail result = builder.build();
// Let user parameters to further set JobDetail properties.
if (jobParameters != null && jobParameters.size() > 0) {
LOG.debug("Setting user extra jobParameters {}", jobParameters);
setProperties(result, jobParameters);
}
LOG.debug("Created jobDetail={}", result);
return result;
}
use of org.quartz.JobBuilder in project BRFS by zhangnianli.
the class QuartzBaseSchedulers method addTask.
@Override
public boolean addTask(T task) throws Exception {
if (!checkTask(task)) {
return false;
}
// 1.设置job的名称及执行的class
Class<? extends Job> clazz = (Class<? extends Job>) Class.forName(task.getClassInstanceName());
String taskName = task.getTaskName();
String taskGroup = task.getTaskGroupName();
JobBuilder jobBuilder = JobBuilder.newJob(clazz).withIdentity(taskName, taskGroup);
// 2.设置任务需要的数据
Map<String, String> tmp = task.getTaskContent();
if (tmp != null && !tmp.isEmpty()) {
JobDataMap jobData = new JobDataMap();
jobData.putAll(tmp);
jobBuilder.usingJobData(jobData);
}
// 3.生成jobDetail
JobDetail jobDetail = jobBuilder.build();
// 4.判断触发器的类型 0 cron任务,1 simple任务
int taskType = task.getTaskKind();
String cycleContent = task.getCycleContent();
Trigger trigger = null;
if (taskType == 0) {
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cycleContent);
trigger = TriggerBuilder.newTrigger().withIdentity(taskName, taskGroup).withSchedule(cronScheduleBuilder).build();
} else if (taskType == 1) {
String[] cycles = StringUtils.getSplit(cycleContent, ",");
if (cycles == null || cycles.length == 0) {
throw new NullPointerException("simple trigger cycle time is empty !!! content : " + cycleContent);
}
if (cycles.length != 2) {
throw new NullPointerException("simple trigger cycle time is error !!! content : " + cycleContent);
}
long interval = Long.valueOf(cycles[0]);
int repeateCount = Integer.valueOf(cycles[1]);
SimpleScheduleBuilder sSched = SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(interval).withRepeatCount(repeateCount);
trigger = TriggerBuilder.newTrigger().withIdentity(taskName, taskGroup).startNow().withSchedule(sSched).build();
}
if (trigger == null || jobDetail == null) {
return false;
}
Scheduler scheduler = this.ssf.getScheduler(this.instanceName);
scheduler.scheduleJob(jobDetail, trigger);
return true;
}
use of org.quartz.JobBuilder in project syncope by apache.
the class AfterHandlingJob method schedule.
public static void schedule(final SchedulerFactoryBean scheduler, final Map<String, Object> jobMap) {
@SuppressWarnings("unchecked") AfterHandlingJob jobInstance = (AfterHandlingJob) ApplicationContextProvider.getBeanFactory().createBean(AfterHandlingJob.class, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
String jobName = AfterHandlingJob.class.getName() + UUID_GENERATOR.generate();
jobMap.put(JobManager.DOMAIN_KEY, AuthContextUtils.getDomain());
ApplicationContextProvider.getBeanFactory().registerSingleton(jobName, jobInstance);
JobBuilder jobDetailBuilder = JobBuilder.newJob(AfterHandlingJob.class).withIdentity(jobName).usingJobData(new JobDataMap(jobMap));
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger().withIdentity(JobNamer.getTriggerName(jobName)).startNow();
try {
scheduler.getScheduler().scheduleJob(jobDetailBuilder.build(), triggerBuilder.build());
} catch (SchedulerException e) {
LOG.error("Could not schedule, aborting", e);
}
}
Aggregations