package com.ozs.da.service.job;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.quartz.JobListener;

/**
 * @author 许明
 * on 2019/3/7.
 * @version 2.0.0
 */
public class TimeTriggerJobListener implements JobListener
{
    private static final Logger logger = LogManager.getLogger(TimeTriggerJobListener.class);

    /**
     * @see org.quartz.JobListener#getName()
     */
    public String getName()
    {
        return getClass().getSimpleName();
    }

    /**
     * @see org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext)
     *      Scheduler 在 JobDetail 即将被执行，但又被 TriggerListener 否决了时调用这个方法。
     */
    public void jobExecutionVetoed(JobExecutionContext context)
    {
        JobKey jobName = context.getJobDetail().getKey();
        logger.debug(jobName + " is about to be executed");
    }

    /**
     * @see org.quartz.JobListener#jobToBeExecuted(org.quartz.JobExecutionContext)
     *      Scheduler 在 JobDetail 将要被执行时调用这个方法。
     */
    public void jobToBeExecuted(JobExecutionContext context)
    {
        JobKey jobName = context.getJobDetail().getKey();
        logger.debug("quartz任务:::" + jobName + ":::开始执行");
    }

    /**
     * @see org.quartz.JobListener#jobWasExecuted(org.quartz.JobExecutionContext,
     *      org.quartz.JobExecutionException) Scheduler 在 JobDetail 被执行之后调用这个方法。
     */
    public void jobWasExecuted(JobExecutionContext context, JobExecutionException exception)
    {
        JobKey jobName = context.getJobDetail().getKey();
        logger.debug("quartz触发任务JOB_NAME[" + jobName + "]执行结束");
    }

}
