Esempio n. 1
0
  /**
   * create the monitoring agents (rma+sniffer) on the main-container given in parameter and launch
   * them. - RMA agent's is used to debug and monitor the platform; - Sniffer agent is used to
   * monitor communications
   *
   * @param mc the main-container's reference
   * @return a ref to the sniffeur agent
   */
  private static void createMonitoringAgents(ContainerController mc) {

    System.out.println("Launching the rma agent on the main container ...");
    AgentController rma;

    try {
      rma = mc.createNewAgent("rma", "jade.tools.rma.rma", new Object[0]);
      rma.start();
    } catch (StaleProxyException e) {
      e.printStackTrace();
      System.out.println("Launching of rma agent failed");
    }

    System.out.println("Launching  Sniffer agent on the main container...");
    AgentController snif = null;

    try {
      snif = mc.createNewAgent("sniffeur", "jade.tools.sniffer.Sniffer", new Object[0]);
      snif.start();

    } catch (StaleProxyException e) {
      e.printStackTrace();
      System.out.println("launching of sniffer agent failed");
    }
  }
Esempio n. 2
0
 private void createQueenAgents(int nQueens) {
   log.info("Create number of " + nQueens + " Queen Agents");
   ContainerController containerController = getContainerController();
   try {
     for (int i = 1; i <= nQueens; i++) {
       containerController
           .createNewAgent("Queen" + i, XQueen.class.getName(), new Object[] {i, nQueens})
           .start();
     }
   } catch (StaleProxyException e) {
     log.severe(e.getMessage());
   }
 }
