本文整理汇总了Java中jade.lang.acl.MessageTemplate类的典型用法代码示例。如果您正苦于以下问题:Java MessageTemplate类的具体用法?Java MessageTemplate怎么用?Java MessageTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageTemplate类属于jade.lang.acl包,在下文中一共展示了MessageTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: action
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
@Override
public void action() {
MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.CFP);
ACLMessage msg = myAgent.receive();
if (msg != null) {
parseContent(msg.getContent());
ACLMessage reply = msg.createReply();
int bid;
if (itemPrice < wallet / 4) {
// Place a bid 5 to 10% higher than the received value
bid = (int) (itemPrice + itemPrice * ((float) ThreadLocalRandom.current().nextInt(5, 10) / 10));
reply.setPerformative(ACLMessage.PROPOSE);
reply.setContent(String.valueOf(bid));
} else {
reply.setPerformative(ACLMessage.REFUSE);
}
myAgent.send(reply);
} else {
block();
}
}
示例2: action
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
public void action() {
MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.CFP);
ACLMessage msg = myAgent.receive(mt);
if (msg != null) {
// CFP Message received. Process it
String title = msg.getContent();
ACLMessage reply = msg.createReply();
Integer price = (Integer) catalogue.get(title);
if (price != null) {
// The requested book is available for sale. Reply with the price
reply.setPerformative(ACLMessage.PROPOSE);
reply.setContent(String.valueOf(price.intValue()));
} else {
// The requested book is NOT available for sale.
reply.setPerformative(ACLMessage.REFUSE);
reply.setContent("not-available");
}
myAgent.send(reply);
} else {
block();
}
}
示例3: action
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
@Override
public void action() {
MessageTemplate mt = MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.REQUEST),
MessageTemplate.MatchContent("listGroup"));
ACLMessage message=myAgent.receive(mt);
if(message!=null && message.getPerformative()==ACLMessage.REQUEST){
System.out.println(message.getContent()+"\n");
if(message.getContent().equals("listGroup")){
System.out.println("oklistGruop\n");
myAgent.addBehaviour(new GetListGameBehaviour(myAgent,message));
}
}
}
示例4: action
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
@Override
public void action() {
MessageTemplate mt = MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.SUBSCRIBE),
MessageTemplate.MatchContent(Constance.roomselect_Mode));
ACLMessage message=myAgent.receive(mt);
if (message != null) {
System.out.println("subscrib received");
System.out.println(message.getContent());
if (message.getContent().equals(Constance.roomselect_Mode)) {
System.out.println("code 104 matched");
System.out.println("receive userAgent subscription");
//UserAgent ask for creating a new room
myAgent.addBehaviour(new GameManageBehaviour(myAgent, message));
}
}
}
示例5: action
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
@Override
public void action() {
// TODO Auto-generated method stub
MessageTemplate mts =
MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.SUBSCRIBE),
MessageTemplate.or(
MessageTemplate.MatchConversationId("register"),
MessageTemplate.MatchConversationId("unregister")));
ACLMessage subscribe_message = myAgent.receive(mts);
if(subscribe_message!=null){
if(subscribe_message.getConversationId().equals("register")){
myAgent.addMultiPlayUser(subscribe_message.getSender());
}else if(subscribe_message.getConversationId().equals("unregister")){
myAgent.removeMultiPlayUser(subscribe_message.getSender());
}
}
}
示例6: action
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
@Override
public void action() {
ACLMessage agree = receive(MessageTemplate.MatchPerformative(ACLMessage.AGREE));
ACLMessage cancel = receive(MessageTemplate.MatchPerformative(ACLMessage.CANCEL));
if(agree != null) {
finish = new FinishChecker();
addBehaviour(finish);
fail = new FailChecker();
addBehaviour(fail);
removeBehaviour(ack);
ack = null;
System.out.println("OrderAgent AGREE received, REQUEST processing: " + OrderAgent.this.getLocalName());
} else {
if(cancel != null) {
query = new OrderPickerQuerier();
addBehaviour(query);
removeBehaviour(ack);
ack = null;
System.out.println("OrderAgent CANCEL received, restarting picking: " + OrderAgent.this.getName());
} else {
block();
}
}
}
示例7: action
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
@Override
public void action() {
ACLMessage recMsg = receive(MessageTemplate.MatchPerformative(ACLMessage.FAILURE));
if(recMsg != null) {
ACLMessage response = new ACLMessage(ACLMessage.FAILURE);
Order ordr = unfinishedOrders.get(recMsg.getSender());
for(AID rec : ordr.requestingAgents) {
response.addReceiver(rec);
}
response.setLanguage("English");
response.setContent("Order " + ordr.id + " failed");
System.out.println("WarehouseAgent: Failed order: " + ordr.id);
send(response);
} else {
block();
}
}
示例8: action
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
@Override
public void action()
{
ACLMessage query_if = receive(MessageTemplate.MatchPerformative(ACLMessage.QUERY_IF));
if (query_if != null && OrderPicker.this.isIdle)
{
ACLMessage response = query_if.createReply();
response.setPerformative(ACLMessage.CONFIRM);
response.setLanguage("JSON");
response.setContent(new JSONObject().put(getLocalName(), true).toString());
send(response);
}
else
{
block();
}
}
示例9: action
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
@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;
}
}
}
示例10: onWake
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
@Override
protected void onWake() {
final MessageTemplate mtMatchingMsgId = MessageTemplate.MatchInReplyTo(messageId);
final MessageTemplate mtMatchingPerformative = MessageTemplate.MatchPerformative(ACLMessage.PROPOSE);
final MessageTemplate mt = MessageTemplate.and(mtMatchingMsgId, mtMatchingPerformative);
final Collection<ACLMessage> proposals = new HashSet<>();
ACLMessage proposal;
while ((proposal = myAgent.receive(mt)) != null) {
proposals.add(proposal);
}
final ACLMessage bestProposal = caller.chooseProposal(conversationId, proposals);
if (bestProposal != null) {
acceptProposal(bestProposal);
final Collection<ACLMessage> others = proposals.stream().filter(p -> !p.equals(bestProposal)).collect(Collectors.toList());
rejectProposals(others);
}
}
示例11: action
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
public void action() {
MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.CFP);
ACLMessage msg = myAgent.receive(mt);
if (msg != null) {
// CFP Message received. Process it
String title = msg.getContent();
ACLMessage reply = msg.createReply();
Integer price = (Integer) catalogue.get(title);
if (price != null) {
// The requested book is available for sale. Reply with the price
reply.setPerformative(ACLMessage.PROPOSE);
reply.setContent(String.valueOf(price.intValue()));
}
else {
// The requested book is NOT available for sale.
reply.setPerformative(ACLMessage.REFUSE);
reply.setContent("not-available");
}
myAgent.send(reply);
}
else {
block();
}
}
示例12: setup
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
public void setup() {
this.myIntrospector = JadeAgentIntrospector.getMyInstance((Agent) this);
LogActivator.logToFile(logger, this.getName(), Level.ALL);
// Register the service
try {
DFAgentDescription dfd = new DFAgentDescription();
ServiceDescription sd = new ServiceDescription();
sd.setType("server");
sd.setName("report-service");
// Sets the agent description
dfd.setName(this.getAID());
dfd.addServices(sd);
// Register the agent
DFService.register(this, dfd);
} catch (Exception e) {
logger.severe("Exception registering agent in DF. Agent: " + this.getName());
}
MessageTemplate t = MessageTemplate.MatchPerformative(ACLMessage.INFORM);
addBehaviour(new ReportServer(this,t));
}
示例13: setup
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
public void setup() {
this.myIntrospector = JadeAgentIntrospector.getMyInstance((Agent) this);
LogActivator.logToFile(logger, this.getName(), Level.ALL);
// Register the service
try {
DFAgentDescription dfd = new DFAgentDescription();
ServiceDescription sd = new ServiceDescription();
sd.setType("server");
sd.setName("helpdesk-service");
// Sets the agent description
dfd.setName(this.getAID());
dfd.addServices(sd);
// Register the agent
DFService.register(this, dfd);
} catch (Exception e) {
logger.severe("Exception registering agent in DF. Agent: " + this.getName());
}
MessageTemplate t = MessageTemplate.MatchPerformative(ACLMessage.REQUEST);
addBehaviour(new HelpDeskServer(this,t));
}
示例14: ask
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
protected ACLMessage ask(final ACLMessage m) {
try {
String waitingRW = "id"+incReplyWithId();
m.setReplyWith(waitingRW);
send(m);
ACLMessage r = blockingReceive(MessageTemplate.MatchInReplyTo(waitingRW), 5000);
if (r != null)
return r;
else
logger.warning("ask timeout for "+m.getContent());
} catch (Exception e) {
logger.log(Level.SEVERE, "Error waiting message.", e);
}
return null;
}
示例15: ask
import jade.lang.acl.MessageTemplate; //导入依赖的package包/类
protected ACLMessage ask(final ACLMessage m) {
try {
String waitingRW = "id"+incReplyWithId();
m.setReplyWith(waitingRW);
send(m);
ACLMessage r = blockingReceive(MessageTemplate.MatchInReplyTo(waitingRW), 5000);
if (r != null)
return r;
else
logger.warning("ask timeout for "+m.getContent());
} catch (Exception e) {
logger.log(Level.SEVERE, "Error waiting message.", e);
}
return null;
}