package activemq;_x000D_
_x000D_
import algoritmes.ConcurrentMergeSort;_x000D_
import helper.CustomUtilities;_x000D_
import org.apache.activemq.ActiveMQConnectionFactory;_x000D_
_x000D_
import javax.jms.*;_x000D_
import java.util.ArrayList;_x000D_
import java.util.List;_x000D_
_x000D_
import static helper.Config.ACTIVEMQ_URL;_x000D_
_x000D_
/**_x000D_
 * Parallel Computing_x000D_
 * AUTHOR: R. Lobato & C. Verra_x000D_
 */_x000D_
public class Consumer {_x000D_
    private static String subject = "resultaat";_x000D_
_x000D_
    public static void main(String[] args) throws JMSException {_x000D_
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ACTIVEMQ_URL);_x000D_
        Connection connection = connectionFactory.createConnection();_x000D_
        connection.start();_x000D_
_x000D_
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);_x000D_
        Destination destination = session.createQueue(subject);_x000D_
        MessageConsumer consumer = session.createConsumer(destination);_x000D_
_x000D_
        int count = 0;_x000D_
_x000D_
        //	Lijst van Integers_x000D_
        List<Integer> list = new ArrayList<>();_x000D_
_x000D_
        while (true) {_x000D_
_x000D_
            Message message = consumer.receive();_x000D_
            if (message instanceof TextMessage) {_x000D_
                count++;_x000D_
                TextMessage textMessage = (TextMessage) message;_x000D_
_x000D_
                // String aan integers opslaan_x000D_
                String str = textMessage.getText();_x000D_
                //	String aan integers opsplitten_x000D_
                String[] integerStrings = str.split(" ");_x000D_
_x000D_
                //	Parse String Integers naar ints_x000D_
                for (String integerString : integerStrings) {_x000D_
                    int j = Integer.parseInt(integerString);_x000D_
                    //	Voeg toe aan list_x000D_
                    list.add(j);_x000D_
                }_x000D_
_x000D_
                //	Als het aantal lijsten gelijk is aan het aantal producers_x000D_
                if (count == Producer.NODES) {_x000D_
                    int[] array = list.stream().mapToInt(i -> i).toArray();_x000D_
                    //	Sorteer lijsten individueel_x000D_
                    ConcurrentMergeSort concurrentMergeSort = new ConcurrentMergeSort(array);_x000D_
                    concurrentMergeSort.sort();_x000D_
_x000D_
                    if (CustomUtilities.isArraySorted(array))_x000D_
                        break;_x000D_
                }_x000D_
            }_x000D_
        }_x000D_
_x000D_
        connection.close();_x000D_
    }_x000D_
}
//	Parse String Integers naar ints_x000D_
package activemq;_x000D_
_x000D_
import algoritmes.ConcurrentMergeSort;_x000D_
import helper.CustomUtilities;_x000D_
import org.apache.activemq.ActiveMQConnectionFactory;_x000D_
_x000D_
import javax.jms.*;_x000D_
import java.util.ArrayList;_x000D_
import java.util.List;_x000D_
_x000D_
import static helper.Config.ACTIVEMQ_URL;_x000D_
_x000D_
/**_x000D_
 * Parallel Computing_x000D_
 * AUTHOR: R. Lobato & C. Verra_x000D_
 */_x000D_
public class Consumer {_x000D_
    private static String subject = "resultaat";_x000D_
_x000D_
    public static void main(String[] args) throws JMSException {_x000D_
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ACTIVEMQ_URL);_x000D_
        Connection connection = connectionFactory.createConnection();_x000D_
        connection.start();_x000D_
_x000D_
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);_x000D_
        Destination destination = session.createQueue(subject);_x000D_
        MessageConsumer consumer = session.createConsumer(destination);_x000D_
_x000D_
        int count = 0;_x000D_
_x000D_
        //	Lijst van Integers_x000D_
        List<Integer> list = new ArrayList<>();_x000D_
_x000D_
        while (true) {_x000D_
_x000D_
            Message message = consumer.receive();_x000D_
            if (message instanceof TextMessage) {_x000D_
                count++;_x000D_
                TextMessage textMessage = (TextMessage) message;_x000D_
_x000D_
                // String aan integers opslaan_x000D_
                String str = textMessage.getText();_x000D_
                //	String aan integers opsplitten_x000D_
                String[] integerStrings = str.split(" ");_x000D_
_x000D_
                //	Parse String<SUF>
                for (String integerString : integerStrings) {_x000D_
                    int j = Integer.parseInt(integerString);_x000D_
                    //	Voeg toe aan list_x000D_
                    list.add(j);_x000D_
                }_x000D_
_x000D_
                //	Als het aantal lijsten gelijk is aan het aantal producers_x000D_
                if (count == Producer.NODES) {_x000D_
                    int[] array = list.stream().mapToInt(i -> i).toArray();_x000D_
                    //	Sorteer lijsten individueel_x000D_
                    ConcurrentMergeSort concurrentMergeSort = new ConcurrentMergeSort(array);_x000D_
                    concurrentMergeSort.sort();_x000D_
_x000D_
                    if (CustomUtilities.isArraySorted(array))_x000D_
                        break;_x000D_
                }_x000D_
            }_x000D_
        }_x000D_
_x000D_
        connection.close();_x000D_
    }_x000D_
}