package com.eactive.eai.rms.onl.server.handler;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.eactive.eai.rms.onl.server.repository.Repository;
import com.eactive.eai.rms.onl.vo.AdaptersStatusVO;

@Component("adaptersStatusHandler")
public class AdaptersStatusHandler implements IMessageHandler {
    private static final Logger logger = Logger.getLogger(AdaptersStatusHandler.class);

    public static final int TIME_TO_LIVE = 5;

    public AdaptersStatusHandler() {
	}
    
    @Autowired 
    private Repository repository;

    public Class targetClass() {
        return AdaptersStatusVO.class;
    }

    public void messageReceived(Object message)
            throws Exception {
        AdaptersStatusVO adaptersStatusVO = (AdaptersStatusVO) message;
        
       // HashMap hm = adaptersStatusVO.getAdaptersStatus();
//        
//        for (Object obj : hm.keySet()){
//        	String key = (String)obj;
//        	boolean status = (Boolean)hm.get(key);
////        	System.out.println(key+"="+status);
//        }
        
        repository.addMonitorData(adaptersStatusVO.getHostName(), adaptersStatusVO
                .getInstanceName(), adaptersStatusVO.getCategory(), adaptersStatusVO,
                TIME_TO_LIVE);
        if( logger.isDebugEnabled() ) {
	        logger.debug("RECV AdaptersStatusHandler][" + adaptersStatusVO.getHostName() +"]["  + adaptersStatusVO.getInstanceName() + "]\n[" 
	        		+ adaptersStatusVO);
        }
    }

    public void setRepository(Repository repository) { 
        this.repository = repository;
    }
    
//    public static void main(String[] args) { //취약점소스 수정 2020.08.26
//		AdaptersStatusHandler h = new AdaptersStatusHandler();
//	}

}
