本文整理汇总了Java中jade.lang.acl.ACLMessage类的典型用法代码示例。如果您正苦于以下问题:Java ACLMessage类的具体用法?Java ACLMessage怎么用?Java ACLMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ACLMessage类属于jade.lang.acl包,在下文中一共展示了ACLMessage类的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: action
import jade.lang.acl.ACLMessage; //导入依赖的package包/类
@Override
public void action() {
myAgent.getContentManager().registerLanguage(new SLCodec(), FIPANames.ContentLanguage.FIPA_SL0);
myAgent.getContentManager().registerOntology(JADEManagementOntology.getInstance());
ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
msg.addReceiver(myAgent.getDefaultDF());
msg.setOntology(JADEManagementOntology.NAME);
msg.setLanguage(FIPANames.ContentLanguage.FIPA_SL0);
msg.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
Action a = new Action();
a.setActor( myAgent.getDefaultDF() );
a.setAction( new ShowGui() );
try {
myAgent.getContentManager().fillContent(msg,a);
} catch (Exception e) {
e.printStackTrace();
}
myAgent.send(msg);
myAgent.doDelete();
}
示例6: 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;
}
}
}
示例7: adviceNextGhost
import jade.lang.acl.ACLMessage; //导入依赖的package包/类
protected void adviceNextGhost()
{
// Selects the next ghost (if any) to leave the house and sends it a message
List<GhostAgent> nextGhosts = new ArrayList<>(); // Just for a hack
board.getGhosts().stream().filter((ghost)
-> (!ghost.equals(myAgent)) && !ghost.isHouseLeft() && nextGhosts.isEmpty()).forEachOrdered((ghost) ->
{
Coord2D position = ghost.getBoardCell().getPosition();
for (Direction direction : Direction.values())
{
Cell nearCell = board.getCell(new Coord2D(position.x + direction.xInc, position.y + direction.yInc));
if (nearCell.getType() == CellType.GHOST_HOUSE)
{
// Mounts the message and sends it to the next ghost to leave the house
ACLMessage nextGhostMessage = new ACLMessage(ACLMessage.INFORM);
nextGhostMessage.setOntology(GhostVocabulary.ONTOLOGY);
nextGhostMessage.setContent(GhostVocabulary.LEAVE_THE_HOUSE);
nextGhostMessage.addReceiver(ghost.getAID());
myAgent.send(nextGhostMessage);
nextGhosts.add(ghost); // It's added an element to nextGhosts just to break the forEachOrdered()
}
}
});
}
示例8: processExecutionControlOntologyMsg
import jade.lang.acl.ACLMessage; //导入依赖的package包/类
boolean processExecutionControlOntologyMsg() {
ACLMessage m = receive(ts);
if (m != null) {
// send the agent state
ACLMessage r = m.createReply();
r.setPerformative(ACLMessage.INFORM);
try {
Document agStateDoc = jasonBridgeAgArch.getTS().getAg().getAgState();
r.setContentObject((Serializable)agStateDoc);
send(r);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error sending message " + r, e);
}
}
m = receive(tc);
if (m != null) {
int cycle = Integer.parseInt(m.getUserDefinedParameter("cycle"));
logger.fine("new cycle: "+cycle);
jasonBridgeAgArch.setCycleNumber(cycle);
return true;
}
return false;
}
示例9: aclToKqml
import jade.lang.acl.ACLMessage; //导入依赖的package包/类
public static String aclToKqml(ACLMessage m) {
switch(m.getPerformative()) {
case ACLMessage.INFORM: return "tell";
case ACLMessage.QUERY_REF: return "askOne";
case ACLMessage.REQUEST: return "achieve";
/*case UNTELL: return "untell";
case UNACHIEVE: return "unachieve";
case ASKALL: return "askAll";
case ASKHOW: return "askHow";
case TELLHOW: return "tellHow";
case UNTELLHOW: return "untellHow";*/
case ACLMessage.INFORM_REF:
String kp = m.getUserDefinedParameter("kqml-performative");
if (kp != null) {
return kp;
}
break;
}
return ACLMessage.getPerformative(m.getPerformative()).toLowerCase().replaceAll("-", "_");
}
示例10: informAllAgsToPerformCycle
import jade.lang.acl.ACLMessage; //导入依赖的package包/类
public void informAllAgsToPerformCycle(final int cycle) {
addBehaviour(new OneShotBehaviour() {
public void action() {
try {
logger.fine("Sending performCycle "+cycle+" to all agents.");
ACLMessage m = new ACLMessage(ACLMessage.INFORM);
m.setOntology(controllerOntology);
addAllAgsAsReceivers(m);
m.setContent("performCycle");
m.addUserDefinedParameter("cycle", String.valueOf(cycle));
send(m);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error in informAllAgsToPerformCycle", e);
}
}
});
}
示例11: 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);
}
}
示例12: isActionFeedback
import jade.lang.acl.ACLMessage; //导入依赖的package包/类
boolean isActionFeedback(ACLMessage m) {
// check if there are feedbacks on requested action executions
if (m.getOntology() != null && m.getOntology().equals(JadeEnvironment.actionOntology)) {
String irt = m.getInReplyTo();
if (irt != null) {
ActionExec a = myPA.remove(irt);
// was it a pending action?
if (a != null) {
if (m.getContent().equals("ok")) {
a.setResult(true);
} else {
a.setResult(false);
}
actionExecuted(a);
} else {
logger.log(Level.SEVERE, "Error: received feedback for an Action that is not pending. The message is "+m);
}
}
return true;
}
return false;
}
示例13: action
import jade.lang.acl.ACLMessage; //导入依赖的package包/类
public void action() {
ResultsAgent a = (ResultsAgent)myAgent;
// Send result before closing down
ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
msg.setSender(a.getAID());
msg.addReceiver(new AID(SendTo, false));
try {
Object[] oMsg=new Object[3];
oMsg[0] = ID;
oMsg[1] = bText1;
oMsg[2] = bText2;
msg.setContentObject(oMsg);
} catch (IOException ex) {
System.err.println("Cannot add result to message. Sending empty message.");
ex.printStackTrace(System.err);
}
a.send(msg);
}
示例14: action
import jade.lang.acl.ACLMessage; //导入依赖的package包/类
/** Actually sends the result to the dispatching agent.
*/
public void action() {
synchronized (myAgent) {
NGramDocumentComparatorAgent a = (NGramDocumentComparatorAgent)myAgent;
// Send result before closing down
ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
msg.setSender(a.getAID());
msg.addReceiver(a.ResultConsumer);
try {
msg.setContentObject(Result);
} catch (IOException ex) {
System.err.println("Cannot add result to message. Sending empty message.");
ex.printStackTrace(System.err);
}
a.send(msg);
}
}
示例15: setup
import jade.lang.acl.ACLMessage; //导入依赖的package包/类
public void setup() {
@SuppressWarnings("unchecked")
final List<ACLMessage> l = (List<ACLMessage>)getArguments()[0];
addBehaviour(new jade.core.behaviours.CyclicBehaviour() {
public void action() {
System.out.println(" Trying... ");
ACLMessage m = receive();
if(m != null) {
System.out.println(" received "+m);
l.add(m);
} else {
block();
}
}
});
}