Exemplo n.º 1
0
  private void downloadDocument() {

    final DownloadRequest request = new DownloadRequest(doc);
    ACLMessage message = new ACLMessage(ACLMessage.REQUEST);
    message.addReceiver(this.dest);
    message.setContent(request.toJSON());
    this.myAgent.send(message);

    final ACLMessage answer = this.myAgent.blockingReceive();

    final ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);

    BinaryContent res = null;
    try {
      //			System.out.println("Sessions reçues :"+answer.getContent());
      res = mapper.readValue(answer.getContent(), BinaryContent.class);
    } catch (IOException e) {
      e.printStackTrace();
    }

    final String path =
        RequestConstants.clientAgentDirectory + this.doc.getName() + this.doc.getType();
    FileOutputStream fos;
    try {
      fos = new FileOutputStream(path);
      fos.write(res.getContent());
      fos.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
    @Override
    protected void onTick() { // every 1000 ms
      if (awaitingRelease == false) {
        if (moveMentQueue.size() == 0) // agent has no pending movement
        {
          if (travelPoints.size() != 0) // if there are actually points
          // to visit
          {
            movementVerified = false;
            calculateNextHop();
            try {
              Thread.sleep(2);
            } catch (InterruptedException e) {
              e.printStackTrace(); // wait a small while to receive
              // a reply to the hop claim
            }
          }
        }

        if (moveMentQueue.size() > 0 && movementVerified) {
          String conversationString = "";
          String statusID = "V"; // holding item
          if (holdingItem.x == 0) // not holding item
          {
            statusID = "R";
          }
          if (claimDropdownID == true) {
            statusID = "D";
            claimDropdownID = false;
          }
          if (nextDestination.get(0) == ITEMDROPDOWN
              && moveMentQueue.get(0).x == holdingItem.x
              && moveMentQueue.get(0).y == holdingItem.y) {
            claimDropdownID = true;
          }
          conversationString += (statusID + ",");
          conversationString += (location.x + ",");
          conversationString += (location.y + ",");
          conversationString += (moveMentQueue.get(0).x + ",");
          conversationString += moveMentQueue.get(0).y;
          location = moveMentQueue.get(0);
          moveMentQueue.remove(0);
          if (location.x == travelPoints.get(0).x && location.y == travelPoints.get(0).y) {
            checkArrival();
          }
          ACLMessage mapUpd = new ACLMessage(ACLMessage.INFORM);
          mapUpd.addReceiver(guiAgents[0]); // The gui agent needs to
          // know that the robot
          // actually did a move

          mapUpd.setContent(conversationString); // x,y is for the
          // GUI agent, it
          // has to
          // visualize
          // movement
          mapUpd.setConversationId("map-update");
          myAgent.send(mapUpd);
        }
      }
    }
Exemplo n.º 3
0
  @Override
  public void action() {
    ACLMessage message = new ACLMessage(ACLMessage.REQUEST);
    System.out.println(" ----- SendFileToServerBehaviour started ----- ");

    try {
      jO = new JSONObject();
      jO.put("action", "ADD");
      jO.put("login", LoginActivity.USER_LOGIN);
      jO.put("project_name", ProjectsFragment.PROJECT_NAME);
      jO.put("project_id", ProjectsFragment.PROJECT_NAME);
      jO.put("session_id", SessionsFragment.SESSION_NAME);
      jO.put("file_name", AddFileActivity.FILE_NAME);
      jO.put("file", AddFileActivity.FILE_TO_STRING);

      message.setContent(jO.toString());
      System.out.println(" jO messageToserver= " + jO);

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    message.addReceiver(clientAgent.searchServer());
    myAgent.send(message);
  }
Exemplo n.º 4
0
  private void proposeMove(String queenName) {
    DFAgentDescription template = new DFAgentDescription();
    ServiceDescription sd = new ServiceDescription();
    sd.setType("Publish-queen");
    template.addServices(sd);

    try {
      DFAgentDescription[] result = DFService.search(this, template);
      if (result != null && result.length > 0) {
        ACLMessage msg = new ACLMessage(ACLMessage.PROPOSE);
        for (int i = 0; i < result.length; ++i) {
          if (result[i].getName().getLocalName().equals(queenName)) {
            msg.addReceiver(result[i].getName());
          }
        }

        msg.setContent(ChessCommand.MOVE);
        send(msg);

      } else {
        log.severe("Queen is not registred or not available");
      }

    } catch (FIPAException e) {
      log.severe(e.getMessage());
    }
  }
Exemplo n.º 5
0
 // #APIDOC_EXCLUDE_BEGIN
 public static void notifyFailureToSender(ACLMessage msg, String sender, String error) {
   if (myFrontEnd != null) {
     // Send back a failure message
     try {
       Iterator it = msg.getAllReceiver();
       while (it.hasNext()) {
         AID receiver = (AID) it.next();
         // If this receiver is local, the message has certainly been delivered
         // successfully --> Do not send any FAILURE back for this receiver
         if (myFrontEnd.getLocalAgent(receiver.getLocalName()) == null) {
           ACLMessage failure = msg.createReply();
           failure.setPerformative(ACLMessage.FAILURE);
           failure.setSender(myFrontEnd.getAMS());
           failure.setLanguage(FIPANames.ContentLanguage.FIPA_SL);
           String content = "( (action " + sender;
           content = content + " (ACLMessage) ) (MTS-error " + receiver + " \"" + error + "\") )";
           failure.setContent(content);
           myFrontEnd.messageIn(failure, sender);
         }
       }
     } catch (Exception e1) {
       logger.log(Logger.SEVERE, "Error delivering FAILURE message.", e1);
     }
   }
 }
Exemplo n.º 6
0
    public void action() { // request the map from the GuiAgent
      // updateGuiAgents();
      // System.out.println("I did a one shot map request");//debugging
      // purpose
      ACLMessage mapReq = new ACLMessage(ACLMessage.QUERY_IF);

      mapReq.addReceiver(guiAgents[0]);
      if (wantsCleanMap) {
        mapReq.setContent("Give me map, clean");
      } else {
        mapReq.setContent("Give me map");
      }
      mapReq.setConversationId("map-request");
      myAgent.send(mapReq);

      done();
    }
Exemplo n.º 7
0
    public void action() { // listen to incomming CFP from storageAgents

      MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.CFP);
      ACLMessage msg = myAgent.receive(mt);

      /*System.out.println("REQUEST RECEIVED");
      System.out.println(msg);*/
      if (msg != null) { // only respond to CFP messages
        // CFP Message received. Process it
        // System.out.println("Got request");
        String requestedLocation = msg.getContent();
        ACLMessage reply = msg.createReply(); // add the sender as
        // recipient
        Integer x =
            Integer.parseInt(
                requestedLocation.substring(
                    0, requestedLocation.lastIndexOf(','))); // parse the x of
        // product
        Integer y =
            Integer.parseInt(
                requestedLocation.substring(
                    requestedLocation.lastIndexOf(',') + 1,
                    requestedLocation.length())); // parse the y of product
        Integer price = calculatePathCost(new Point(x, y));
        if (holdingItem.x == x && holdingItem.y == y) { // robot is
          // carrying the
          // requested
          // item
          price = 1;
        }
        if (price != null) {
          reply.setPerformative(ACLMessage.PROPOSE);
          reply.setContent(String.valueOf(price.intValue()));
          // System.out.println(getAID().getName() + ": My cost is " +
          // price + ". To get to location: " +x + ","+y);//debugging
          // purpose
        } else {
          reply.setPerformative(ACLMessage.REFUSE);
          reply.setContent("Pathplanning error");
        }
        myAgent.send(reply);
      } else {
        block();
      }
    }
  @Override
  public int onEnd() {
    // send to the seller. request was firstly sent by him
    ACLMessage reply = request.createReply();
    reply.setContent("the winner is:");
    reply.setPerformative(ACLMessage.INFORM); // depending if it is failure or ...
    myAgent.send(reply);

    return 0;
  }
 private ACLMessage createMessageToDevices(String content, String conversationId) {
   ACLMessage message = new ACLMessage(ACLMessage.INFORM);
   for (AID destinataire : addDevicesRecivers()) {
     message.addReceiver(destinataire);
   }
   // Ajout du contenu du message.
   message.setConversationId(conversationId);
   message.setContent(content);
   return message;
 }
 @Override
 public void action() {
   ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
   msg.setLanguage("myLanguage");
   msg.setContent("olá");
   msg.addReceiver(new AID("rma#localhost:1099/JADE", false));
   send(msg);
   System.out.println("Agente: " + getAID().getName() + " - Mensagem enviada");
   doDelete();
 }
Exemplo n.º 11
0
 void enviarMensaje(String mensaje) {
   ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
   for (int i = 0; i < m_AidListaMensajeros.size(); i++) {
     msg.addReceiver(m_AidListaMensajeros.elementAt(i));
   }
   msg.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
   msg.setConversationId("MS");
   msg.setContent(mensaje);
   send(msg);
   System.out.println(getLocalName() + ": Ha enviado un mensaje: " + mensaje);
 }
Exemplo n.º 12
0
    public void action() { // request the map from the GuiAgent
      updateGuiAgents();
      // System.out.println("I did a one shot map request");//debugging
      // purpose
      ACLMessage mapReq = new ACLMessage(ACLMessage.QUERY_IF);

      mapReq.addReceiver(guiAgents[0]);
      mapReq.setContent("Give me map");
      mapReq.setConversationId("map-request");
      myAgent.send(mapReq);

      ACLMessage mapUpd = new ACLMessage(ACLMessage.INFORM);
      mapUpd.addReceiver(guiAgents[0]); // The gui agent needs to know
      // where the agent is
      // initialized
      mapUpd.setContent("R,26,1" + "," + location.x + "," + location.y); // put the agent on
      // the map
      mapUpd.setConversationId("map-update");
      myAgent.send(mapUpd);
      done();
    }
 protected void nuevoMensaje(String destinatario, String contenido) {
   // Realizamos las acciones necesarias cada cierto tiempo
   // Construye mensaje de tipo INFORM
   ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
   // agrega contenido
   // String contenido = generaCoordenadas();
   msg.setContent(contenido);
   // agrega la direccion del destinatario
   msg.addReceiver(new AID(destinatario, AID.ISLOCALNAME));
   // envia mensaje
   myAgent.send(msg);
 }
  @Override
  public void action() {
    ACLMessage message = new ACLMessage(ACLMessage.REQUEST);
    message.setContent(writeMessage());
    message.setConversationId(conversationId);
    message.addReceiver(getSynchroAgent());
    // Envoi de message vers Sync
    myAgent.send(message);

    // Création du behaviour qui va attendre la réponse de la synchronisation
    myAgent.addBehaviour(new ServerWaitingSynchronistBehaviour(conversationId, user));
  }
Exemplo n.º 15
0
    @Override
    public void action() {
      //			System.out.println(getName() + ": state=Handle_CFP");
      informed = false;
      MessageTemplate template_cfp = MessageTemplate.MatchPerformative(ACLMessage.CFP);
      MessageTemplate template_nobids = MessageTemplate.MatchContent("no-bids");
      ACLMessage cfp = receive(template_cfp);
      ACLMessage nobids = receive(template_nobids);
      if (cfp != null && cfp.getConversationId().equals(convID)) { // CFP received
        try {
          receivedItem = (Artifact) cfp.getContentObject();
          // System.out.println(getName() + ": Received CFP - " + receivedItem.getName());
          ACLMessage proposal = new ACLMessage(ACLMessage.PROPOSE);
          proposal.addReceiver(marketAgent);
          proposal.setConversationId(convID);

          if (acceptOffer(receivedItem)) proposal.setContent("yes");
          else proposal.setContent("no");
          send(proposal);
          // System.out.println(getName() + ": Proposal sent to Auctioneer. Proposal= " +
          // proposal.getContent());
        } catch (UnreadableException e) {
          ACLMessage notUnderstood = new ACLMessage(ACLMessage.NOT_UNDERSTOOD);
          notUnderstood.addReceiver(marketAgent);
          notUnderstood.setConversationId(convID);
          send(notUnderstood);
        }

        informed = true;
        status = CFP_RECEIVED;
      } else if (nobids != null && nobids.getConversationId().equals(convID)) {
        // System.out.println(getName() + ": No-bids received...");
        informed = true;
        status = NO_BIDS;
      } else block();
    }
Exemplo n.º 16
0
  public void action() {
    buySideOrders.addAll(MarketAgent.buySideQueue);
    Collections.sort(buySideOrders);
    sellSideOrders.addAll(MarketAgent.sellSideQueue);
    Collections.sort(sellSideOrders);

    System.out.println(myAgent.getLocalName() + " LocalBuyOrders: " + buySideOrders.size());
    System.out.println(myAgent.getLocalName() + " LocalSellOrders: " + sellSideOrders.size());

    ACLMessage tradingRequestMsg = new ACLMessage(ACLMessage.REQUEST);
    tradingRequestMsg.setConversationId("TradingRequest");
    tradingRequestMsg.setContent("ReadyToStart");
    tradingRequestMsg.addReceiver(MarketAgent.marketAID);
    myAgent.send(tradingRequestMsg);
  }
Exemplo n.º 17
0
  /**
   * Request for medicine.
   *
   * <p>This method sends a <b> FIPA REQUEST </b> message to all agents who offers the <tt>
   * m_sMedicService </tt> service.
   *
   * <p>The content of message is: <tt> ( x , y , z ) ( health ) </tt>.
   *
   * <p>Variable <tt> m_iMedicsCount </tt> is updated.
   *
   * <p><em> It's very useful to overload this method. </em>
   */
  protected void CallForMedic() {

    try {

      DFAgentDescription dfd = new DFAgentDescription();
      ServiceDescription sd = new ServiceDescription();
      sd.setType(m_sMedicService);
      dfd.addServices(sd);
      DFAgentDescription[] result = DFService.search(this, dfd);

      if (result.length > 0) {

        m_iMedicsCount = result.length;

        // Fill the REQUEST message
        ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);

        for (int i = 0; i < result.length; i++) {

          DFAgentDescription dfdMedic = result[i];
          AID Medic = dfdMedic.getName();
          if (!Medic.equals(getName())) msg.addReceiver(dfdMedic.getName());
          else m_iMedicsCount--;
        }
        msg.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
        msg.setConversationId("CFM");
        msg.setContent(
            " ( "
                + m_Movement.getPosition().x
                + " , "
                + m_Movement.getPosition().y
                + " , "
                + m_Movement.getPosition().z
                + " ) ( "
                + GetHealth()
                + " ) ");
        send(msg);
        System.out.println(getLocalName() + ": Need a Medic! (v21)");

      } else {
        m_iMedicsCount = 0;
      }
    } catch (FIPAException fe) {
      fe.printStackTrace();
    }
  }
