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

@Component
public class HostStatusHandler implements IMessageHandler {

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

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

    private int timeToLive = 30;

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

    public void messageReceived( Object message)
            throws Exception {
        HostStatusVo vo = (HostStatusVo) message;
        repository.addMonitorData(vo, timeToLive);
        
        if( logger.isDebugEnabled() ) {
            logger.debug("RECV Host data["
                + vo.getInstanceName() + "] cpu="
                + vo.getCpu() + ", mem="
                + vo.getMemory() + ", disk="
                + vo.getDisk() );
        }

    }

}