Esempio n. 3
0
  /**
   * Start the agents
   *
   * @param agentList
   */
  private static void startAgents(List<AgentController> agentList) {

    System.out.println("Starting agents...");

    for (final AgentController ac : agentList) {
      try {
        ac.start();
      } catch (StaleProxyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    System.out.println("Agents started...");
  }
Esempio n. 4
0
 public Seller(
     String name,
     Product product,
     ContainerController containerController,
     String strategy,
     BigDecimal decrement,
     BigDecimal minPrice) {
   this.name = name;
   this.product = product;
   this.minPrice = minPrice;
   this.strategy = strategy;
   this.decrement = decrement;
   try {
     this.createAgent(containerController);
   } catch (StaleProxyException e) {
     e.printStackTrace();
   }
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      nickname = extras.getString("nickname");
    }

    try {
      chatClientInterface =
          MicroRuntime.getAgent(nickname).getO2AInterface(ChatClientInterface.class);
    } catch (StaleProxyException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ControllerException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    myReceiver = new MyReceiver();

    IntentFilter refreshParticipantsFilter = new IntentFilter();
    refreshParticipantsFilter.addAction("jade.demo.chat.REFRESH_PARTICIPANTS");
    registerReceiver(myReceiver, refreshParticipantsFilter);

    setContentView(R.layout.participants);

    setListAdapter(
        new ArrayAdapter<String>(
            this, R.layout.participant, chatClientInterface.getParticipantNames()));

    ListView listView = getListView();
    listView.setTextFilterEnabled(true);
    listView.setOnItemClickListener(listViewtListener);
  }
  @Override
  public void action() {
    ACLMessage message = myAgent.receive(template);
    if (message != null) {
      ACLMessage answer = null;

      JsonParser js = new JsonParser();
      int action =
          ((JsonObject) js.parse(message.getContent())).get(Constants.JSON_ACTION).getAsInt();

      // si MESSAGE_ACTION_GET_CONTENT renvoie le contenu en envoyant au client un message
      // MESSAGE_RECEIVE_ELEMENT_TITLE

      switch (action) {
        case Constants.MESSAGE_ACTION_CREATE_ELEMENT:
          AgentController newElement;
          try {
            AgentContainer controller = myAgent.getContainerController();
            Date dNow = new Date();
            SimpleDateFormat ft = new SimpleDateFormat("hh:mm:ss");

            newElement =
                controller.createNewAgent(
                    "Nouvel element : " + ft.format(dNow),
                    "com.workhub.jade.agent.ElementAgent",
                    new Object[] {MessageFactory.getAgentType(message), message.getSender()});
            newElement.start();
          } catch (StaleProxyException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
      }
    } else {
      block();
    }
  }
Esempio n. 7
0
  /**
   * Creates the agents and add them to the agentList. agents are NOT started.
   *
   * @param containerList :Name and container's ref
   * @param sniff : a ref to the sniffeur agent
   * @return the agentList
   */
  private static List<AgentController> createAgents(
      HashMap<String, ContainerController> containerList) {
    System.out.println("Launching agents...");
    ContainerController c;
    String agentName;
    List<AgentController> agentList = new ArrayList<AgentController>();

    // wumpus on container0
    c = containerList.get("container0");
    agentName = "Golem";
    try {
      Object[] objtab = new Object[] {env}; // used to give informations to the agent
      AgentController ag =
          c.createNewAgent(agentName, mas.agents.GolemAgent.class.getName(), objtab);
      agentList.add(ag);
      System.out.println(agentName + " launched");
    } catch (StaleProxyException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // wumpus on container0
    //		c = containerList.get("container0");
    //		agentName="Wumpus1";
    //		try {
    //
    //
    //			Object[] objtab=new Object[]{env,agentName};//used to give informations to the agent
    //			AgentController	ag=c.createNewAgent(agentName,DummyWumpusAgent.class.getName(),objtab);
    //			agentList.add(ag);
    //			System.out.println(agentName+" launched");
    //		} catch (StaleProxyException e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //		}

    //		agentName="Wumpus2";
    //		try {
    //
    //
    //			Object[] objtab=new Object[]{env,agentName};//used to give informations to the agent
    //			AgentController	ag=c.createNewAgent(agentName,DummyAgentWumpus.class.getName(),objtab);
    //			agentList.add(ag);
    //			System.out.println(agentName+" launched");
    //		} catch (StaleProxyException e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //		}
    //
    //		//wumpus on container0
    //		c = containerList.get("container0");
    //		agentName="Wumpus3";
    //		try {
    //
    //
    //			Object[] objtab=new Object[]{env,agentName};//used to give informations to the agent
    //			AgentController	ag=c.createNewAgent(agentName,DummyAgentWumpus.class.getName(),objtab);
    //			agentList.add(ag);
    //			System.out.println(agentName+" launched");
    //		} catch (StaleProxyException e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //		}
    //
    //
    // Agent0 on container0
    c = containerList.get("container0");
    agentName = "Explo1";
    try {

      Object[] objtab = new Object[] {env}; // used to give informations to the agent
      AgentController ag = c.createNewAgent(agentName, DummyExploAgent.class.getName(), objtab);
      agentList.add(ag);
      System.out.println(agentName + " launched");
    } catch (StaleProxyException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //
    ////

    c = containerList.get("container0");
    agentName = "Explo2";
    try {

      Object[] objtab = new Object[] {env}; // used to give informations to the agent
      AgentController ag = c.createNewAgent(agentName, DummyExploAgent.class.getName(), objtab);
      agentList.add(ag);
      System.out.println(agentName + " launched");
    } catch (StaleProxyException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    c = containerList.get("container0");
    agentName = "Explo3";
    try {

      Object[] objtab = new Object[] {env}; // used to give informations to the agent
      AgentController ag = c.createNewAgent(agentName, DummyExploAgent.class.getName(), objtab);
      agentList.add(ag);
      System.out.println(agentName + " launched");
    } catch (StaleProxyException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    /*
    		c = containerList.get("container0");
    		agentName="Explo4";
    		try {


    			Object[] objtab=new Object[]{env};//used to give informations to the agent
    			AgentController	ag=c.createNewAgent(agentName,DummyExploAgent.class.getName(),objtab);
    			agentList.add(ag);
    			System.out.println(agentName+" launched");
    		} catch (StaleProxyException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}

    		c = containerList.get("container0");
    		agentName="Explo5";
    		try {


    			Object[] objtab=new Object[]{env};//used to give informations to the agent
    			AgentController	ag=c.createNewAgent(agentName,DummyExploAgent.class.getName(),objtab);
    			agentList.add(ag);
    			System.out.println(agentName+" launched");
    		} catch (StaleProxyException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}

    		c = containerList.get("container0");
    		agentName="Explo6";
    		try {


    			Object[] objtab=new Object[]{env};//used to give informations to the agent
    			AgentController	ag=c.createNewAgent(agentName,DummyExploAgent.class.getName(),objtab);
    			agentList.add(ag);
    			System.out.println(agentName+" launched");
    		} catch (StaleProxyException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}


    		c = containerList.get("container0");
    		agentName="Explo7";
    		try {

    			Object[] objtab=new Object[]{env};//used to give informations to the agent
    			AgentController	ag=c.createNewAgent(agentName,DummyExploAgent.class.getName(),objtab);
    			agentList.add(ag);
    			System.out.println(agentName+" launched");
    		} catch (StaleProxyException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    //
    ////

    		c = containerList.get("container0");
    		agentName="Explo8";
    		try {


    			Object[] objtab=new Object[]{env};//used to give informations to the agent
    			AgentController	ag=c.createNewAgent(agentName,DummyExploAgent.class.getName(),objtab);
    			agentList.add(ag);
    			System.out.println(agentName+" launched");
    		} catch (StaleProxyException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}


    		c = containerList.get("container0");
    		agentName="Explo9";
    		try {


    			Object[] objtab=new Object[]{env};//used to give informations to the agent
    			AgentController	ag=c.createNewAgent(agentName,DummyExploAgent.class.getName(),objtab);
    			agentList.add(ag);
    			System.out.println(agentName+" launched");
    		} catch (StaleProxyException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}

    		c = containerList.get("container0");
    		agentName="Explo10";
    		try {


    			Object[] objtab=new Object[]{env};//used to give informations to the agent
    			AgentController	ag=c.createNewAgent(agentName,DummyExploAgent.class.getName(),objtab);
    			agentList.add(ag);
    			System.out.println(agentName+" launched");
    		} catch (StaleProxyException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}

    		c = containerList.get("container0");
    		agentName="Explo11";
    		try {


    			Object[] objtab=new Object[]{env};//used to give informations to the agent
    			AgentController	ag=c.createNewAgent(agentName,DummyExploAgent.class.getName(),objtab);
    			agentList.add(ag);
    			System.out.println(agentName+" launched");
    		} catch (StaleProxyException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}

    		c = containerList.get("container0");
    		agentName="Explo12";
    		try {


    			Object[] objtab=new Object[]{env};//used to give informations to the agent
    			AgentController	ag=c.createNewAgent(agentName,DummyExploAgent.class.getName(),objtab);
    			agentList.add(ag);
    			System.out.println(agentName+" launched");
    		} catch (StaleProxyException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		*/
    /*
     */

    System.out.println("Agents launched...");
    return agentList;
  }