package com.eactive.eai.rms.onl.common.service;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import com.eactive.eai.rms.common.util.CommonUtil;
import com.eactive.eai.rms.onl.common.scheduler.Schedule;

@Schedule
@Component
public class MemoryTrInitJob implements Job{

    /** The Constant logger. */
    private static final Logger logger = Logger.getLogger(MemoryTrInitJob.class);
	
    private MemoryTrInitService memTrService;
	
	/**
	 * 자정에 수행한다.
	 */
    //@ScheduleMethod(type = ScheduleType.CRON, cronExpression = "1 0 0 * * ?")
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
       // JobKey jobKey = context.getJobDetail().getKey();

		ApplicationContext appContext = null;
		try {
			appContext = (ApplicationContext)context.getScheduler().getContext().get("applicationContext");
		} catch (SchedulerException e) {
			logger.error("applicationContext get module error",e);
			return ;
		}  
		memTrService = (MemoryTrInitService)appContext.getBean("memoryTrInitService");	
		
    	logger.info("START SCHEDULER RESET TRANSACTION ! : " + CommonUtil.getToday(""));
    	
        memTrService.clearTransactionMemoryMap();
    	
        logger.info("END SCHEDULER RESET TRANSACTION ! : " + CommonUtil.getToday(""));
		
	}    
}
