From f6de77d685ecfbf52c10a53e2a65f925da73c762 Mon Sep 17 00:00:00 2001 From: Murtuza Chhil Date: Thu, 5 Jul 2018 11:08:50 +0530 Subject: [PATCH 1/2] Implement TriggerListener At times its possible trigger doesn't fire (quartz calls it mis-fire)and we need to log it else we may just not know when a job isn't performed. Mis-fire handling instructions need to be provided at trigger creation time (withMisfireHandlingInstructionFireAndProceed). Also helpful to log when the trigger is fired and completed(part of TriggerListener implementation) along with info when it will get triggered again. --- .../main/java/org/jpos/q2/QuartzAdaptor.java | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/modules/quartz/src/main/java/org/jpos/q2/QuartzAdaptor.java b/modules/quartz/src/main/java/org/jpos/q2/QuartzAdaptor.java index 929e9c0f77..035d55b2ed 100644 --- a/modules/quartz/src/main/java/org/jpos/q2/QuartzAdaptor.java +++ b/modules/quartz/src/main/java/org/jpos/q2/QuartzAdaptor.java @@ -27,7 +27,19 @@ import org.jpos.util.LogSource; import org.jpos.util.Logger; import org.jpos.util.NameRegistrar; -import org.quartz.*; +import org.quartz.CronScheduleBuilder; +import org.quartz.CronTrigger; +import org.quartz.Job; +import org.quartz.JobBuilder; +import org.quartz.JobDataMap; +import org.quartz.JobDetail; +import org.quartz.JobExecutionContext; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.Trigger; +import org.quartz.Trigger.CompletedExecutionInstruction; +import org.quartz.TriggerBuilder; +import org.quartz.TriggerListener; import org.quartz.impl.StdSchedulerFactory; import java.util.Date; @@ -35,7 +47,7 @@ import java.util.UUID; @SuppressWarnings("unused unchecked") -public class QuartzAdaptor extends QBeanSupport implements XmlConfigurable { +public class QuartzAdaptor extends QBeanSupport implements XmlConfigurable, TriggerListener { private Scheduler scheduler; private Element config; protected void initService() throws Exception { @@ -68,6 +80,7 @@ protected void initService() throws Exception { trigger = TriggerBuilder.newTrigger() .withIdentity(e.getAttributeValue("id"), getName()) .withSchedule(CronScheduleBuilder.cronSchedule(e.getAttributeValue("when"))) + .withMisfireHandlingInstructionFireAndProceed()) .build(); Date ft = scheduler.scheduleJob(job, trigger); @@ -152,4 +165,36 @@ private Scheduler createScheduler() throws SchedulerException { return new StdSchedulerFactory(p).getScheduler(); } + + @Override + public void triggerFired(Trigger trigger, JobExecutionContext context) { + LogEvent evt = getLog().createInfo(); + evt.addMessage(getName() + " Trigger Fired and it will fire again at " + trigger.getNextFireTime() + " " + + context.getJobDetail()); + Logger.log(evt); + + } + + @Override + public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) { + return false; + } + + @Override + public void triggerMisfired(Trigger trigger) { + LogEvent evt = getLog().createInfo(); + evt.addMessage(getName() + " Trigger Mis-Fired and will fire again at " + trigger.getNextFireTime()); + Logger.log(evt); + + } + + @Override + public void triggerComplete(Trigger trigger, JobExecutionContext context, + CompletedExecutionInstruction triggerInstructionCode) { + LogEvent evt = getLog().createInfo(); + evt.addMessage("Trigger completed. " + context.getJobDetail()); + Logger.log(evt); + + } + } From ee87887a734d50640566e9e78ae5766c53ded1bb Mon Sep 17 00:00:00 2001 From: Murtuza Chhil Date: Thu, 5 Jul 2018 11:39:27 +0530 Subject: [PATCH 2/2] Update QuartzAdaptor.java Manual edit added an extra bracket --- modules/quartz/src/main/java/org/jpos/q2/QuartzAdaptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/quartz/src/main/java/org/jpos/q2/QuartzAdaptor.java b/modules/quartz/src/main/java/org/jpos/q2/QuartzAdaptor.java index 035d55b2ed..50e5c2c0a1 100644 --- a/modules/quartz/src/main/java/org/jpos/q2/QuartzAdaptor.java +++ b/modules/quartz/src/main/java/org/jpos/q2/QuartzAdaptor.java @@ -79,7 +79,7 @@ protected void initService() throws Exception { try { trigger = TriggerBuilder.newTrigger() .withIdentity(e.getAttributeValue("id"), getName()) - .withSchedule(CronScheduleBuilder.cronSchedule(e.getAttributeValue("when"))) + .withSchedule(CronScheduleBuilder.cronSchedule(e.getAttributeValue("when")) .withMisfireHandlingInstructionFireAndProceed()) .build();