AOP.java Source code

Java tutorial

Introduction

Here is the source code for AOP.java

Source

import aop.controller.RequestController;
import aop.model.World;
import com.google.gson.Gson;
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.wrapper.ContainerController;
import jade.core.Runtime;
import jade.wrapper.StaleProxyException;
import java.awt.Point;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author John
 */
public class AOP {

    public static ContainerController mainContainer;
    public static Runtime rt;

    public static void main(String[] args) throws Exception {
        RequestController rc = new RequestController();

        rt = Runtime.instance();

        World world = new World();

        int prisonerCount = 8;
        String[] prisonerNames = { "Randy", "Stan", "Kyle", "Eric", "Kenny", "Chef", "Butters", "MrMackey" };

        createContainer();

        Random rand = new Random(System.currentTimeMillis());

        Gson gson = new Gson();
        String json = gson.toJson(world);
        rc.sendPostReq(0, json);

        try {
            for (int i = 0; i < prisonerCount; i++) {
                Object[] agentArgs = new Object[3];
                agentArgs[0] = world;
                agentArgs[1] = world.getRooms().get(0);
                agentArgs[2] = new Point(rand.nextInt(199), rand.nextInt(199));

                mainContainer.createNewAgent(prisonerNames[i], "aop.agents.Prisoner", agentArgs).start();
            }

        } catch (StaleProxyException ex) {
            Logger.getLogger(AOP.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void createContainer() {
        Profile profile = new ProfileImpl();
        profile.setParameter(Profile.PLATFORM_ID, "world");
        profile.setParameter(Profile.CONTAINER_NAME, "mainContainer");
        profile.setParameter(Profile.SERVICES, "jade.core.messaging.TopicManagementService");
        mainContainer = rt.createMainContainer(profile);
    }
}