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);
}
}
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);
}
}
}
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);
}
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);
}
}
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);
}
}
Aggregations