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

@Component
public class SmsHandler implements IMessageHandler {
	private static final Logger logger = Logger.getLogger(SmsHandler.class);
	public static final int TIME_TO_LIVE = 5;

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

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

	public void messageReceived( Object message)
			throws Exception {

		SmsVO smsVO = (SmsVO) message; 
		
		if (logger.isDebugEnabled()){
			logger.debug("RECV SmsHandler] smsVO="+smsVO.getMessage() + " HostName=" + smsVO.getHostName() + ", InstanceName=" + smsVO.getInstanceName() );
		}
		repository.addMonitorData(smsVO.getHostName(), smsVO.getInstanceName(),
				smsVO.getCategory(), smsVO, TIME_TO_LIVE);
	}

}
