use of org.quartz.SchedulerException in project opennms by OpenNMS.
the class ReportScheduler method buildReportSchedule.
private void buildReportSchedule() {
synchronized (m_lock) {
for (Report report : m_configDao.getReports()) {
JobDetail detail = null;
CronTriggerImpl trigger = null;
try {
detail = new JobDetailImpl(report.getReportName(), JOB_GROUP, ReportJob.class, false, false);
detail.getJobDataMap().put(ReportJob.KEY, report);
trigger = new CronTriggerImpl(report.getReportName(), JOB_GROUP, report.getCronSchedule());
trigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
getScheduler().scheduleJob(detail, trigger);
} catch (ParseException e) {
LOG.error("buildReportSchedule: {}", e.getMessage(), e);
} catch (SchedulerException e) {
LOG.error("buildReportSchedule: {}", e.getMessage(), e);
}
}
}
}
use of org.quartz.SchedulerException in project OpenClinica by OpenClinica.
the class ImportSpringJob method executeInternal.
@Override
protected void executeInternal(final JobExecutionContext context) throws JobExecutionException {
ApplicationContext appContext;
try {
appContext = (ApplicationContext) context.getScheduler().getContext().get("applicationContext");
TransactionTemplate transactionTemplate = (TransactionTemplate) appContext.getBean("sharedTransactionTemplate");
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
executeInternalInTransaction(context);
}
});
} catch (SchedulerException e) {
throw new JobExecutionException(e);
}
}
use of org.quartz.SchedulerException in project karaf by apache.
the class QuartzScheduler method schedule.
/**
* Schedule a job
* @see org.apache.karaf.scheduler.Scheduler#schedule(java.lang.Object, org.apache.karaf.scheduler.ScheduleOptions)
* @throws SchedulerException if the job can't be scheduled
* @throws IllegalArgumentException If the preconditions are not met
*/
public void schedule(final Object job, final ScheduleOptions options) throws IllegalArgumentException, SchedulerException {
this.checkJob(job);
if (!(options instanceof InternalScheduleOptions)) {
throw new IllegalArgumentException("Options has not been created via schedule or is null.");
}
final InternalScheduleOptions opts = (InternalScheduleOptions) options;
if (opts.argumentException != null) {
throw opts.argumentException;
}
// as this method might be called from unbind and during
// unbind a deactivate could happen, we check the scheduler first
final org.quartz.Scheduler s = this.scheduler;
if (s == null) {
throw new IllegalStateException("Scheduler is not available anymore.");
}
final String name;
if (opts.name != null) {
// if there is already a job with the name, remove it first
try {
final JobKey key = JobKey.jobKey(opts.name);
final JobDetail jobdetail = s.getJobDetail(key);
if (jobdetail != null) {
s.deleteJob(key);
this.logger.debug("Unscheduling job with name {}", opts.name);
}
} catch (final SchedulerException ignored) {
// ignore
}
name = opts.name;
} else {
name = job.getClass().getName() + ':' + UUID.randomUUID();
opts.name = name;
}
final Trigger trigger = opts.trigger.withIdentity(name).build();
// create the data map
final JobDataMap jobDataMap = this.initDataMap(name, job, opts);
final JobDetail detail = this.createJobDetail(name, jobDataMap, opts.canRunConcurrently);
this.logger.debug("Scheduling job {} with name {} and trigger {}", job, name, trigger);
s.scheduleJob(detail, trigger);
}
use of org.quartz.SchedulerException in project sling by apache.
the class QuartzScheduler method removeJob.
/**
* @see org.apache.sling.commons.scheduler.Scheduler#removeJob(java.lang.String)
*/
public void removeJob(final Long bundleId, final String jobName) throws NoSuchElementException {
// as this method might be called from unbind and during
// unbind a deactivate could happen, we check the scheduler first
final Map<String, SchedulerProxy> proxies;
synchronized (this.schedulers) {
if (this.active) {
proxies = new HashMap<>(this.schedulers);
} else {
proxies = Collections.emptyMap();
}
}
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;
}
} catch (final SchedulerException ignored) {
// ignore
}
}
}
if (this.active) {
throw new NoSuchElementException("No job found with name " + jobName);
}
}
use of org.quartz.SchedulerException in project deltaspike by apache.
the class AbstractQuartzScheduler method start.
@Override
public void start() {
if (this.scheduler != null) {
throw new UnsupportedOperationException("the scheduler is started already");
}
SchedulerFactory schedulerFactory = null;
try {
Properties properties = new Properties();
properties.put(StdSchedulerFactory.PROP_SCHED_JOB_FACTORY_CLASS, CdiAwareJobFactory.class.getName());
try {
ResourceBundle config = loadCustomQuartzConfig();
Enumeration<String> keys = config.getKeys();
String key;
while (keys.hasMoreElements()) {
key = keys.nextElement();
properties.put(key, config.getString(key));
}
} catch (Exception e1) {
LOG.info("no custom quartz-config file found. falling back to the default config provided by quartz.");
InputStream inputStream = null;
try {
inputStream = ClassUtils.getClassLoader(null).getResourceAsStream("org/quartz/quartz.properties");
properties.load(inputStream);
} catch (Exception e2) {
LOG.warning("failed to load quartz default-config");
schedulerFactory = new StdSchedulerFactory();
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
if (schedulerFactory == null) {
schedulerFactory = new StdSchedulerFactory(properties);
}
} catch (Exception e) {
LOG.log(Level.WARNING, "fallback to default scheduler-factory", e);
schedulerFactory = new StdSchedulerFactory();
}
try {
this.scheduler = schedulerFactory.getScheduler();
if (SchedulerBaseConfig.LifecycleIntegration.START_SCOPES_PER_JOB) {
this.scheduler.getListenerManager().addJobListener(new InjectionAwareJobListener());
}
if (!this.scheduler.isStarted()) {
this.scheduler.startDelayed(SchedulerBaseConfig.LifecycleIntegration.DELAYED_START_IN_SECONDS);
}
} catch (SchedulerException e) {
throw ExceptionUtils.throwAsRuntimeException(e);
}
}
Aggregations