Beispiel #1
0
  /**
   * Permet de trouver tous les agents en fonction d'un service
   *
   * @param service
   * @return tableau d'adresses d'agents
   */
  protected AID[] findAgentsFromService(String service) {
    DFAgentDescription dfd = new DFAgentDescription();
    ServiceDescription sd = new ServiceDescription();
    sd.setType(service);
    dfd.addServices(sd);

    SearchConstraints ALL = new SearchConstraints();
    ALL.setMaxResults(new Long(-1));

    AID[] agents = null;

    try {
      DFAgentDescription[] result = DFService.search(this, dfd, ALL);
      agents = new AID[result.length];

      for (int i = 0; i < result.length; i++) {
        agents[i] = result[i].getName();
      }

    } catch (FIPAException fe) {
      fe.printStackTrace();
    }

    return agents;
  }
Beispiel #2
0
  public void setup() {
    System.out.println("ASU.setup()");

    getContentManager().registerLanguage(codec);
    getContentManager().registerOntology(ontology);

    ACLMessage aclmsg = new ACLMessage(ACLMessage.REQUEST);
    AssignPowerRequest apr = new AssignPowerRequest();
    apr.setAssignedPower(100000);

    aclmsg.setLanguage(codec.getName());
    aclmsg.setOntology(ontology.getName());
    aclmsg.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
    aclmsg.setReplyByDate(new Date(System.currentTimeMillis() + 30000));

    AMSAgentDescription[] agents = null;
    try {
      SearchConstraints c = new SearchConstraints();
      c.setMaxResults(new Long(-1));

      agents = AMSService.search(this, new AMSAgentDescription(), c);
    } catch (Exception e) {
      System.out.println("Problem searching AMS: " + e);
      e.printStackTrace();
    }

    for (AMSAgentDescription agent : agents) {

      AID agentID = agent.getName();

      try {
        getContentManager().fillContent(aclmsg, new Action(agentID, apr));
      } catch (Exception e) {
        e.printStackTrace();
      }

      System.out.println(agentID.getLocalName());

      if (agentID.getLocalName().compareTo("TURBINE") != 0) continue;

      aclmsg.clearAllReceiver();
      aclmsg.addReceiver(agentID);

      System.out.println("Sending to " + agentID);

      addBehaviour(new ASURequestInitiatorBehaviour(this, aclmsg));

      try {
        Thread.yield();
        Thread.sleep(5000);
      } catch (Exception e) {
        System.out.println("INTERRUPT");
      }

      ACLMessage aclmsg2 = new ACLMessage(ACLMessage.REQUEST);
      BeginPowerTransitionRequest bptr = new BeginPowerTransitionRequest();
      bptr.setAssignedPowerValid(false);

      aclmsg2.setLanguage(codec.getName());
      aclmsg2.setOntology(ontology.getName());
      aclmsg2.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
      aclmsg2.setReplyByDate(new Date(System.currentTimeMillis() + 30000));

      try {
        getContentManager().fillContent(aclmsg2, new Action(agentID, bptr));
      } catch (Exception e) {
        e.printStackTrace();
      }

      aclmsg2.clearAllReceiver();
      aclmsg2.addReceiver(agentID);

      System.out.println("Sending to " + agentID);

      addBehaviour(new ASURequestInitiatorBehaviour(this, aclmsg2));
    }
  }