Skip to content

Commit

Permalink
Assignment 4 schedule and aggregation of order #12
Browse files Browse the repository at this point in the history
accepting proposals now always working
  • Loading branch information
Dr4gonbl4de committed Nov 25, 2018
1 parent 6e0dae4 commit 395c079
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/org/team_pjt/agents/OrderProcessing.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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());
Expand Down

0 comments on commit 395c079

Please sign in to comment.