diff --git a/src/main/java/org/team_pjt/agents/OrderProcessing.java b/src/main/java/org/team_pjt/agents/OrderProcessing.java index 169af1e..712109d 100644 --- a/src/main/java/org/team_pjt/agents/OrderProcessing.java +++ b/src/main/java/org/team_pjt/agents/OrderProcessing.java @@ -127,9 +127,15 @@ private void sendNotFeasibleMessage(ACLMessage msg, String content) { private void distributeScheduledOrder() { System.out.println("waiting for accepted proposal"); - MessageTemplate acceptedProposalMT = MessageTemplate.MatchPerformative(ACLMessage.ACCEPT_PROPOSAL); + MessageTemplate acceptedProposalMT = MessageTemplate.or(MessageTemplate.MatchPerformative(ACLMessage.ACCEPT_PROPOSAL), + MessageTemplate.MatchPerformative(ACLMessage.REJECT_PROPOSAL)); ACLMessage accepted_proposal = receive(acceptedProposalMT); if(accepted_proposal != null) { + if(accepted_proposal.getPerformative() == ACLMessage.REJECT_PROPOSAL) { + step++; + return; + } + System.out.println("accept proposal received"); findAllAgents(); ACLMessage propagate_accepted_order = new ACLMessage(ACLMessage.PROPAGATE); propagate_accepted_order.setContent(accepted_proposal.getContent()); @@ -138,7 +144,6 @@ private void distributeScheduledOrder() { } sendMessage(propagate_accepted_order); System.out.println("Propagated all scheduled Orders"); - System.out.println(myAgent.getName() + " called finished()"); step++; } else { @@ -208,7 +213,6 @@ public void action() { MessageTemplate schedulerReply = MessageTemplate.and(MessageTemplate.MatchConversationId(order.getGuid()), MessageTemplate.MatchConversationId(order.getGuid())); ACLMessage schedulerMessage = myAgent.receive(schedulerReply); - System.out.println("in case 1"); if (schedulerMessage != null) { System.out.println("schedule reply received!"); if (schedulerMessage.getPerformative() == ACLMessage.CONFIRM) { @@ -229,7 +233,7 @@ public void action() { proposeMsg.setConversationId(order.getGuid()); sendMessage(proposeMsg); System.out.println("proposed available products"); - distributeScheduledOrder(); + step++; } else if (schedulerMessage.getPerformative() == ACLMessage.DISCONFIRM) { bFeasibleOrder = false; } @@ -240,12 +244,16 @@ public void action() { block(); } break; + case 2: + System.out.println("in case 3"); + distributeScheduledOrder(); + break; } } @Override public boolean done() { - boolean isDone = step >= 2 || messageCounter == allCustomers.length; + boolean isDone = step >= 3 || messageCounter == allCustomers.length; if(isDone) { myAgent.addBehaviour(new schedulerSyncing()); myAgent.addBehaviour(new OfferRequestServer());