Search in sources :

Example 66 with JobDetail

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;
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException)

Example 67 with JobDetail

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();
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) JobDetailImpl(org.quartz.impl.JobDetailImpl) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) RequisitionDef(org.opennms.netmgt.config.provisiond.RequisitionDef) ParseException(java.text.ParseException)

Example 68 with JobDetail

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;
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException)

Example 69 with JobDetail

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);
    }
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) PrintWriter(java.io.PrintWriter)

Example 70 with JobDetail

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);
}
Also used : JobDetail(org.quartz.JobDetail) Job(org.quartz.Job)

Aggregations

JobDetail (org.quartz.JobDetail)131 SchedulerException (org.quartz.SchedulerException)59 Trigger (org.quartz.Trigger)51 Scheduler (org.quartz.Scheduler)34 Test (org.junit.Test)30 CronTrigger (org.quartz.CronTrigger)26 JobKey (org.quartz.JobKey)22 SimpleTrigger (org.quartz.SimpleTrigger)22 JobDataMap (org.quartz.JobDataMap)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 TriggerKey (org.quartz.TriggerKey)10 HashMap (java.util.HashMap)8 Date (java.util.Date)7 ArrayList (java.util.ArrayList)5 Command (org.openhab.core.types.Command)5 IOException (java.io.IOException)4 Serializable (java.io.Serializable)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4