本文整理汇总了Java中jade.lang.acl.ACLMessage.CFP属性的典型用法代码示例。如果您正苦于以下问题:Java ACLMessage.CFP属性的具体用法?Java ACLMessage.CFP怎么用?Java ACLMessage.CFP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类jade.lang.acl.ACLMessage
的用法示例。
在下文中一共展示了ACLMessage.CFP属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: action
@Override
public void action() {
final MessageTemplate mt = MessageTemplate.MatchConversationId(conversationId);
final ACLMessage request = myAgent.receive(mt);
if (request == null) {
block();
} else {
switch (request.getPerformative()) {
case ACLMessage.CFP:
respondToCfp(request);
return;
case ACLMessage.ACCEPT_PROPOSAL:
respondToAcceptProposal(request);
return;
case ACLMessage.REJECT_PROPOSAL:
return;
default:
return;
}
}
}
示例2: action
@Override
public void action() {
try {
final Date proposalDeadline = caller.getProposalDeadline(conversationId);
final Collection<DFAgentDescription> stationAgents = getCfpRecipients();
final ACLMessage cfp = new ACLMessage(ACLMessage.CFP);
cfp.setConversationId(conversationId);
cfp.setReplyWith(messageId);
cfp.setReplyByDate(proposalDeadline);
for (final DFAgentDescription agent : stationAgents) {
cfp.addReceiver(agent.getName());
}
caller.configureCfp(conversationId, cfp);
myAgent.send(cfp);
myAgent.addBehaviour(new CollectProposalsBehaviour(proposalDeadline));
} catch (FIPAException e) {
LOG.error("Unable to contact stations.", e);
}
}
示例3: action
public void action() {
switch (step) {
case 0:
// Send the cfp to all sellers
ACLMessage cfp = new ACLMessage(ACLMessage.CFP);
for (int i = 0; i < sellerAgents.length; ++i) {
cfp.addReceiver(sellerAgents[i]);
}
cfp.setContent(targetBookTitle);
cfp.setConversationId("book-trade");
cfp.setReplyWith("cfp"+System.currentTimeMillis()); // Unique value
myAgent.send(cfp);
// Prepare the template to get proposals
mt = MessageTemplate.and(MessageTemplate.MatchConversationId("book-trade"),
MessageTemplate.MatchInReplyTo(cfp.getReplyWith()));
step = 1;
break;
case 1:
// Receive all proposals/refusals from seller agents
ACLMessage reply = myAgent.receive(mt);
if (reply != null) {
// Reply received
if (reply.getPerformative() == ACLMessage.PROPOSE) {
// This is an offer
int price = Integer.parseInt(reply.getContent());
if (bestSeller == null || price < bestPrice) {
// This is the best offer at present
bestPrice = price;
bestSeller = reply.getSender();
}
}
repliesCnt++;
if (repliesCnt >= sellerAgents.length) {
// We received all replies
step = 2;
}
} else {
block();
}
break;
case 2:
// Send the purchase order to the seller that provided the best offer
ACLMessage order = new ACLMessage(ACLMessage.ACCEPT_PROPOSAL);
order.addReceiver(bestSeller);
order.setContent(targetBookTitle);
order.setConversationId("book-trade");
order.setReplyWith("order"+System.currentTimeMillis());
myAgent.send(order);
// Prepare the template to get the purchase order reply
mt = MessageTemplate.and(MessageTemplate.MatchConversationId("book-trade"),
MessageTemplate.MatchInReplyTo(order.getReplyWith()));
step = 3;
break;
case 3:
// Receive the purchase order reply
reply = myAgent.receive(mt);
if (reply != null) {
// Purchase order reply received
if (reply.getPerformative() == ACLMessage.INFORM) {
// Purchase successful. We can terminate
System.out.println(targetBookTitle+" successfully purchased from agent "+reply.getSender().getName());
System.out.println("Price = "+bestPrice);
myAgent.doDelete();
} else {
System.out.println("Attempt failed: requested book already sold.");
}
step = 4;
} else {
block();
}
break;
}
}