本文整理汇总了Java中jade.lang.acl.MessageTemplate.MatchPerformative方法的典型用法代码示例。如果您正苦于以下问题:Java MessageTemplate.MatchPerformative方法的具体用法?Java MessageTemplate.MatchPerformative怎么用?Java MessageTemplate.MatchPerformative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jade.lang.acl.MessageTemplate
的用法示例。
在下文中一共展示了MessageTemplate.MatchPerformative方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}
示例4: 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();
}
}
示例5: 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));
}
示例6: 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));
}
示例7: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
@Override
public void action() {
if (first) {
AID server_name = myAgent.getServerName();
if (server_name != null){
msg.clearAllReceiver();
msg.addReceiver(server_name);
msg.setContent(Constance.roomselect_Mode);
MyAID sound_agent = new MyAID(myAgent.getMySoundAgent().getName(), myAgent.getMySoundAgent().getAddressesArray()[0]);
msg.setReplyWith(sound_agent.toJSON());
myAgent.send(msg);
first = false;
System.out.println("Ask for creating room sent");
} else {
System.out.println("server not found");
}
} else {
MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.CONFIRM);
ACLMessage message=myAgent.receive(mt);
if(message != null){
myAgent.addBehaviour(new ModeSelectBehaviour(myAgent, Constance.roomselect_Mode));
done = true;
System.out.println("room created, behaviour done");
myAgent.setRoomId(message.getContent());
myAgent.addBehaviour(new LocalGameDaemonBehaviour(myAgent));
}
}
}
示例8: setupConfiguration5
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
private void setupConfiguration5(Object[] arguments) {
MessageTemplate template = MessageTemplate.MatchPerformative(ACLMessage.INFORM);
addBehaviour(new RequestServer(template, 0));
logger.fine("RequestServer behaviour added");
setMessageReceived(false);
long timeToWait = 200;
try {
Thread.sleep(timeToWait);
} catch (InterruptedException e) {
logger.severe(this.getName() + " could not wait " + timeToWait
+ " milliseconds. Exception: " + e);
}
}
示例9: setupConfiguration6
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
private void setupConfiguration6(Object[] arguments) {
MessageTemplate template = MessageTemplate.MatchPerformative(ACLMessage.REQUEST);
addBehaviour(new RequestServer(template, 1));
logger.fine("RequestServer behaviour added");
long timeToWait = 200;
try {
Thread.sleep(timeToWait);
} catch (InterruptedException e) {
logger.severe(this.getName() + " could not wait " + timeToWait
+ " milliseconds. Exception: " + e);
}
}
示例10: RobotPositionResponder
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
public RobotPositionResponder(Agent a, Grid grid) {
super(a);
msgTemplate = MessageTemplate.MatchPerformative(ACLMessage.INFORM);
// this.grid = grid;
}
示例11: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
@Override
public void action() {
MessageTemplate mt = MessageTemplate
.MatchPerformative(ACLMessage.INFORM);
ACLMessage aclMsg = myAgent.receive(mt);
if (aclMsg != null) {
// Message matching the template has come in.
String msgStr = aclMsg.getContent();
FrameworkMessage message = null;
try {
message = new FrameworkMessageImpl(
SYSTEM_TYPE.DISTRIBUTED_SYSTEM,
SYSTEM_TYPE.SIMULATION_ENGINE, msgStr);
} catch (CsfCheckedException e) {
// FIXME: Remove all of the agents/shutdown the MAS?
System.out
.println("[JADE Controller Agent] Error converting message from a distributed JADE agent to the JADE Controller Agent: "
+ msgStr);
doDelete();
e.printStackTrace();
}
System.out
.println("[JADE Controller Agent] Received the distributed autonomous agent (model) decision. Forwarding to the simulation engine (agent)");
jade_MAS_RunContext.messageSimulationEngine(message,
jade_MAS_RunContext.getDistSysRunContext());
FRAMEWORK_COMMAND fc = getJade_MAS_RunContext()
.waitForAndProcessSimulationEngineMessageAfterHandshake();
if (fc == FRAMEWORK_COMMAND.STOP_SIMULATION) {
System.out
.println("[JADE Controller Agent] Received Stop Simulation Command from Simulation Engine. Listening for new simulation run");
setupNewSimulationRun();
}
} else {
block(); // Save CPU cycles by not executing this thread until
// new messages come in.
}
}