Search in sources :

Example 96 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 97 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 98 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());
                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 99 with JobDetail

use of org.quartz.JobDetail in project series-rest-api by 52North.

the class PreRenderingJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    if (interrupted) {
        return;
    }
    LOGGER.info("Start prerendering task");
    final Stopwatch stopwatch = Stopwatch.startStopwatch();
    final JobDetail details = context.getJobDetail();
    JobDataMap jobDataMap = details.getJobDataMap();
    taskConfigPrerendering = readJobConfig(jobDataMap.getString(JOB_DATA_CONFIG_FILE));
    webappFolder = jobDataMap.getString(JOB_DATA_WEBAPP_FOLDER);
    List<RenderingConfig> phenomenonStyles = taskConfigPrerendering.getPhenomenonStyles();
    List<RenderingConfig> styles = taskConfigPrerendering.getSeriesStyles();
    for (RenderingConfig config : phenomenonStyles) {
        Map<String, String> parameters = new HashMap<>();
        parameters.put("phenomenon", config.getId());
        IoParameters query = QueryParameters.createFromQuery(parameters);
        for (DatasetOutput<?, ?> metadata : datasetService.getCondensedParameters(query)) {
            String timeseriesId = metadata.getId();
            renderConfiguredIntervals(timeseriesId, config);
            if (interrupted) {
                return;
            }
        }
    }
    for (RenderingConfig config : styles) {
        renderConfiguredIntervals(config.getId(), config);
        if (interrupted) {
            return;
        }
    }
    LOGGER.debug("prerendering took '{}'", stopwatch.stopInSeconds());
}
Also used : JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) HashMap(java.util.HashMap) Stopwatch(org.n52.web.common.Stopwatch) IoParameters(org.n52.io.request.IoParameters) RenderingConfig(org.n52.io.PrerenderingJobConfig.RenderingConfig)

Example 100 with JobDetail

use of org.quartz.JobDetail in project oxCore by GluuFederation.

the class QuartzSchedulerManager method schedule.

public void schedule(@Observes TimerEvent timerEvent) {
    checkInitialized();
    JobDataMap dataMap = new JobDataMap();
    dataMap.put(TimerJob.KEY_TIMER_EVENT, timerEvent);
    String uuid = UUID.randomUUID().toString();
    JobDetail timerJob = JobBuilder.newJob(TimerJob.class).withIdentity(TimerJob.class.getSimpleName() + "_" + uuid, TimerJob.TIMER_JOB_GROUP).usingJobData(dataMap).build();
    TimerSchedule timerSchedule = timerEvent.getSchedule();
    Date triggerStartTime = new Date(System.currentTimeMillis() + timerSchedule.getDelay() * 1000L);
    Trigger timerTrigger = TriggerBuilder.newTrigger().withIdentity(uuid, TimerJob.TIMER_JOB_GROUP).startAt(triggerStartTime).withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(timerSchedule.getInterval())).build();
    try {
        scheduler.scheduleJob(timerJob, timerTrigger);
    } catch (SchedulerException ex) {
        throw new IllegalStateException("Failed to schedule Timer Event", ex);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) TimerSchedule(org.xdi.service.timer.schedule.TimerSchedule) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) Date(java.util.Date)

Aggregations

JobDetail (org.quartz.JobDetail)122 SchedulerException (org.quartz.SchedulerException)56 Trigger (org.quartz.Trigger)47 Scheduler (org.quartz.Scheduler)33 Test (org.junit.Test)30 CronTrigger (org.quartz.CronTrigger)25 JobKey (org.quartz.JobKey)22 SimpleTrigger (org.quartz.SimpleTrigger)21 JobDataMap (org.quartz.JobDataMap)18 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)14 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 TriggerKey (org.quartz.TriggerKey)10 HashMap (java.util.HashMap)8 IOException (java.io.IOException)5 Serializable (java.io.Serializable)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Command (org.openhab.core.types.Command)5 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4