Java 类org.quartz.impl.StdScheduler 实例源码

项目:nextreports-server    文件:CleanHistorySettingsPanel.java   
protected void afterChange(Form<?> form, AjaxRequestTarget target) {
    Settings settings = (Settings) form.getModelObject();
    if (!oldCronExpression.equals(settings.getCleanHistory().getCronExpression())) {
        // reschedule clean history
        StdScheduler scheduler = (StdScheduler) NextServerApplication.get().getSpringBean("scheduler");
        CronTriggerImpl cronTrigger = (CronTriggerImpl) NextServerApplication.get()
                .getSpringBean("cleanHistoryTrigger");
        try {
            cronTrigger.setCronExpression(settings.getCleanHistory().getCronExpression());
            scheduler.rescheduleJob(cronTrigger.getKey(), cronTrigger);
        } catch (Exception e) {
            e.printStackTrace();
            LOG.error(e.getMessage(), e);
        }
    }
}
项目:nextreports-server    文件:SynchronizerSettingsPanel.java   
protected void afterChange(Form<?> form, AjaxRequestTarget target) {    
        Settings settings = (Settings)form.getModelObject();                
        if (!oldCronExpression.equals(settings.getSynchronizer().getCronExpression())) {                
            // reschedule user synchronizer
            StdScheduler scheduler = (StdScheduler) NextServerApplication.get().getSpringBean("scheduler");
            CronTriggerImpl cronTrigger = (CronTriggerImpl) NextServerApplication.get().getSpringBean("userSynchronizerTrigger");
            try {
                cronTrigger.setCronExpression(settings.getSynchronizer().getCronExpression());                                      
                scheduler.rescheduleJob(cronTrigger.getKey(), cronTrigger);                 
            } catch (Exception e) {                 
                e.printStackTrace();
                LOG.error(e.getMessage(), e);
            }               
        }
}
项目:plugin-vm    文件:VmResourceTest.java   
@Test
public void createAndUpdateSchedule() throws Exception {
    final ApplicationContext mockContext = Mockito.mock(ApplicationContext.class);
    final VmScheduleRepository vmScheduleRepository = Mockito.mock(VmScheduleRepository.class);
    final VmResource mockResource = Mockito.mock(VmResource.class);
    final Subscription entity = this.subscriptionRepository.findOneExpected(subscription);
    Mockito.when(mockContext.getBean(VmScheduleRepository.class)).thenReturn(vmScheduleRepository);
    Mockito.when(mockContext.getBean(SecurityHelper.class)).thenReturn(Mockito.mock(SecurityHelper.class));
    Mockito.when(mockContext.getBean(VmResource.class)).thenReturn(mockResource);

    final StdScheduler scheduler = (StdScheduler) vmSchedulerFactoryBean.getScheduler();
    final QuartzScheduler qscheduler = (QuartzScheduler) FieldUtils.getField(StdScheduler.class, "sched", true).get(scheduler);
    final QuartzSchedulerResources resources = (QuartzSchedulerResources) FieldUtils.getField(QuartzScheduler.class, "resources", true)
            .get(qscheduler);
    final JobDetail jobDetail = scheduler.getJobDetail(scheduler.getJobKeys(GroupMatcher.anyJobGroup()).iterator().next());

    // "ON" call would fail
    Mockito.doThrow(new RuntimeException()).when(mockResource).execute(entity, VmOperation.ON);

    try {
        // Mock the factory
        jobDetail.getJobDataMap().put("context", mockContext);
        ((RAMJobStore) resources.getJobStore()).storeJob(jobDetail, true);

        Assert.assertEquals(1, this.vmScheduleRepository.findAll().size());

        // Schedule all operations within the next 2 seconds
        final String cron = "" + ((DateUtils.newCalendar().get(Calendar.SECOND) + 2) % 60) + " * * * * ?";
        final int id = mockSchedule(vmScheduleRepository, resource.createSchedule(newSchedule(cron, VmOperation.OFF)));
        mockSchedule(vmScheduleRepository, resource.createSchedule(newSchedule(cron + " *", VmOperation.ON)));
        Assert.assertEquals(3, this.vmScheduleRepository.findAll().size());

        // Yield for the schedules
        Thread.sleep(2500);

        // Check the executions
        Mockito.verify(mockResource).execute(entity, VmOperation.OFF);
        Mockito.verify(mockResource).execute(entity, VmOperation.ON); // Failed
        Mockito.verify(mockResource, Mockito.never()).execute(entity, VmOperation.REBOOT);
        Mockito.verify(mockResource, Mockito.never()).execute(entity, VmOperation.RESET);
        Mockito.verify(mockResource, Mockito.never()).execute(entity, VmOperation.SHUTDOWN);
        Mockito.verify(mockResource, Mockito.never()).execute(entity, VmOperation.SUSPEND);

        // Update the CRON and the operation
        final VmScheduleVo vo = newSchedule("" + ((DateUtils.newCalendar().get(Calendar.SECOND) + 2) % 60) + " * * * * ?",
                VmOperation.SHUTDOWN);
        vo.setId(id);
        vo.setSubscription(subscription);
        resource.updateSchedule(vo);
        Assert.assertEquals(3, this.vmScheduleRepository.findAll().size());

        // Yield for the schedules
        Thread.sleep(2500);
        Mockito.verify(mockResource).execute(entity, VmOperation.SHUTDOWN);
    } finally {
        // Restore the factory's context
        jobDetail.getJobDataMap().put("context", applicationContext);
        ((RAMJobStore) resources.getJobStore()).storeJob(jobDetail, true);
    }
}
项目:fastjava    文件:ScheduleJob.java   
public StdScheduler getScheduler() {
    return scheduler;
}
项目:fastjava    文件:ScheduleJob.java   
public void setScheduler(StdScheduler scheduler) {
    this.scheduler = scheduler;
}