Exemplo n.º 18
0
 protected void handleServingFailure(Throwable t, Object cel, ACLMessage msg) {
   myLogger.log(
       Logger.SEVERE,
       "Agent "
           + myAgent.getName()
           + " - Unexpected error serving content-element "
           + cel.getClass().getName()
           + ". Sender is "
           + msg.getSender().getName(),
       t);
   if (performativesRequiringReply.contains(msg.getPerformative())) {
     ACLMessage reply = msg.createReply();
     reply.setPerformative(ACLMessage.FAILURE);
     reply.setContent("((" + ExceptionVocabulary.INTERNALERROR + " \"" + t + "\"))");
     myAgent.send(reply);
   }
 }
Exemplo n.º 19
0
 protected void handleUnsupported(Object keyCel, ACLMessage msg) {
   myLogger.log(
       Logger.WARNING,
       "Agent "
           + myAgent.getName()
           + " - Unsupported content-element "
           + keyCel.getClass().getName()
           + ". Sender is "
           + msg.getSender().getName());
   if (performativesRequiringReply.contains(msg.getPerformative())) {
     ACLMessage reply = msg.createReply();
     reply.setPerformative(ACLMessage.REFUSE);
     reply.setContent(
         "((" + ExceptionVocabulary.UNSUPPORTEDACT + " " + keyCel.getClass().getName() + "))");
     myAgent.send(reply);
   }
 }
