Search in sources :

Example 1 with SimpleTriggerImpl

use of org.quartz.impl.triggers.SimpleTriggerImpl in project opennms by OpenNMS.

the class ImportSchedulerIT method createJobAndVerifyImportJobFactoryIsRegistered.

@Test
public void createJobAndVerifyImportJobFactoryIsRegistered() throws SchedulerException, InterruptedException {
    RequisitionDef def = m_dao.getDefs().get(0);
    JobDetail detail = new JobDetailImpl("test", ImportScheduler.JOB_GROUP, ImportJob.class, false, false);
    detail.getJobDataMap().put(ImportJob.URL, def.getImportUrlResource().orElse(null));
    detail.getJobDataMap().put(ImportJob.RESCAN_EXISTING, def.getRescanExisting());
    class MyBoolWrapper {

        volatile Boolean m_called = false;

        public Boolean getCalled() {
            return m_called;
        }

        public void setCalled(Boolean called) {
            m_called = called;
        }
    }
    final MyBoolWrapper callTracker = new MyBoolWrapper();
    m_importScheduler.getScheduler().getListenerManager().addTriggerListener(new TriggerListener() {

        @Override
        public String getName() {
            return "TestTriggerListener";
        }

        @Override
        public void triggerComplete(Trigger trigger, JobExecutionContext context, Trigger.CompletedExecutionInstruction triggerInstructionCode) {
            LOG.info("triggerComplete called on trigger listener");
            callTracker.setCalled(true);
        }

        @Override
        public void triggerFired(Trigger trigger, JobExecutionContext context) {
            LOG.info("triggerFired called on trigger listener");
            Job jobInstance = context.getJobInstance();
            if (jobInstance instanceof ImportJob) {
                Assert.assertNotNull(((ImportJob) jobInstance).getProvisioner());
                Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.URL));
                Assert.assertEquals("dns://localhost/localhost", context.getJobDetail().getJobDataMap().get(ImportJob.URL));
                Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.RESCAN_EXISTING));
                Assert.assertEquals("dbonly", context.getJobDetail().getJobDataMap().get(ImportJob.RESCAN_EXISTING));
            }
            callTracker.setCalled(true);
        }

        @Override
        public void triggerMisfired(Trigger trigger) {
            LOG.info("triggerMisFired called on trigger listener");
            callTracker.setCalled(true);
        }

        @Override
        public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
            LOG.info("vetoJobExecution called on trigger listener");
            callTracker.setCalled(true);
            return false;
        }
    });
    Calendar testCal = Calendar.getInstance();
    testCal.add(Calendar.SECOND, 5);
    SimpleTriggerImpl trigger = new SimpleTriggerImpl("test", ImportScheduler.JOB_GROUP, testCal.getTime());
    m_importScheduler.getScheduler().scheduleJob(detail, trigger);
    m_importScheduler.start();
    int callCheck = 0;
    while (!callTracker.getCalled() && callCheck++ < 2) {
        Thread.sleep(5000);
    }
// TODO: need to fix the interrupted exception that occurs in the provisioner
}
Also used : SimpleTriggerImpl(org.quartz.impl.triggers.SimpleTriggerImpl) Calendar(java.util.Calendar) TriggerListener(org.quartz.TriggerListener) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) JobDetailImpl(org.quartz.impl.JobDetailImpl) JobExecutionContext(org.quartz.JobExecutionContext) RequisitionDef(org.opennms.netmgt.config.provisiond.RequisitionDef) Job(org.quartz.Job) Test(org.junit.Test)

Example 2 with SimpleTriggerImpl

use of org.quartz.impl.triggers.SimpleTriggerImpl in project jaffa-framework by jaffa-projects.

the class TriggerHelper method createTrigger.

/**
 * Creates a SimpleTrigger with an interval computed from the hours, minutes and seconds.
 */
private static AbstractTrigger<?> createTrigger(ScheduledTask task, Recurrence.Often recurrence) throws FrameworkException, ApplicationExceptions {
    // Compute the repeatInterval for the SimpleTrigger in milliseconds
    long repeatInterval = 0;
    if (recurrence.getHours() != null)
        repeatInterval += recurrence.getHours() * 60 * 60 * 1000;
    if (recurrence.getMinutes() != null)
        repeatInterval += recurrence.getMinutes() * 60 * 1000;
    if (recurrence.getSeconds() != null)
        repeatInterval += recurrence.getSeconds() * 1000;
    SimpleTriggerImpl trigger = new SimpleTriggerImpl();
    if (repeatInterval > 0) {
        trigger.setRepeatInterval(repeatInterval);
        trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
    }
    return trigger;
}
Also used : SimpleTriggerImpl(org.quartz.impl.triggers.SimpleTriggerImpl)

