use of org.quartz.JobKey in project deltaspike by apache.
the class DynamicExpressionObserverJob method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getMergedJobDataMap();
String configExpression = jobDataMap.getString(CONFIG_EXPRESSION_KEY);
String triggerId = jobDataMap.getString(TRIGGER_ID_KEY);
String activeCronExpression = jobDataMap.getString(ACTIVE_CRON_EXPRESSION_KEY);
String configKey = configExpression.substring(1, configExpression.length() - 1);
String configuredValue = ConfigResolver.getPropertyAwarePropertyValue(configKey, activeCronExpression);
if (!activeCronExpression.equals(configuredValue)) {
//both #put calls are needed currently
context.getJobDetail().getJobDataMap().put(ACTIVE_CRON_EXPRESSION_KEY, configuredValue);
context.getTrigger().getJobDataMap().put(ACTIVE_CRON_EXPRESSION_KEY, configuredValue);
BeanProvider.injectFields(this);
JobKey observerJobKey = context.getJobDetail().getKey();
String observedJobName = observerJobKey.getName().substring(0, observerJobKey.getName().length() - OBSERVER_POSTFIX.length());
JobKey observedJobKey = new JobKey(observedJobName, observerJobKey.getGroup());
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerId).forJob(observedJobName, observedJobKey.getGroup()).withSchedule(CronScheduleBuilder.cronSchedule(configuredValue)).build();
//use rescheduleJob instead of delete + add
//(unwrap is ok here, because this class will only get active in case of a quartz-scheduler)
org.quartz.Scheduler quartzScheduler = scheduler.unwrap(org.quartz.Scheduler.class);
try {
quartzScheduler.rescheduleJob(trigger.getKey(), trigger);
} catch (SchedulerException e) {
LOG.warning("failed to updated cron-expression for " + observedJobKey);
}
}
}
use of org.quartz.JobKey in project deltaspike by apache.
the class AbstractQuartzScheduler method createExpressionObserverJob.
private void createExpressionObserverJob(JobKey jobKey, UUID triggerKey, String configExpression, String cronExpression) throws SchedulerException {
if (!ClassDeactivationUtils.isActivated(DynamicExpressionObserverJob.class)) {
return;
}
JobKey observerJobKey = new JobKey(jobKey.getName() + DynamicExpressionObserverJob.OBSERVER_POSTFIX, jobKey.getGroup());
JobDetail jobDetail = JobBuilder.newJob(DynamicExpressionObserverJob.class).usingJobData(DynamicExpressionObserverJob.CONFIG_EXPRESSION_KEY, configExpression).usingJobData(DynamicExpressionObserverJob.TRIGGER_ID_KEY, triggerKey.toString()).usingJobData(DynamicExpressionObserverJob.ACTIVE_CRON_EXPRESSION_KEY, cronExpression).withDescription("Config observer for: " + jobKey).withIdentity(observerJobKey).build();
Trigger trigger = TriggerBuilder.newTrigger().forJob(observerJobKey).withSchedule(CronScheduleBuilder.cronSchedule(SchedulerBaseConfig.JobCustomization.DYNAMIC_EXPRESSION_OBSERVER_INTERVAL)).build();
this.scheduler.scheduleJob(jobDetail, trigger);
}
use of org.quartz.JobKey in project karaf by apache.
the class QuartzScheduler method unschedule.
/**
* @see org.apache.karaf.scheduler.Scheduler#unschedule(java.lang.String)
*/
public boolean unschedule(final String jobName) {
final org.quartz.Scheduler s = this.scheduler;
if (jobName != null && s != null) {
try {
final JobKey key = JobKey.jobKey(jobName);
final JobDetail jobdetail = s.getJobDetail(key);
if (jobdetail != null) {
s.deleteJob(key);
this.logger.debug("Unscheduling job with name {}", jobName);
return true;
}
} catch (final SchedulerException ignored) {
// ignore
}
}
return false;
}
use of org.quartz.JobKey in project karaf by apache.
the class QuartzScheduler method getJobs.
@Override
public Map<Object, ScheduleOptions> getJobs() throws SchedulerException {
Map<Object, ScheduleOptions> jobs = new HashMap<>();
org.quartz.Scheduler s = this.scheduler;
if (s != null) {
for (String group : s.getJobGroupNames()) {
for (JobKey key : s.getJobKeys(GroupMatcher.jobGroupEquals(group))) {
JobDetail detail = s.getJobDetail(key);
ScheduleOptions options = (ScheduleOptions) detail.getJobDataMap().get(DATA_MAP_OPTIONS);
Object job = detail.getJobDataMap().get(DATA_MAP_OBJECT);
jobs.put(job, options);
}
}
}
return jobs;
}
use of org.quartz.JobKey in project sling by apache.
the class QuartzScheduler method unschedule.
/**
* @see org.apache.sling.commons.scheduler.Scheduler#unschedule(java.lang.String)
*/
public boolean unschedule(final Long bundleId, final String jobName) {
if (jobName != null) {
final Map<String, SchedulerProxy> proxies;
synchronized (this.schedulers) {
proxies = new HashMap<>(this.schedulers);
}
for (final SchedulerProxy proxy : proxies.values()) {
synchronized (proxy) {
try {
final JobKey key = JobKey.jobKey(jobName);
final JobDetail jobdetail = proxy.getScheduler().getJobDetail(key);
if (jobdetail != null) {
proxy.getScheduler().deleteJob(key);
this.logger.debug("Unscheduling job with name {}", jobName);
return true;
}
} catch (final SchedulerException ignored) {
// ignore
}
}
}
}
return false;
}
Aggregations