package ve.gob.cnti.receiver.ejb;

import java.util.Map;
import java.util.logging.Logger;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;






import ve.gob.cnti.receiver.jdbc.ConnectionJDBC;
import ve.gob.cnti.receiver.jdbc.IConnectionJDBC;
import ve.gob.cnti.receiver.utils.IMapMessageConverter;
import ve.gob.cnti.receiver.utils.MapMessageConverter;



/**
 * Message-Driven Bean implementation class for: ReciberJMS
 */
@MessageDriven(
		activationConfig = { @ActivationConfigProperty(
				propertyName = "destination", propertyValue = "java:/jms/queue/process"), @ActivationConfigProperty(
				propertyName = "destinationType", propertyValue = "javax.jms.Queue")
		}, 
		mappedName = "java:/jms/queue/process")
public class ReciverProcess implements MessageListener {
	private static final Logger log = Logger.getLogger(ReciverProcess.class.getName());
    /**
     * Default constructor. 
     */
	
    public ReciverProcess() {
        // TODO Auto-generated constructor stub
    }
	
	/**
     * @see MessageListener#onMessage(Message)
     */
    
	public void onMessage(Message message) {
        // TODO Auto-generated method stub     
			log.info("timer 1 segundos");
			try {
			    Thread.sleep(1000);                 //1000 milliseconds is one second.
			   
			} catch(InterruptedException ex) {
			    Thread.currentThread().interrupt();
			}
    	    log.info("usando el ejb para ingresar el proceso finalizado en la bd");
    		MapMessage incoming = (MapMessage)message;
    		IConnectionJDBC connection=new ConnectionJDBC();
    		IMapMessageConverter converterMessage=new MapMessageConverter();
    		Map<String,String> map=converterMessage.converMapMessageToMap(incoming);
    		connection.insertRecordProcess(map);
    		//connection.deleteRecordDocuments(Long.valueOf(map.get("id_instancia")));
    		connection.closeConnection();
    	 
        
	}

}