Exemplo n.º 20
0
    public void action() { // send a message with current coords, the storage
      // agent knows it s own coords so it can be
      // verified where the agent is
      updateStorageAgents();
      // System.out.println("Sent arrival message");
      ACLMessage arrMsg = new ACLMessage(ACLMessage.INFORM);
      updateStorageAgents();

      for (int i = 0; i < storageAgents.length; ++i) {
        arrMsg.addReceiver(storageAgents[i]);
      }

      arrMsg.setContent(location.x + "," + location.y + "," + holdingItem.x + "," + holdingItem.y);
      arrMsg.setConversationId("arrival-inform");
      myAgent.send(arrMsg);

      done();
    }
Exemplo n.º 21
0
 @Override
 public void action() {
   AID[] providers = myAgent.getProvidersInDeal();
   ACLMessage msg = new ACLMessage(ACLMessage.QUERY_REF);
   if (providers.length != 0) {
     for (AID aid : providers) {
       msg.addReceiver(aid);
       // TODO récupérer la ref du produit qu'on veut vraiment acheter
       msg.setContent(String.valueOf(objet.getRefObjet()));
       myAgent.send(msg);
       System.out.println(
           "Requête de prix envoyé a "
               + aid
               + " pour l'objet de reférence "
               + String.valueOf(objet.getRefObjet()));
     }
   }
 }
