/*
 * TestClientAPI.java
 *
 * Created on 25 marzo 2004, 15.59
 */

package test;
import qms.client.*;
import qms.messages.*;
import java.net.*;
import java.io.*;
import java.util.*;
/**
 *
 * @author  Enrico
 */
public class TestBi {
            
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            String queue1 = "coda5";            
            URL sap1 = new URL("http://localhost/node1/UserInterface");
            String body1 = "ciao a tutti!";
            System.out.println("Service Access Point "+sap1);
            System.out.println("Queue:"+queue1);            
            
            QMSClient client1 = new QMSClient();
            client1.setAccessPoint(sap1);                     
            
            
            String queue2 = "coda6";            
            URL sap2 = new URL("http://localhost/node2/UserInterface");
            String body2 = "ciao a tutti!";
            System.out.println("Service Access Point "+sap2);
            System.out.println("Queue:"+queue2);            
            
            QMSClient client2 = new QMSClient();
            client2.setAccessPoint(sap2);                     
            
            
                        
            System.out.println("Posting messages");            
            
            for (int i=0; i < 100; i++) {
                if ((i % 2) == 0) {
                    client1.postMessage("enrico", queue1, body1+" "+i);                                 
                    System.out.println("Sent "+i);
                } else {
                    client2.postMessage("enrico", queue2, body2+" "+i);                                 
                    System.out.println("Sent "+i);
                }
            }
             
            
           /* System.out.println("Waiting...");
            Thread.sleep(10000);
            
            List list = client.listMessages(queue);
            System.out.println("Message ids:"+list);
            
            for (Iterator i = list.iterator(); i.hasNext();) {
                String mid = (String) i.next();
                Message m = client.getMessage(queue, mid);
                System.out.println("Message:\n"+m);
                System.out.println("Deleting...");
                client.deleteMessage(queue,mid);
                System.out.println("OK");
            }
            */
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    
}
