コード例 #1
0
 private MessageTemplate getMessageFilter() {
   Seller mySeller = (Seller) super.myAgent;
   return MessageTemplate.and(
       this.myFSM.getMessageFilter(),
       MessageTemplate.and(
           MessageTemplate.MatchContent(String.valueOf(mySeller.getCurrentPrice())),
           MessageTemplate.MatchPerformative(FishMarketProtocol.Performatives.TO_BID)));
 }
コード例 #2
0
 @Override
 public void action() {
   //			System.out.println(getName() + ": state=Waiting...");
   newAuctionStarted = false;
   MessageTemplate template = MessageTemplate.MatchContent("inform-start-of-auction");
   ACLMessage message = receive(template);
   if (message != null) {
     marketAgent = message.getSender();
     newAuctionStarted = true;
     convID = message.getConversationId();
     // System.out.println(getName() + ": Received Auction start message!");
   } else block();
 }
コード例 #3
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();
    }