Exemplo n.º 22
0
    public void action() { // request the hop
      updateStorageAgents();
      ACLMessage movReq = new ACLMessage(ACLMessage.QUERY_IF);
      movReq.addReceiver(storageAgents[0]); // address only the first
      // storage agent(could be
      // randomnized to decrease
      // workload), all storage
      // agents are aware of the
      // same map they share among
      // them
      // System.out.println(moveMentQueue.size());
      String hopRq = "";
      if (moveMentQueue.size() == 0) {
        hopRq += location.x + "," + location.y + ",";
        hopRq += location.x + "," + location.y + ",";
        hopRq += location.x + "," + location.y + ",";
      } else if (moveMentQueue.size() == 1) {
        hopRq += moveMentQueue.get(0).x + "," + moveMentQueue.get(0).y + ",";
        hopRq += moveMentQueue.get(0).x + "," + moveMentQueue.get(0).y + ",";
        hopRq += moveMentQueue.get(0).x + "," + moveMentQueue.get(0).y + ",";

      } else if (moveMentQueue.size() == 2) {
        hopRq += moveMentQueue.get(0).x + "," + moveMentQueue.get(0).y + ",";
        hopRq += moveMentQueue.get(1).x + "," + moveMentQueue.get(1).y + ",";
        hopRq += moveMentQueue.get(1).x + "," + moveMentQueue.get(1).y + ",";

      } else {
        hopRq += moveMentQueue.get(0).x + "," + moveMentQueue.get(0).y + ",";
        hopRq += moveMentQueue.get(1).x + "," + moveMentQueue.get(1).y + ",";
        hopRq += moveMentQueue.get(2).x + "," + moveMentQueue.get(2).y + ",";
      }
      hopRq += location.x + "," + location.y + ",";

      // System.out.println("Hi, I " + this.myAgent.getAID() + " want these locs: " + hopRq);
      // System.out.println("Hi, I want these locs: " + hopRq);

      movReq.setContent(
          hopRq); // ;x,y;x,y;x,y;");// last x,y is the agent its//yes, the last comma is needed
      // current location, this
      // needs to be claimed too
      movReq.setConversationId("hop-request");
      myAgent.send(movReq);
      done();
    }
 @Override
 public void action() {
   // DEBUG
   System.out.println("Seller: wait more bid timeout !");
   Seller mySeller = (Seller) super.myAgent;
   // Select transition
   float nextPrice = mySeller.getCurrentPrice() + mySeller.getPriceStep();
   float maxPrice = mySeller.getMaxPrice();
   float nextPriceStep = mySeller.getPriceStep() / 2f;
   float minPriceStep = mySeller.getMinPriceStep();
   boolean repBidOk = false;
   this.transition = SellerFSMBehaviourAuctionProgress.TRANSITION_TO_ANNOUNCE;
   if (nextPrice < maxPrice) {
     mySeller.increasePrice();
     // DEBUG
     System.out.println(
         "Seller: transition is set to announce, with price increased by priceStep !");
   } else if (nextPriceStep >= minPriceStep) {
     mySeller.decreasePriceStep();
     mySeller.increasePrice();
     // DEBUG
     System.out.println(
         "Seller: transition is set to announce, with price increased by priceStep/2 !");
   } else {
     repBidOk = true;
     // DEBUG
     System.out.println("Seller: setting transition to attribute !");
     this.transition = SellerFSMBehaviourAuctionProgress.TRANSITION_TO_ATTRIBUTE;
   }
   // DEBUG
   System.out.println("Seller: sending rep_bid(" + repBidOk + ") !");
   // send rep_bid
   ACLMessage reply = new ACLMessage(FishMarketProtocol.Performatives.REP_BID);
   // Receiver
   reply.addReceiver(mySeller.getMarketAgent());
   // Set topic
   reply.addReceiver(MarketFSMBehaviourAuctionProgress.MESSAGE_TOPIC);
   // Set conversation id
   reply.setConversationId(this.myFSM.getConversationId());
   // Add selected bidder AID
   reply.setContent(String.valueOf(repBidOk));
   // Send
   mySeller.send(reply);
 }
