/* Glavni Agent
 */
package Project5;

import COM.meitca.concordia.CollaboratorAgent;
import COM.meitca.concordia.*;
import COM.meitca.concordia.collaborate.*;
import COM.meitca.concordia.event.*;


public class main {

    public static void main(String args[]) {
        try {

            // Retrieve the agent's destination and codebase from the
            // System properties.  These values are set up by the
            // batch or script file that launches the example.
            String destination = System.getProperty("concordia.ex.destination");
            String home = System.getProperty("concordia.ex.home");

            if (destination == null)
                destination = "localhost";


            System.out.println("Launching FetchingAgents "+ home);

            // Create an AgentGroup.  An AgentGroup acts as focal point
            // for collaboration between agents and for group oriented
            // events
            AgentGroupImpl          agentGroup = new AgentGroupImpl();

            // Create and launch the FetchingAgents. Notice that we pass
            // a reference to the AgentGroup into the constructor for the
            // agent.  This allows the agent to join the group.
            FetchingAgent	agent = new FetchingAgent(agentGroup);
            Itinerary	itinerary = new Itinerary();

            itinerary.addDestination(new Destination(destination, "run"));
    		agent.setItinerary(itinerary);
    		agent.setHomeCodebaseURL(home);
            agent.launch();


            System.out.println("Launching Monitor");

            // Create and launch the Monitor.
            Monitor            postAgent = new Monitor(agentGroup);
            //Itinerary               itinerary3 = new Itinerary();

            //itinerary3.addDestination(new Destination(destination, "run"));
    		//postAgent.setItinerary(itinerary3);
    		postAgent.setHomeCodebaseURL(home);
            //postAgent.launch();
			postAgent.run();

            System.out.println("Agents launched.");

            // Wait a while for the example to complete
            /*
			try {
                Thread.currentThread().sleep(50000);
            } catch (InterruptedException e) {}
			*/
            System.out.println("main done.");
            System.exit(0);

        } catch (Exception e) {
            System.err.println("Error during example: " + e);
            e.printStackTrace(System.err);
        }
    }
}