package com.yihu.hos.common;

import com.yihu.hos.web.framework.constrant.DateConvert;
import com.yihu.hos.core.log.Logger;
import com.yihu.hos.core.log.LoggerFactory;
import org.apache.commons.beanutils.ConvertUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.Date;

/**
 * 项目启动执行
 * add by hzp at 2016-01-25
 */
public class ApplicationStart implements ServletContextListener {
    static private final Logger logger = LoggerFactory.getLogger(ApplicationStart.class);


    private static int rebootCount = 0;

    @Override
    public void contextInitialized(ServletContextEvent context) {
        //使用自定义转化器转化时间格式
        ConvertUtils.register(new DateConvert(), Date.class);

        //initQuartz();//启动任务
    }

    @Override
    public void contextDestroyed(ServletContextEvent context) {
        destroyedQuartz();
    }

    /**
     * 初始化任务
     * @return
     */
    public void initQuartz(){
        try {
            //QuartzManager.startJobs();
        } catch(Exception e){
            logger.error(" Quartz job initing Exception " + e.getMessage());
        }
    }

    /**
     * 终止任务
     */
    public void destroyedQuartz(){
        try {
            //QuartzManager.shutdownJobs();
        } catch(Exception e){
           logger.error(" Quartz job destroying Exception " + e.getMessage());
        }
    }

}