Exemplo n.º 24
0
  private void selectSession() {
    this.dest = ((ClientAgent) this.myAgent).findDocumentAgent()[0].getName();
    final SelectRequest request = new SelectRequest(objectTypes.session, new Predicate[0]);
    final ACLMessage message = new ACLMessage(ACLMessage.REQUEST);
    message.addReceiver(this.dest);
    message.setContent(request.toJSON());
    this.myAgent.send(message);
    final ACLMessage answer = this.myAgent.blockingReceive();
    final ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);

    ModelObject[] res = null;
    try {
      //			System.out.println("Sessions reçues :"+answer.getContent());
      res = mapper.readValue(answer.getContent(), ModelObject[].class);
    } catch (IOException e) {
      e.printStackTrace();
    }
    this.session = (Session) res[res.length - 1];
  }
Exemplo n.º 25
0
  private void selectDocument() {
    Predicate p[] = {new MobilizedIn(session)};
    final SelectRequest request = new SelectRequest(objectTypes.document, p);
    final ACLMessage message = new ACLMessage(ACLMessage.REQUEST);
    message.addReceiver(this.dest);
    message.setContent(request.toJSON());
    this.myAgent.send(message);
    final ACLMessage answer = this.myAgent.blockingReceive();
    final ObjectMapper mapper = new ObjectMapper();
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);

    ModelObject[] res = null;
    try {
      //			System.out.println("Documents reçus :"+answer.getContent());
      res = mapper.readValue(answer.getContent(), ModelObject[].class);
    } catch (IOException e) {
      e.printStackTrace();
    }
    this.doc = (Document) res[0];
  }
