

import java.util.Iterator;
import java.util.Set;
import java.util.regex.Pattern;
import javax.jms.Connection;
import javax.jms.ConnectionMetaData;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.QueueConnection;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.swing.JComboBox;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.advisory.DestinationListener;
import org.apache.activemq.advisory.DestinationSource;
import org.apache.activemq.broker.region.Queue;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTempQueue;
import org.apache.activemq.command.ActiveMQTopic;

/**
 *
 * @author David Rodriguez A.
 */
public class UpdateQueueList  {
    public UpdateQueueList(ClientFrame frame) throws JMSException{
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("system", "manager", "tcp://localhost:61616");
        ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
        connection.start();
        
        //obteniendo lista de colas----------------------------------
        DestinationSource source = connection.getDestinationSource();
        Set<ActiveMQQueue> queues = source.getQueues();
        Iterator<ActiveMQQueue> list = queues.iterator();
        Iterator<ActiveMQQueue> list2 = queues.iterator();

        /*Agrega lista al comboBox*/
        while(list.hasNext()){
            String s=list.next().getQueueName();
            //System.out.println(s.startsWith("ControlQueue"));
            if(s.startsWith("ControlQueue")){
                String[] result= s.split(":");
                frame.getCombo().addItem(result[1]);
            }
        }
        
        //sacando las colas para el cliente
        while(list2.hasNext()){
            String s2=list2.next().getQueueName();
             if(s2.startsWith("ClientDataQueue")){
                String[] result= s2.split(":");
                System.out.println(result[1]);
                DataListener data = new DataListener(connectionFactory,s2,frame);
                frame.getMap().put(result[1], data);
                
            }
        }

        connection.cleanup();
        connection.close();
    }
}