Example 3 with SimpleTriggerImpl

use of org.quartz.impl.triggers.SimpleTriggerImpl in project opennms by OpenNMS.

the class DefaultSchedulerService method execute.

/*
     * (non-Javadoc)
     * @see
     * org.opennms.web.svclayer.support.SchedulerService#execute(org.opennms
     * .web.report.database.model.DatabaseReportCriteria, java.lang.String,
     * org.springframework.webflow.execution.RequestContext)
     */
/**
 * {@inheritDoc}
 */
@Override
public String execute(String id, ReportParameters criteria, DeliveryOptions deliveryOptions, RequestContext context) {
    try {
        if (m_reportWrapperService.validate(criteria, id) == false) {
            context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(PARAMETER_ERROR).build());
            return ERROR;
        } else {
            SimpleTriggerImpl trigger = new SimpleTriggerImpl(deliveryOptions.getInstanceId(), m_triggerGroup, new Date(), null, 0, 0L);
            trigger.setJobName(m_jobDetail.getKey().getName());
            trigger.getJobDataMap().put("criteria", (ReportParameters) criteria);
            trigger.getJobDataMap().put("reportId", id);
            trigger.getJobDataMap().put("mode", ReportMode.IMMEDIATE);
            trigger.getJobDataMap().put("deliveryOptions", (DeliveryOptions) deliveryOptions);
            try {
                m_scheduler.scheduleJob(trigger);
            } catch (SchedulerException e) {
                LOG.warn(SCHEDULER_ERROR, e);
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(SCHEDULER_ERROR).build());
                return ERROR;
            }
            return SUCCESS;
        }
    } catch (ReportServiceLocatorException e) {
        LOG.error(REPORTID_ERROR, e);
        context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(REPORTID_ERROR).build());
        return ERROR;
    }
}
Also used : SimpleTriggerImpl(org.quartz.impl.triggers.SimpleTriggerImpl) SchedulerException(org.quartz.SchedulerException) MessageBuilder(org.springframework.binding.message.MessageBuilder) ReportServiceLocatorException(org.opennms.reporting.core.svclayer.ReportServiceLocatorException) Date(java.util.Date)

Example 4 with SimpleTriggerImpl

use of org.quartz.impl.triggers.SimpleTriggerImpl in project spring-framework by spring-projects.

the class SimpleTriggerFactoryBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    if (this.name == null) {
        this.name = this.beanName;
    }
    if (this.group == null) {
        this.group = Scheduler.DEFAULT_GROUP;
    }
    if (this.jobDetail != null) {
        this.jobDataMap.put("jobDetail", this.jobDetail);
    }
    if (this.startDelay > 0 || this.startTime == null) {
        this.startTime = new Date(System.currentTimeMillis() + this.startDelay);
    }
    SimpleTriggerImpl sti = new SimpleTriggerImpl();
    sti.setName(this.name != null ? this.name : toString());
    sti.setGroup(this.group);
    if (this.jobDetail != null) {
        sti.setJobKey(this.jobDetail.getKey());
    }
    sti.setJobDataMap(this.jobDataMap);
    sti.setStartTime(this.startTime);
    sti.setRepeatInterval(this.repeatInterval);
    sti.setRepeatCount(this.repeatCount);
    sti.setPriority(this.priority);
    sti.setMisfireInstruction(this.misfireInstruction);
    sti.setDescription(this.description);
    this.simpleTrigger = sti;
}
Also used : SimpleTriggerImpl(org.quartz.impl.triggers.SimpleTriggerImpl) Date(java.util.Date)

Aggregations

SimpleTriggerImpl (org.quartz.impl.triggers.SimpleTriggerImpl)4 Date (java.util.Date)2 Calendar (java.util.Calendar)1 Test (org.junit.Test)1 RequisitionDef (org.opennms.netmgt.config.provisiond.RequisitionDef)1 ReportServiceLocatorException (org.opennms.reporting.core.svclayer.ReportServiceLocatorException)1 Job (org.quartz.Job)1 JobDetail (org.quartz.JobDetail)1 JobExecutionContext (org.quartz.JobExecutionContext)1 SchedulerException (org.quartz.SchedulerException)1 Trigger (org.quartz.Trigger)1 TriggerListener (org.quartz.TriggerListener)1 JobDetailImpl (org.quartz.impl.JobDetailImpl)1 MessageBuilder (org.springframework.binding.message.MessageBuilder)1