zoukankan      html  css  js  c++  java
  • 好记性不如烂博客之 Quartz HowTo: Using Trigger Listeners

    How-To: Using Trigger Listeners

    Creating a TriggerListener

    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
        }
    }
    
    

    Registering A TriggerListener With The Scheduler To Listen To All Triggers

    scheduler.getListenerManager().addTriggerListener(myTriggerListener, allTriggers());
    
    

    Registering A TriggerListener With The Scheduler To Listen To A Specific Trigger

    scheduler.getListenerManager().addTriggerListener(myTriggerListener, triggerKeyEquals(triggerKey("myTriggerName", "myTriggerGroup")));
    
    

    Registering A TriggerListener With The Scheduler To Listen To All Triggers In a Group

    scheduler.getListenerManager().addTriggerListener(myTriggerListener, triggerGroupEquals("myTriggerGroup"));
    

     

  • 相关阅读:
    区块链中的密码学
    初识nodeJS
    JS或jQuery获取当前屏幕宽度
    jQuery与Zepto的异同
    使用递归解决斐波那契数列的性能问题
    sass高级语法的补充
    sass的高级语法
    栅格 CSS中的循环 媒体查询
    Zepto
    dedecms 留言板中引用模板文件方法
  • 原文地址:https://www.cnblogs.com/daxin/p/3110664.html
Copyright © 2011-2022 走看看