Search in sources :

Example 86 with SchedulerException

use of org.quartz.SchedulerException 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 87 with SchedulerException

use of org.quartz.SchedulerException in project jmxtrans by jmxtrans.

the class JmxTransformer method processServersIntoJobs.

/**
	 * Processes all the Servers into Job's
	 * <p/>
	 * Needs to be called after processFiles()
	 */
private void processServersIntoJobs() throws LifecycleException {
    for (Server server : this.masterServersList) {
        try {
            // need to inject the poolMap
            for (Query query : server.getQueries()) {
                for (OutputWriter writer : query.getOutputWriterInstances()) {
                    writer.start();
                }
            }
            // Now validate the setup of each of the OutputWriter's per
            // query.
            this.validateSetup(server, server.getQueries());
            // Now schedule the jobs for execution.
            this.scheduleJob(server);
        } catch (ParseException ex) {
            throw new LifecycleException("Error parsing cron expression: " + server.getCronExpression(), ex);
        } catch (SchedulerException ex) {
            throw new LifecycleException("Error scheduling job for server: " + server, ex);
        } catch (ValidationException ex) {
            throw new LifecycleException("Error validating json setup for query", ex);
        }
    }
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) SchedulerException(org.quartz.SchedulerException) ValidationException(com.googlecode.jmxtrans.model.ValidationException) MBeanServer(javax.management.MBeanServer) Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) ParseException(java.text.ParseException) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter)

Example 88 with SchedulerException

use of org.quartz.SchedulerException in project pinot by linkedin.

the class AlertJobScheduler method runAdHoc.

public void runAdHoc(Long id, DateTime windowStartTime, DateTime windowEndTime) {
    EmailConfigurationDTO alertConfig = emailConfigurationDAO.findById(id);
    if (alertConfig == null) {
        throw new IllegalArgumentException("No alert config with id " + id);
    }
    String triggerKey = String.format("alert_adhoc_trigger_%d", id);
    Trigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).startNow().build();
    String jobKey = "adhoc_" + getJobKey(id);
    JobDetail job = JobBuilder.newJob(AlertJobRunner.class).withIdentity(jobKey).build();
    AlertJobContext alertJobContext = new AlertJobContext();
    alertJobContext.setJobDAO(anomalyJobDAO);
    alertJobContext.setTaskDAO(anomalyTaskDAO);
    alertJobContext.setEmailConfigurationDAO(emailConfigurationDAO);
    alertJobContext.setAlertConfigId(id);
    alertJobContext.setJobName(jobKey);
    job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_CONTEXT, alertJobContext);
    job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_MONITORING_WINDOW_START_TIME, windowStartTime);
    job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_MONITORING_WINDOW_END_TIME, windowEndTime);
    try {
        quartzScheduler.scheduleJob(job, trigger);
    } catch (SchedulerException e) {
        LOG.error("Exception while scheduling job", e);
    }
    LOG.info("Started {}: {}", jobKey, alertConfig);
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)

Example 89 with SchedulerException

use of org.quartz.SchedulerException in project elastic-job by dangdangdotcom.

the class DaemonTaskScheduler method scheduleJob.

private void scheduleJob(final Scheduler scheduler, final JobDetail jobDetail, final String triggerIdentity, final String cron) {
    try {
        if (!scheduler.checkExists(jobDetail.getKey())) {
            scheduler.scheduleJob(jobDetail, createTrigger(triggerIdentity, cron));
        }
        scheduler.start();
        RUNNING_SCHEDULERS.putIfAbsent(scheduler.getSchedulerName(), scheduler);
    } catch (final SchedulerException ex) {
        throw new JobSystemException(ex);
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) JobSystemException(com.dangdang.ddframe.job.exception.JobSystemException)

Example 90 with SchedulerException

use of org.quartz.SchedulerException in project elastic-job by dangdangdotcom.

the class DaemonTaskScheduler method init.

/**
     * 初始化作业.
     */
public void init() {
    JobDetail jobDetail = JobBuilder.newJob(DaemonJob.class).withIdentity(jobRootConfig.getTypeConfig().getCoreConfig().getJobName()).build();
    jobDetail.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, elasticJob);
    jobDetail.getJobDataMap().put(JOB_FACADE_DATA_MAP_KEY, jobFacade);
    jobDetail.getJobDataMap().put(EXECUTOR_DRIVER_DATA_MAP_KEY, executorDriver);
    jobDetail.getJobDataMap().put(TASK_ID_DATA_MAP_KEY, taskId);
    try {
        scheduleJob(initializeScheduler(), jobDetail, taskId.getValue(), jobRootConfig.getTypeConfig().getCoreConfig().getCron());
    } catch (final SchedulerException ex) {
        throw new JobSystemException(ex);
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) JobSystemException(com.dangdang.ddframe.job.exception.JobSystemException)

Aggregations

SchedulerException (org.quartz.SchedulerException)133 JobDetail (org.quartz.JobDetail)59 Trigger (org.quartz.Trigger)42 Scheduler (org.quartz.Scheduler)37 JobKey (org.quartz.JobKey)33 SimpleTrigger (org.quartz.SimpleTrigger)19 JobDataMap (org.quartz.JobDataMap)18 CronTrigger (org.quartz.CronTrigger)17 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)15 ApplicationContext (org.springframework.context.ApplicationContext)15 ArrayList (java.util.ArrayList)12 SchedulerContext (org.quartz.SchedulerContext)12 IOException (java.io.IOException)11 TriggerKey (org.quartz.TriggerKey)10 Date (java.util.Date)9 JobExecutionException (org.quartz.JobExecutionException)9 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)6 ParseException (java.text.ParseException)5 Command (org.openhab.core.types.Command)5 JobSystemException (com.dangdang.ddframe.job.exception.JobSystemException)4