use of org.quartz.Scheduler in project jmxtrans by jmxtrans.
the class JmxTransModule method scheduler.
@Provides
@Inject
Scheduler scheduler(JmxTransConfiguration configuration, GuiceJobFactory jobFactory) throws SchedulerException, IOException {
StdSchedulerFactory serverSchedFact = new StdSchedulerFactory();
try (InputStream stream = openQuartzConfiguration(configuration)) {
serverSchedFact.initialize(stream);
}
Scheduler scheduler = serverSchedFact.getScheduler();
scheduler.setJobFactory(jobFactory);
return scheduler;
}
use of org.quartz.Scheduler in project head by mifos.
the class BatchjobsServiceFacadeWebTier method getBatchjobs.
@Override
public List<BatchjobsDto> getBatchjobs(ServletContext context) throws TaskSystemException, FileNotFoundException, IOException, SchedulerException {
List<BatchjobsDto> batchjobs = new ArrayList<BatchjobsDto>();
MifosScheduler mifosScheduler = (MifosScheduler) context.getAttribute(MifosScheduler.class.getName());
Scheduler scheduler = mifosScheduler.getScheduler();
for (String groupName : scheduler.getJobGroupNames()) {
for (String jobName : scheduler.getJobNames(groupName)) {
Trigger[] triggers = scheduler.getTriggersOfJob(jobName, groupName);
Trigger trigger = triggers.length > 0 ? triggers[0] : null;
JobDetail jobDetail = scheduler.getJobDetail(jobName, groupName);
if (trigger != null && jobDetail != null) {
Date nextFire = trigger.getNextFireTime() != null ? trigger.getNextFireTime() : new Date(0);
Date lastFire = mifosScheduler.getJobsPreviousRunTime(jobName);
Date lastSuccessfulRun = mifosScheduler.getJobsLastSuccessfulRunTime(jobName);
int priority = trigger.getPriority();
String frequency = "";
String taskType = "";
if (trigger instanceof CronTrigger) {
frequency = ((CronTrigger) trigger).getCronExpression();
taskType = CRON_TRIGGER;
}
if (trigger instanceof SimpleTrigger) {
frequency = Long.toString(((SimpleTrigger) trigger).getRepeatInterval());
taskType = SIMPLE_TRIGGER;
}
String previousRunStatus = mifosScheduler.getJobsPreviousRunStatus(jobName);
int triggerState = scheduler.getTriggerState(trigger.getName(), groupName);
String failDescription = mifosScheduler.getJobFailDescription(jobName);
batchjobs.add(new BatchjobsDto(jobName, frequency, taskType, priority, previousRunStatus, lastFire, lastSuccessfulRun, nextFire, triggerState, failDescription));
}
}
}
return batchjobs;
}
use of org.quartz.Scheduler in project head by mifos.
the class BatchjobsServiceFacadeWebTier method getBatchjobsScheduler.
@Override
public BatchjobsSchedulerDto getBatchjobsScheduler(ServletContext context) throws SchedulerException {
MifosScheduler mifosScheduler = (MifosScheduler) context.getAttribute(MifosScheduler.class.getName());
Scheduler scheduler = mifosScheduler.getScheduler();
BatchjobsSchedulerDto batchjobsScheduler = new BatchjobsSchedulerDto(!scheduler.isInStandbyMode());
return batchjobsScheduler;
}
use of org.quartz.Scheduler in project head by mifos.
the class BatchJobCatchUpIntegrationTest method testIncompleteTaskDelay.
@Test
public void testIncompleteTaskDelay() throws Exception {
mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/catchUpTask.xml");
Scheduler scheduler = mifosScheduler.getScheduler();
ProductStatus productStatusTask = new ProductStatus();
productStatusTask.setJobExplorer(mifosScheduler.getBatchJobExplorer());
productStatusTask.setJobLauncher(mifosScheduler.getBatchJobLauncher());
productStatusTask.setJobLocator(mifosScheduler.getBatchJobLocator());
productStatusTask.setJobRepository(mifosScheduler.getBatchJobRepository());
String quartzJobName = "ProductStatusJob";
String quartzTriggerName = "ProductStatusTrigger2";
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.SECOND, 10);
Date previousFireTime = calendar.getTime();
calendar.set(Calendar.SECOND, 21);
Date quartzFireTime = calendar.getTime();
calendar.set(Calendar.SECOND, 22);
Date quartzNextFireTime = calendar.getTime();
calendar.set(Calendar.SECOND, 20);
Date quartzPrevFireTime = calendar.getTime();
JobDetail jobDetail = scheduler.getJobDetail(quartzJobName, Scheduler.DEFAULT_GROUP);
jobDetail.setJobDataMap(new JobDataMap());
CronTrigger trigger = new CronTrigger(quartzTriggerName, Scheduler.DEFAULT_GROUP, quartzJobName, Scheduler.DEFAULT_GROUP, "* * * * * ?");
trigger.setJobDataMap(new JobDataMap());
TriggerFiredBundle triggerFiredBundle = new TriggerFiredBundle(jobDetail, trigger, new BaseCalendar(), false, quartzFireTime, quartzFireTime, quartzPrevFireTime, quartzNextFireTime);
JobExecutionContext jobExecutionContext = new JobExecutionContext(scheduler, triggerFiredBundle, productStatusTask);
JobLauncher jobLauncher = mifosScheduler.getBatchJobLauncher();
JobLocator jobLocator = mifosScheduler.getBatchJobLocator();
jobLauncher.run(jobLocator.getJob(jobName), MifosBatchJob.createJobParameters(previousFireTime.getTime()));
Thread.sleep(1500);
productStatusTask.catchUpMissedLaunches(jobLocator.getJob(jobName), jobExecutionContext);
JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 20);
Assert.assertEquals(11, jobInstances.size());
for (JobInstance jobInstance : jobInstances) {
List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstance);
Assert.assertEquals(BatchStatus.COMPLETED, jobExecutions.get(0).getStatus());
Assert.assertEquals(calendar.getTimeInMillis(), jobInstance.getJobParameters().getLong(MifosBatchJob.JOB_EXECUTION_TIME_KEY));
calendar.roll(Calendar.SECOND, false);
}
}
use of org.quartz.Scheduler in project openhab1-addons by openhab.
the class MpdBinding method cancelScheduler.
/**
* Delete all quartz scheduler jobs of the group <code>MPD</code>.
*/
private void cancelScheduler() {
try {
Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
Set<JobKey> jobKeys = sched.getJobKeys(jobGroupEquals(MPD_SCHEDULER_GROUP));
if (jobKeys.size() > 0) {
sched.deleteJobs(new ArrayList<JobKey>(jobKeys));
logger.debug("Found {} jobs to delete from the DefaultScheduler (keys={})", jobKeys.size(), jobKeys);
}
} catch (SchedulerException e) {
logger.warn("Couldn't remove job(s): {}", e.getMessage());
}
}
Aggregations