package com.ozs.da.handler;

import com.ozs.da.entity.task.Task;
import com.ozs.da.entity.model.ScheduleRoundEvent;
import com.lmax.disruptor.ExceptionHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @author 许明
 * on 2019/3/7.
 * @version 2.0.0
 */
public class ScheduleRoundExceptionHandler implements ExceptionHandler {

    private static final Logger logger = LogManager.getLogger(ScheduleRoundExceptionHandler.class);

    /**
     * @see com.lmax.disruptor.ExceptionHandler#handleEventException(java.lang.Throwable,
     *      long, java.lang.Object)
     */
    @Override
    public void handleEventException(Throwable ex, long sequence, Object event)
    {
        Task task = ((ScheduleRoundEvent) event).getTask();
        String errorMsg = "";
        if (task != null)
        {
            errorMsg = "job配置错误  job id[" + ((ScheduleRoundEvent) event).getTask().getId() + "]将不进行轮询";
        }
        logger.error(errorMsg, ex);
    }

    /**
     * @see com.lmax.disruptor.ExceptionHandler#handleOnStartException(java.lang.Throwable)
     */
    @Override
    public void handleOnStartException(Throwable ex)
    {
        logger.error("Exception during onStart()", ex);
    }

    /**
     * @see com.lmax.disruptor.ExceptionHandler#handleOnShutdownException(java.lang.Throwable)
     */
    @Override
    public void handleOnShutdownException(Throwable ex)
    {
        logger.error("Exception during onShutdown()", ex);
    }
}
