/** * from: Luis Lezcano Airaldi <*****@*****.**> to: [email protected] date: Sat, * Jun 7, 2014 at 3:10 PM * * <p>Hello! It's very easy to use Jade as a library. Here's an example from a small application I * made: */ public void testJade1() { // This is the important method. This launches the jade platform. final Runtime rt = Runtime.instance(); final Profile profile = new ProfileImpl(); // With the Profile you can set some options for the container profile.setParameter(Profile.PLATFORM_ID, "Platform Name"); profile.setParameter(Profile.CONTAINER_NAME, "Container Name"); // Create the Main Container final AgentContainer mainContainer = rt.createMainContainer(profile); final String agentName = "manager"; final String agentType = "ia.main.AgentManager"; // FIXME final Object[] agentArgs = {}; try { // Here I create an agent in the main container and start it. final AgentController ac = mainContainer.createNewAgent(agentName, agentType, agentArgs); ac.start(); } catch (final StaleProxyException e) { LOG.error( String.format( "Problem creating/starting Jade agent '%s'" + " of type: %s with args: %s", agentName, agentType, Arrays.asList(agentArgs)), e); } }
public Environment(String name, String host, String port) { this.name = name; this.host = host; this.port = port; try { Runtime runtime = Runtime.instance(); profile = new ProfileImpl(host, Integer.valueOf(port), name); mainConteiner = runtime.createMainContainer(profile); AgentController rma = mainConteiner.createNewAgent("rma", "jade.tools.rma.rma", new Object[0]); rma.start(); } catch (ControllerException exception) { exception.printStackTrace(); } }
/** * Create an empty platform composed of 1 main container and 3 containers. * * @return a ref to the platform and update the containerList */ private static Runtime emptyPlatform(HashMap<String, ContainerController> containerList) { Runtime rt = Runtime.instance(); // 1) create a platform (main container+DF+AMS) Profile pMain = new ProfileImpl(hostname, 8888, null); System.out.println("Launching a main-container..." + pMain); AgentContainer mainContainerRef = rt.createMainContainer(pMain); // DF and AMS are include // 2) create the containers containerList.putAll(createContainers(rt)); // 3) create monitoring agents : rma agent, used to debug and monitor the platform; sniffer // agent, to monitor communications; createMonitoringAgents(mainContainerRef); System.out.println("Plaform ok"); return rt; }
public void init(Properties params, AServProtocolManager manager) throws AServException { int port = 8888; Object args[] = new Object[2]; // set up the manager as an argument to pass to the JADEFIPAAServiceAgent args[0] = manager; // set up the Parameters as an argument to pass to the JADEFIPAServiceAgent args[1] = params; if (params.getProperty("jade") != null) port = Integer.parseInt(params.getProperty("jade")); // Properties props = new Properties(); try { // Get a hold on JADE runtime Runtime rt = Runtime.instance(); // Exit the JVM when there are no more containers around rt.setCloseVM(true); /** * Profile with no MTP( Message Transfer Protocol props.setProperty("nomtp", "true"); Profile * pMain = new ProfileImpl(props); */ // create a default Profile Profile pMain = new ProfileImpl(null, port, null); // logger.trace( "Launching a whole in-process platform... {}", pMain ); mc = rt.createMainContainer(pMain); algagentcontroller = mc.createNewAgent("JadeFIPAAServiceAgent", JadeFIPAAServiceAgent.class.getName(), args); algagentcontroller.start(); } catch (Exception ex) { throw new AServException("Cannot launch Jade Server", ex); } }
public void startContainer() throws SlickException { // ----------JADE start // Get a hold of JADE runtime Runtime runtime = Runtime.instance(); // Create a default profile ProfileImpl profile = new ProfileImpl(); // Create a new non-main container, connecting to the default // main container (i.e. on this host, port 1099) ContainerController cc = runtime.createMainContainer(profile); AgentController rma = null; AgentController player1 = null; AgentController player2 = null; AgentController player3 = null; AgentController player4 = null; ArrayList<AgentController> landmarks = new ArrayList<AgentController>(); Object[] arguments = new Object[3]; arguments[0] = this.map; arguments[1] = "team1-luffy"; arguments[2] = map.getAvatars().get(1); Object[] argumentsChief = new Object[3]; argumentsChief[0] = this.map; argumentsChief[1] = "team1-luffy"; argumentsChief[2] = map.getAvatars().get(0); Object[] arguments2 = new Object[3]; arguments2[0] = this.map; arguments2[1] = "team2-roronoa"; arguments2[2] = map.getAvatars().get(2); Object[] argumentsChief2 = new Object[3]; argumentsChief2[0] = this.map; argumentsChief2[1] = "team2-roronoa"; argumentsChief2[2] = map.getAvatars().get(3); try { rma = cc.createNewAgent("rma", "jade.tools.rma.rma", null); player1 = cc.createNewAgent( ((Avatar) arguments[2]).getName(), "agents.TickerExplorerRandomPlayer", arguments); player2 = cc.createNewAgent( ((Avatar) arguments2[2]).getName(), "agents.TickerExplorerRandomPlayer", arguments2); player3 = cc.createNewAgent( "Chiefteam1-luffy", "agents.TickerExplorerRandomPlayer", argumentsChief); player4 = cc.createNewAgent( "Chiefteam2-roronoa", "agents.TickerExplorerRandomPlayer", argumentsChief2); for (int i = 0; i < map.getLandmarks().size(); i++) { Object[] landmarkArgs = new Object[4]; landmarkArgs[0] = "Landmark" + i; landmarkArgs[1] = this.map; landmarkArgs[2] = map.getLandmarks().get(i); landmarkArgs[3] = map.getLandmarks().get(i).getMessage(); landmarks.add( cc.createNewAgent( map.getLandmarks().get(i).getName(), "agents.LandmarkAgent", landmarkArgs)); } System.out.println("Agent created \n"); } catch (StaleProxyException ex) { System.out.println("here is problem"); } try { // rma.start(); player1.start(); player2.start(); player3.start(); player4.start(); for (int i = 0; i < map.getLandmarks().size(); i++) { landmarks.get(i).start(); } System.out.println("Agent started \n"); } catch (StaleProxyException ex) { System.out.println("Stale Proxy pointer ex"); } catch (NullPointerException ex) { System.out.println("Null pointer ex"); ex.printStackTrace(); } // //----------JADE end }