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

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

    public static final int TIME_TO_LIVE = 5;

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

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

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

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

}
