use of org.quartz.impl.JobDetailImpl in project spring-framework by spring-projects.
the class JobDetailFactoryBean method afterPropertiesSet.
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() {
if (this.name == null) {
this.name = this.beanName;
}
if (this.group == null) {
this.group = Scheduler.DEFAULT_GROUP;
}
if (this.applicationContextJobDataKey != null) {
if (this.applicationContext == null) {
throw new IllegalStateException("JobDetailBean needs to be set up in an ApplicationContext " + "to be able to handle an 'applicationContextJobDataKey'");
}
getJobDataMap().put(this.applicationContextJobDataKey, this.applicationContext);
}
JobDetailImpl jdi = new JobDetailImpl();
jdi.setName(this.name);
jdi.setGroup(this.group);
jdi.setJobClass((Class) this.jobClass);
jdi.setJobDataMap(this.jobDataMap);
jdi.setDurability(this.durability);
jdi.setRequestsRecovery(this.requestsRecovery);
jdi.setDescription(this.description);
this.jobDetail = jdi;
}
use of org.quartz.impl.JobDetailImpl in project opennms by OpenNMS.
the class ImportSchedulerIT method createJobAndVerifyImportJobFactoryIsRegistered.
@Test
public void createJobAndVerifyImportJobFactoryIsRegistered() throws SchedulerException, InterruptedException {
RequisitionDef def = m_dao.getDefs().get(0);
JobDetail detail = new JobDetailImpl("test", ImportScheduler.JOB_GROUP, ImportJob.class, false, false);
detail.getJobDataMap().put(ImportJob.URL, def.getImportUrlResource());
detail.getJobDataMap().put(ImportJob.RESCAN_EXISTING, def.getRescanExisting());
class MyBoolWrapper {
volatile Boolean m_called = false;
public Boolean getCalled() {
return m_called;
}
public void setCalled(Boolean called) {
m_called = called;
}
}
final MyBoolWrapper callTracker = new MyBoolWrapper();
m_importScheduler.getScheduler().getListenerManager().addTriggerListener(new TriggerListener() {
@Override
public String getName() {
return "TestTriggerListener";
}
@Override
public void triggerComplete(Trigger trigger, JobExecutionContext context, Trigger.CompletedExecutionInstruction triggerInstructionCode) {
LOG.info("triggerComplete called on trigger listener");
callTracker.setCalled(true);
}
@Override
public void triggerFired(Trigger trigger, JobExecutionContext context) {
LOG.info("triggerFired called on trigger listener");
Job jobInstance = context.getJobInstance();
if (jobInstance instanceof ImportJob) {
Assert.assertNotNull(((ImportJob) jobInstance).getProvisioner());
Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.URL));
Assert.assertEquals("dns://localhost/localhost", context.getJobDetail().getJobDataMap().get(ImportJob.URL));
Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.RESCAN_EXISTING));
Assert.assertEquals("dbonly", context.getJobDetail().getJobDataMap().get(ImportJob.RESCAN_EXISTING));
}
callTracker.setCalled(true);
}
@Override
public void triggerMisfired(Trigger trigger) {
LOG.info("triggerMisFired called on trigger listener");
callTracker.setCalled(true);
}
@Override
public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
LOG.info("vetoJobExecution called on trigger listener");
callTracker.setCalled(true);
return false;
}
});
Calendar testCal = Calendar.getInstance();
testCal.add(Calendar.SECOND, 5);
SimpleTriggerImpl trigger = new SimpleTriggerImpl("test", ImportScheduler.JOB_GROUP, testCal.getTime());
m_importScheduler.getScheduler().scheduleJob(detail, trigger);
m_importScheduler.start();
int callCheck = 0;
while (!callTracker.getCalled() && callCheck++ < 2) {
Thread.sleep(5000);
}
//TODO: need to fix the interrupted exception that occurs in the provisioner
}
use of org.quartz.impl.JobDetailImpl 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.impl.JobDetailImpl in project engine by craftercms.
the class ConfigurationScriptJobResolverTest method testResolveJobs.
@Test
public void testResolveJobs() throws Exception {
List<JobContext> jobContexts = resolver.resolveJobs(siteContext);
assertNotNull(jobContexts);
assertEquals(2, jobContexts.size());
JobDetailImpl jobDetail = (JobDetailImpl) jobContexts.get(0).getDetail();
CronTrigger trigger = (CronTrigger) jobContexts.get(0).getTrigger();
assertEquals(ScriptJob.class, jobDetail.getJobClass());
assertEquals("/scripts/jobs/morejobs/testJob2.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
assertEquals("0 0/15 * * * ?", trigger.getCronExpression());
jobDetail = (JobDetailImpl) jobContexts.get(1).getDetail();
trigger = (CronTrigger) jobContexts.get(1).getTrigger();
assertEquals(ScriptJob.class, jobDetail.getJobClass());
assertEquals("/scripts/jobs/testJob.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
assertEquals("0 0/15 * * * ?", trigger.getCronExpression());
}
use of org.quartz.impl.JobDetailImpl in project spring-framework by spring-projects.
the class MethodInvokingJobDetailFactoryBean method afterPropertiesSet.
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException {
prepare();
// Use specific name if given, else fall back to bean name.
String name = (this.name != null ? this.name : this.beanName);
// Consider the concurrent flag to choose between stateful and stateless job.
Class<?> jobClass = (this.concurrent ? MethodInvokingJob.class : StatefulMethodInvokingJob.class);
// Build JobDetail instance.
JobDetailImpl jdi = new JobDetailImpl();
jdi.setName(name);
jdi.setGroup(this.group);
jdi.setJobClass((Class) jobClass);
jdi.setDurability(true);
jdi.getJobDataMap().put("methodInvoker", this);
this.jobDetail = jdi;
postProcessJobDetail(this.jobDetail);
}
Aggregations