import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jms.JMSException;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.advisory.DestinationSource;
import org.apache.activemq.command.ActiveMQQueue;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

public class DBConnector {

    public static void main(String args[]){

        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("system","manager","tcp://localhost:61616");
        DBManager dbm = new DBManager();
        Iterator<ActiveMQQueue> lista = null;
        
        try {
            ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
            connection.start();
            DestinationSource source = connection.getDestinationSource();
            Set<ActiveMQQueue> colas = source.getQueues();
            lista = colas.iterator();

        } catch (JMSException ex) {
            System.out.println("Error en conector: "+ex.getMessage());
        }
        
        while(lista.hasNext()){
            String s;
            DataListener dl;
            try {
                s = lista.next().getQueueName();
                if(s.startsWith("DataQueue")){
                    System.out.println(s);
                    String[] nombre = s.split(":");
                    dl = new DataListener(connectionFactory,dbm,nombre[1]);
                    new Thread(dl,nombre[1]).start();
                }
            } catch (JMSException ex) {
                System.out.println("Error al obtener nombres de lista: "+ex.getMessage());
            }
        }

    }
}
