protected ACLMessage prepareResultNotification(ACLMessage request, ACLMessage response) {
   if (request.getOntology().equals("request-ids")) return handleTourGuideRequest(request);
   else if (request.getOntology().equals("get-item-information"))
     return handleProfilerRequest(request);
   else {
     ACLMessage informDone = request.createReply();
     informDone.setPerformative(ACLMessage.NOT_UNDERSTOOD);
     return informDone;
   }
 }
Пример #2
0
  @Override
  public void handleMessage(ACLMessage msg) {
    System.out.println(myAgent.getAID().getName() + " RECIEVED message: " + msg.getOntology());
    if (msg != null) {
      Object o = null;
      try {
        o = msg.getContentObject();
        if (o == null) {
          block();
        }
      } catch (UnreadableException ex) {
        Logger.getLogger(TourGuideAgent.class.getName()).log(Level.SEVERE, null, ex);
        block();
      }

      if (msg.getOntology().equalsIgnoreCase(Ontologies.PROFILER_REQUEST_TOUR_AGENT)) {
        UserProfile up = (UserProfile) o;

        tourGuide.usersLock.lock();
        try {
          tourGuide.getUsers().put(msg.getSender(), up);
        } finally {
          tourGuide.usersLock.unlock();
        }

        tourGuide.startTour();
      } else if (msg.getOntology().equalsIgnoreCase(Ontologies.QUERY_ARTIFACTS)) {
        Map<String, AID> requests = tourGuide.getRequests();
        final AID user = requests.get(msg.getConversationId());
        List<ACLMessage> msglist = tourGuide.getResponses().get(user);
        msglist.add(msg);
        System.out.println(
            "added msg " + msg + " to msgList: " + tourGuide.getResponses().get(user));
        requests.remove(msg.getConversationId());
      }
    } else {
      System.err.println("Agent " + myAgent.getAID().getName() + " RECIEVED message: null.");
      block();
    }

    myAgent.addBehaviour(
        new TGAMsgReceiverBehaviour(myAgent, null, deadline, getDataStore(), null));
  }
 @Override
 public boolean match(ACLMessage msg) {
   String ontology = msg.getOntology();
   return ontology.equalsIgnoreCase(Ontologies.AUCTION_START)
       || ontology.equalsIgnoreCase(Ontologies.CALL_FOR_PROPOSALS)
       || ontology.equalsIgnoreCase(Ontologies.AUCTION_NO_BIDS)
       || ontology.equalsIgnoreCase(Ontologies.AUCTION_WON)
       || msg.getPerformative() == ACLMessage.ACCEPT_PROPOSAL
       || msg.getPerformative() == ACLMessage.REJECT_PROPOSAL;
 }
  /** Looks at the message type and starts the appropriate handler */
  @Override
  public void action() {
    ACLMessage msg = curator.receive(mt);

    if (msg != null) {
      String ontology = msg.getOntology();

      if (ontology.equalsIgnoreCase(Ontologies.AUCTION_START)) {
        handleAuctionStart(msg);
      } else if (ontology.equalsIgnoreCase(Ontologies.CALL_FOR_PROPOSALS)) {
        handleCFP(msg);
      } else if (ontology.equalsIgnoreCase(Ontologies.AUCTION_NO_BIDS)) {
        handleAuctionNoBids(msg);
      } else if (ontology.equalsIgnoreCase(Ontologies.AUCTION_WON)) {
        handleAuctionWon(msg);
      } else if (msg.getPerformative() == ACLMessage.ACCEPT_PROPOSAL) {
        handleAcceptProposal(msg);
      } else if (msg.getPerformative() == ACLMessage.REJECT_PROPOSAL) {
        handleReject(msg);
      }
    } else {
      block();
    }
  }
Пример #5
0
  @Override
  public void action() {

    // message templte for dutch auction
    MessageTemplate mt =
        MessageTemplate.and(
            MessageTemplate.MatchPerformative(ACLMessage.INFORM),
            MessageTemplate.MatchProtocol(FIPANames.InteractionProtocol.FIPA_DUTCH_AUCTION));

    msg = myAgent.receive(mt);

    if (msg != null) {
      if (msg.getPerformative() == ACLMessage.INFORM) {
        if (msg.getOntology().equals("AUCTION")) {
          if (msg.getContent().startsWith("AUCTION")) {
            System.out.println(myAgent.getLocalName() + ": auction has started");
            // Auction with 100 as this agents highest buying price
            int price = 40000 + rand.nextInt(15000);
            myAgent.addBehaviour(new NewAuctionBehaviour(Integer.toString(price)));
          } else myAgent.putBack(msg);
        }
      }
    }
  }