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

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

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

@Component
public class EaiEngineStatusHandler implements IMessageHandler {

    private static final Logger logger = Logger.getLogger(EaiEngineStatusHandler.class);

    @Autowired
    @Qualifier("repository")
    Repository repository;

    public Class<EAIEngineStatusVo> targetClass() {
        return EAIEngineStatusVo.class;
    }

    public void messageReceived( Object message)
            throws Exception {

        EAIEngineStatusVo vo = (EAIEngineStatusVo) message;
        repository.addMonitorData(vo.getHostName(), vo.getInstanceName(),
            vo.getCategory(), vo, 20);
        
        if( logger.isDebugEnabled() ) {
            logger.debug("RECV Engine data["
                + vo.getInstanceName() + "] state="
                + vo.getServerState() + ", host=" 
                + vo.getHostName() );
        }
        
        if( logger.isInfoEnabled() ) {
            logger.info("RECV Engine data["
                + vo.getInstanceName() + "] state="
                + vo.getServerState() + ", host=" 
                + vo.getHostName() );
        }
        
    }

}
