本文整理汇总了Java中jade.lang.acl.ACLMessage.setContent方法的典型用法代码示例。如果您正苦于以下问题:Java ACLMessage.setContent方法的具体用法?Java ACLMessage.setContent怎么用?Java ACLMessage.setContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jade.lang.acl.ACLMessage
的用法示例。
在下文中一共展示了ACLMessage.setContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleGameEnd
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
private void handleGameEnd()
{
// If the game still has remaining ghosts and collectibles,
// Pacman still didn't won the game
int remainingGhosts = (int) board.getGhosts()
.stream()
.filter(ghost -> !ghost.isShouldDie())
.count();
if (0 < remainingGhosts && board.hasRemainingCollectibles())
{
return;
}
// Else, informs Game agent the game has been won (and should end)
ACLMessage message = new ACLMessage(ACLMessage.INFORM);
message.setOntology(GameVocabulary.ONTOLOGY);
message.setContent(GameVocabulary.END_PACMAN_WINS);
message.addReceiver(new AID(Constant.GAME_AGENT_NAME, AID.ISLOCALNAME));
myAgent.send(message);
}
示例2: die
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
public void die()
{
// Marks the ghost for dying
setShouldDie(true);
// Notifies other ghosts so they can run
ACLMessage message = new ACLMessage(ACLMessage.INFORM);
message.setOntology(GhostVocabulary.ONTOLOGY);
message.setContent(GhostVocabulary.THE_MOTHERFUCKER_KILLED_ME);
board.getGhosts()
.stream()
.filter(ghost -> !ghost.equals(this))
.forEach(ghost -> message.addReceiver(ghost.getAID()));
send(message);
// Notifies GameAgent I'm dead
message.clearAllReceiver();
message.setOntology(GameVocabulary.ONTOLOGY);
message.setContent(GameVocabulary.GHOST_KILLED);
message.addReceiver(new AID(Constant.GAME_AGENT_NAME, AID.ISLOCALNAME));
send(message);
// Effectively dies
doDelete();
}
示例3: informAgsEnvironmentChanged
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
public void informAgsEnvironmentChanged(Collection<String> agentsToNotify) {
try {
if (agentsToNotify == null) {
informAgsEnvironmentChanged();
} else {
ACLMessage m = new ACLMessage(ACLMessage.INFORM);
m.setContent("environmentChanged");
for (String ag: agentsToNotify) {
m.addReceiver(new AID(ag, AID.ISLOCALNAME));
}
send(m);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Error sending notifyEvents ", e);
}
}
示例4: perceive
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<Literal> perceive() {
if (!isRunning()) return null;
if (getEnvironmentAg() == null) return null;
@SuppressWarnings("rawtypes")
List percepts = null;
try {
ACLMessage askMsg = new ACLMessage(ACLMessage.QUERY_REF);
askMsg.addReceiver(environmentAID);
askMsg.setOntology(JadeEnvironment.perceptionOntology);
askMsg.setContent("getPercepts");
ACLMessage r = jadeAg.ask(askMsg);
if (r != null && r.getContent().startsWith("[")) {
percepts = ListTermImpl.parseList(r.getContent());
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Error in perceive.", e);
}
return percepts;
}
示例5: recycle
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
private void recycle()
{
if (!((GameAgent) myAgent).isTurnComplete())
{
if (Constant.DEBUG)
{
System.out.println("ResendTimeout is " + ResendTimeout);
}
if (0 == --ResendTimeout)
{
System.out.println("Resending move order...");
ACLMessage message = new ACLMessage(ACLMessage.REQUEST);
message.setOntology(GameVocabulary.ONTOLOGY);
message.setContent(GameVocabulary.MOVE_YOUR_BODY);
((GameAgent) myAgent).getAgentsToMove().forEach(agent -> message.addReceiver(agent));
myAgent.send(message);
ResendTimeout = Constant.GAME_RESEND_MOVE_ORDER_TIMEOUT;
}
}
}
示例6: act
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void act(ActionExec action) { //, List<ActionExec> feedback) {
if (!isRunning()) return;
if (getEnvironmentAg() == null) return;
try {
Term acTerm = action.getActionTerm();
logger.fine("doing: " + acTerm);
String rw = "id"+jadeAg.incReplyWithId();
ACLMessage m = new ACLMessage(ACLMessage.REQUEST);
m.addReceiver(environmentAID);
m.setOntology(JadeEnvironment.actionOntology);
m.setContent(acTerm.toString());
m.setReplyWith(rw);
myPA.put(rw, action);
jadeAg.send(m);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error sending action " + action, e);
}
}
示例7: action
import jade.lang.acl.ACLMessage; //导入方法依赖的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();
}
}
示例8: perceive
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<Literal> perceive() {
super.perceive();
if (!isRunning()) return null;
if (getEnvironmentAg() == null) return null;
@SuppressWarnings("rawtypes")
List percepts = null;
try {
ACLMessage askMsg = new ACLMessage(ACLMessage.QUERY_REF);
askMsg.addReceiver(environmentAID);
askMsg.setOntology(JadeEnvironment.perceptionOntology);
askMsg.setContent("getPercepts");
ACLMessage r = jadeAg.ask(askMsg);
if (r != null && r.getContent().startsWith("[")) {
percepts = ListTermImpl.parseList(r.getContent());
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Error in perceive.", e);
}
return percepts;
}
示例9: act
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void act(ActionExec action) {
if (!isRunning()) return;
if (getEnvironmentAg() == null) return;
try {
Term acTerm = action.getActionTerm();
logger.fine("doing: " + acTerm);
String rw = "id"+jadeAg.incReplyWithId();
ACLMessage m = new ACLMessage(ACLMessage.REQUEST);
m.addReceiver(environmentAID);
m.setOntology(JadeEnvironment.actionOntology);
m.setContent(acTerm.toString());
m.setReplyWith(rw);
myPA.put(rw, action);
jadeAg.send(m);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error sending action " + action, e);
}
}
示例10: action
import jade.lang.acl.ACLMessage; //导入方法依赖的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();
}
}
示例11: receiveMessage
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void receiveMessage(final FrameworkMessage msg, final String messageID,
final String inReplyToMessageID, final JadeControllerMock jade_ControllerMock) {
final ACLMessage aclMsg = new ACLMessage(ACLMessage.INFORM);
aclMsg.addReceiver(aid);
aclMsg.setContent(msg.toPrettyPrintedXMLString());
aclMsg.setConversationId("jade-controller");
aclMsg.setReplyWith(UUID.randomUUID().toString());
System.out
.println("[JADE Controller Agent ] Sending message to distributed JADE Agent: "
+ distributedSystemID
+ " "
+ distributedAutonomousAgentID
+ " "
+ distAutAgentModelID);
jadeControllerAgent.send(aclMsg);
}
示例12: action
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action() {
ACLMessage message = new ACLMessage(ACLMessage.INFORM);
message.setConversationId("BACKGROUND");
message.addReceiver(myAgent.getSoundAgentName());
my_data.setAction(type);
my_data.setPath(path);
ObjectMapper mapper = new ObjectMapper();
StringWriter sw = new StringWriter();
try {
mapper.writeValue(sw, my_data);
message.setContent(sw.toString());
} catch (Exception e) {
e.printStackTrace();
}
myAgent.send(message);
System.out.println("bg message sent");
}
示例13: action
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action() {
ObjectMapper mapper = new ObjectMapper();
StringWriter sw = new StringWriter();
ACLMessage message = new ACLMessage(ACLMessage.INFORM);
try {
mapper.writeValue(sw, inform);
message.addReceiver(aid);
//message.setConversationId(id.toString());
message.setConversationId("NOTE");
message.setContent(sw.toString());
myAgent.send(message);
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: action
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action()
{
removeBehaviour(OrderPicker.this.abortOrder);
removeBehaviour(OrderPicker.this.shelfInteraction);
log("Order complete, send INFORM to " + OrderPicker.this.currentOrderAgent.getLocalName() + "!");
ACLMessage inform = new ACLMessage(ACLMessage.INFORM);
inform.addReceiver(OrderPicker.this.currentOrderAgent);
inform.setLanguage("JSON");
inform.setProtocol("JSON");
inform.setContent(OrderPicker.this.orderOutgoing.toString());
send(inform);
OrderPicker.this.itemStatus.clear();
OrderPicker.this.shelfInfo.clear();
OrderPicker.this.orderOutgoing = null;
OrderPicker.this.orderOutgoing = new JSONArray();
OrderPicker.this.isIdle = true;
removeBehaviour(this);
}
示例15: action
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action()
{
// If the game is not running or Pacman is marked
// for death, doesn't move
if (!( // If not
((PacmanAgent) myAgent).isGameRunning() // ... game is running
&& !((PacmanAgent) myAgent).isShouldDie() // ... Pacman is not marked for death
))
{
System.out.println(myAgent.getLocalName() + " cannot move!");
// Replies to the Game Agent denying this behaviour
ACLMessage reply = originMessage.createReply();
reply.setPerformative(ACLMessage.REFUSE);
reply.setContent(GameVocabulary.MOVED_MY_BODY);
myAgent.send(reply);
// Updates the GhostAgent state
((PacmanAgent) myAgent).setMoving(false);
// Removes this behaviour from Pacman
myAgent.removeBehaviour(this);
return;
}
synchronized(this)
{
move(); // Pacman makes a movement
checkGhostInSamePath(); // Pacman checks if there is a ghost in the same path as it
}
}