Implement the TriggerListener interface.
package foo;
import org.quartz.JobExecutionContext;
import org.quartz.Trigger;
import org.quartz.TriggerListener;
import org.quartz.Trigger.CompletedExecutionInstruction;
public class MyTriggerListener implements TriggerListener {
private String name;
public MyTriggerListener(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void triggerComplete(Trigger trigger, JobExecutionContext context,
CompletedExecutionInstruction triggerInstructionCode) {
// do something with the event
}
public void triggerFired(Trigger trigger, JobExecutionContext context) {
// do something with the event
}
public void triggerMisfired(Trigger trigger) {
// do something with the event
}
public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
// do something with the event
return false;
}
}
OR -
Extend TriggerListenerSupport.
package foo;
import org.quartz.JobExecutionContext;
import org.quartz.Trigger;
import org.quartz.listeners.TriggerListenerSupport;
public class MyOtherTriggerListener extends TriggerListenerSupport {
private String name;
public MyOtherTriggerListener(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public void triggerFired(Trigger trigger, JobExecutionContext context) {
// do something with the event
}
}
scheduler.getListenerManager().addTriggerListener(myTriggerListener, allTriggers());
scheduler.getListenerManager().addTriggerListener(myTriggerListener, triggerKeyEquals(triggerKey("myTriggerName", "myTriggerGroup")));
scheduler.getListenerManager().addTriggerListener(myTriggerListener, triggerGroupEquals("myTriggerGroup"));