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.AdaptersVO;

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

    public static final int TIME_TO_LIVE = 5;

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

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

    public void messageReceived( Object message) throws Exception {
        AdaptersVO adaptersVO = (AdaptersVO) message;
        repository.addMonitorData(adaptersVO.getHostName(), adaptersVO
                .getInstanceName(), adaptersVO.getCategory(), adaptersVO,
                TIME_TO_LIVE);
        if( logger.isDebugEnabled() ) {
	        logger.debug("RECV AdaptersHandler][" + adaptersVO.getHostName() +"]["  + adaptersVO.getInstanceName() + "]\n[" + adaptersVO);
        }
    }

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

}
