Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TriggerListener #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions modules/quartz/src/main/java/org/jpos/q2/QuartzAdaptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,27 @@
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;
import java.util.Properties;
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 {
Expand Down Expand Up @@ -67,7 +79,8 @@ 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();

Date ft = scheduler.scheduleJob(job, trigger);
Expand Down Expand Up @@ -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);

}

}