use of org.quartz.JobDetail in project opennms by OpenNMS.
the class ImportJobFactory method newJob.
/**
* {@inheritDoc}
*/
@Override
public Job newJob(final TriggerFiredBundle bundle, final Scheduler scheduler) throws SchedulerException {
JobDetail jobDetail = bundle.getJobDetail();
Class<ImportJob> jobClass = getJobClass(jobDetail);
ImportJob job = null;
try {
job = jobClass.newInstance();
job.setProvisioner(getProvisioner());
return job;
} catch (Throwable e) {
SchedulerException se = new SchedulerException("failed to create job class: " + jobDetail.getJobClass().getName() + "; " + e.getLocalizedMessage(), e);
throw se;
}
}
use of org.quartz.JobDetail in project opennms by OpenNMS.
the class ImportScheduler method buildImportSchedule.
/**
* <p>buildImportSchedule</p>
*/
protected void buildImportSchedule() {
synchronized (m_lock) {
Iterator<RequisitionDef> it = m_configDao.getDefs().iterator();
while (it.hasNext()) {
RequisitionDef def = it.next();
JobDetail detail = null;
CronTriggerImpl trigger = null;
try {
detail = new JobDetailImpl(def.getImportName().orElse(null), JOB_GROUP, ImportJob.class, false, false);
detail.getJobDataMap().put(ImportJob.URL, def.getImportUrlResource().orElse(null));
detail.getJobDataMap().put(ImportJob.RESCAN_EXISTING, def.getRescanExisting());
trigger = new CronTriggerImpl(def.getImportName().orElse(null), JOB_GROUP, def.getCronSchedule().orElse(null));
trigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
getScheduler().scheduleJob(detail, trigger);
} catch (ParseException e) {
LOG.error("buildImportSchedule: {}", e.getLocalizedMessage(), e);
} catch (SchedulerException e) {
LOG.error("buildImportSchedule: {}", e.getLocalizedMessage(), e);
}
}
}
printCurrentSchedule();
}
use of org.quartz.JobDetail in project opennms by OpenNMS.
the class ReportJobFactory method newJob.
/**
* {@inheritDoc}
*/
@Override
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException {
JobDetail jobDetail = bundle.getJobDetail();
Class<ReportJob> jobClass = getJobClass(jobDetail);
ReportJob job = null;
try {
job = jobClass.newInstance();
job.setReportd(getReportd());
return job;
} catch (Throwable e) {
SchedulerException se = new SchedulerException("failed to create job class: " + jobDetail.getJobClass().getName() + "; " + e.getLocalizedMessage(), e);
throw se;
}
}
use of org.quartz.JobDetail in project javaee7-samples by javaee-samples.
the class TestServlet method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Quartz Scheduler</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Quartz Scheduler</h1>");
JobDetail simpleJob = JobBuilder.newJob(MySimpleJob.class).build();
JobDetail cronJob = JobBuilder.newJob(MyCronJob.class).build();
Trigger simpleTrigger = TriggerBuilder.newTrigger().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1).repeatForever()).build();
Trigger cronTrigger = TriggerBuilder.newTrigger().withSchedule(CronScheduleBuilder.cronSchedule("0/3 * * * * ?")).build();
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
out.println("Starting the scheduler");
scheduler.start();
out.println("<h2>Starting Simple Trigger - every 1 second</h2>");
scheduler.scheduleJob(simpleJob, simpleTrigger);
out.println("<h2>Starting Cron Trigger - every 3 seconds</h2>");
scheduler.scheduleJob(cronJob, cronTrigger);
out.println("Sleeping for 7 seconds");
Thread.sleep(7000);
out.println("<br>Shutting down the scheduler");
scheduler.shutdown();
out.println("<br><br>Check \"server.log\" for output - 8 outputs from simple trigger, 3 from cron trigger");
out.println("</body>");
out.println("</html>");
} catch (SchedulerException | InterruptedException ex) {
Logger.getLogger(TestServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of org.quartz.JobDetail in project jmxtrans by jmxtrans.
the class GuiceJobFactory method newJob.
@Override
public Job newJob(TriggerFiredBundle bundle) throws SchedulerException {
JobDetail jobDetail = bundle.getJobDetail();
Class<Job> jobClass = jobDetail.getJobClass();
return injector.getInstance(jobClass);
}
Aggregations