Exemplo n.º 26
0
  @Override
  public void action() {
    MessageTemplate template =
        MessageTemplate.and(
            MessageTemplate.MatchPerformative(ACLMessage.REQUEST),
            MessageTemplate.MatchConversationId("1"));
    ACLMessage message = myAgent.receive(template);

    if (message != null) {
      try {
        RequestCellsMessage requestMessage =
            mapper.readValue(message.getContent(), RequestCellsMessage.class);
        List<Cellule> cellules =
            EnvironnementAgent.sudoku.getCellulesForRank(requestMessage.getRank());
        CellsMessage cellsMessage = new CellsMessage(cellules, requestMessage.getRank());
        StringWriter stringWriter = new StringWriter();
        try {
          mapper.writeValue(stringWriter, cellsMessage);
        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        String messageString = stringWriter.toString();
        if (messageString != null) {
          ACLMessage response = new ACLMessage(ACLMessage.INFORM);
          response.setContent(messageString);
          response.setConversationId("1");
          response.addReceiver(new AID("AgentSimulation", AID.ISLOCALNAME));
          myAgent.send(response);
        }
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

    } else {
      block();
    }
  }
Exemplo n.º 27
0
  //  send CFPs to the bidders
  protected Vector<ACLMessage> prepareCfps(ACLMessage cfp) {
    // look for the bidders in the DF
    DFAgentDescription[] template = searchForBidders(cfp);
    // prepare request
    Vector<ACLMessage> result = new Vector<ACLMessage>(); // prep result vector

    Good theGood = neg.getGood();
    cfp.setContent("Offer is");
    try {
      cfp.setContentObject(theGood);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    System.out.println("Offer:" + request.getContent() + "by" + request.getSender());

    for (int i = 0; i < template.length; i++) {
      cfp.addReceiver(template[i].getName());
    }
    result.add(cfp);
    return result;
  }
Exemplo n.º 28
0
  @Override
  public void action() {

    SNumGente numGente = new SNumGente(2);
    STemperatura sense = new STemperatura();

    AireAcond vent = new AireAcond();
    imprimir = sense.toString() + vent.toString();
    if (sense.getVar() > 20) {
      vent.encender();
    } else {
      if (sense.getVar() < 13) {
        vent.apagar();
      }
    }
    System.out.println(sense.toString());
    System.out.println(vent.toString());

    ACLMessage mensajeRioCoca = getAgent().blockingReceive();
    if (mensajeRioCoca != null) {
      System.out.println(getAgent().getLocalName() + ": acaba de recibir el siguiente mensaje: ");
      System.out.println(mensajeRioCoca);
    }

    ACLMessage respuestaRioCoca = new ACLMessage(ACLMessage.INFORM);
    respuestaRioCoca.setSender(getAgent().getAID());
    respuestaRioCoca.setLanguage(mensajeRioCoca.getLanguage());
    respuestaRioCoca.addReceiver(mensajeRioCoca.getSender());
    respuestaRioCoca.setContent(String.valueOf(numGente.getVar()));
    System.out.println(getAgent().getLocalName() + ": Enviando contestacion");
    System.out.println(respuestaRioCoca);
    getAgent().send(respuestaRioCoca);

    // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
    // methods, choose Tools | Templates.
  }
 private ACLMessage createMessage() {
   ACLMessage message;
   if (id == -1) message = new ACLMessage(ACLMessage.FAILURE);
   else {
     message = new ACLMessage(ACLMessage.INFORM);
     BDDAnswerMessage answer = new BDDAnswerMessage();
     answer.setDemande(demande);
     answer.setUser(user);
     answer.setId(id);
     ObjectMapper omap = new ObjectMapper();
     String messageCorps;
     try {
       messageCorps = omap.writeValueAsString(answer);
       message.setContent(messageCorps);
       message.addReceiver(receiver);
       System.out.println(receiver.getName());
       message.setConversationId(conversationId);
     } catch (JsonProcessingException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
   return message;
 }
 @Override
 public void action() {
   Seller mySeller = (Seller) super.myAgent;
   mySeller.notifyAuctionStarted();
   this.myFSM.resetBidCount();
   this.myFSM.resetWaitCycleCount();
   // DEBUG
   System.out.println("Seller: sending to_announce(" + mySeller.getCurrentPrice() + ") !");
   ACLMessage mess = new ACLMessage(FishMarketProtocol.Performatives.TO_ANNOUNCE);
   // Receiver
   mess.addReceiver(mySeller.getMarketAgent());
   // Set topic
   mess.addReceiver(MarketFSMBehaviourAuctionProgress.MESSAGE_TOPIC);
   // Set conversation id
   mess.setConversationId(this.myFSM.getConversationId());
   // Add price
   mess.setContent(String.valueOf(mySeller.getCurrentPrice()));
   // Send
   mySeller.send(mess);
   // Update GUI
   mySeller.notifyNewAnnounce();
   // DEBUG
   System.out.println("Seller: notifying GUI !");
 }