本文整理汇总了Java中jason.asSemantics.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于jason.asSemantics包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkMail
import jason.asSemantics.Message; //导入依赖的package包/类
/** overridden to ignore bid messages */
public void checkMail() {
List mbox = (List) fEnv.getAgMbox(getName());
synchronized (mbox) {
Iterator i = mbox.iterator();
while (i.hasNext()) {
Message im = (Message) i.next();
if (!im.getPropCont().startsWith("bid")) {
fTS.getC().getMB().add(im);
if (fTS.getSettings().verbose() >= 1) {
System.out.println("Agent " + getName() + " received message: " + im);
}
}
i.remove();
}
}
}
示例2: sendMsg
import jason.asSemantics.Message; //导入依赖的package包/类
public void sendMsg(Message m) throws ReceiverNotFoundException {
// actually send the message
if (m.getSender() == null) m.setSender(getAgName());
CentralisedAgArch rec = masRunner.getAg(m.getReceiver());
if (rec == null) {
if (isRunning())
throw new ReceiverNotFoundException("Receiver '" + m.getReceiver() + "' does not exist! Could not send " + m);
else
return;
}
rec.receiveMsg(m.clone()); // send a cloned message
// notify listeners
if (msgListeners != null)
for (MsgListener l: msgListeners)
l.msgSent(m);
}
示例3: broadcast
import jason.asSemantics.Message; //导入依赖的package包/类
public void broadcast(final Message m) {
addBehaviour(new OneShotBehaviour() {
private static final long serialVersionUID = 1L;
public void action() {
try {
ACLMessage acl = jasonToACL(m);
addAllAgsAsReceivers(acl);
send(acl);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error in broadcast of "+m, e);
}
}
});
}
示例4: fencePerceived
import jason.asSemantics.Message; //导入依赖的package包/类
public void fencePerceived(int x, int y, boolean open) {
int obj;
Atom s;
if (open) {
obj = WorldModel.OPEN_FENCE;
s = aOPEN;
} else {
obj = WorldModel.CLOSED_FENCE;
s = aCLOSED;
}
if (!model.hasObject(obj, x, y)) {
model.add(obj, x, y);
//if (acView != null) acView.addObject(obj, x, y);
Message m = new Message("tell", null, null, createCellPerception(x, y, ASSyntax.createStructure(aFENCE.toString(), s)));
try { broadcast(m); } catch (Exception e) { e.printStackTrace(); }
}
}
示例5: locationPerceived
import jason.asSemantics.Message; //导入依赖的package包/类
/** update the model with the agent location and share this information with team mates */
void locationPerceived(final int x, final int y) {
if (model == null) {
logger.info("***** No model created yet! I cannot set my location");
return;
}
oldLoc = model.getAgPos(getMyId());
if (oldLoc != null) {
model.clearAgView(oldLoc); // clear golds and enemies
}
if (oldLoc == null || !oldLoc.equals(new Location(x,y))) {
try {
model.setAgPos(getMyId(), x, y);
//if (acView != null) acView.getModel().setAgPos(getMyId(), x, y);
model.incVisited(x, y);
Message m = new Message("tell", null, null, "my_status("+x+","+y+")");
broadcast(m);
} catch (Exception e) {
e.printStackTrace();
}
}
myAddQueue(lastLocations, new Location(x, y));
checkRestart();
}
示例6: broadcast
import jason.asSemantics.Message; //导入依赖的package包/类
/** change broadcast to send messages to only my team mates */
@Override
public void broadcast(Message m) throws Exception {
//String basename = getAgName().substring(0,getAgName().length()-1);
if (model == null) return;
for (int i=1; i <= model.getAgsByTeam() ; i++) {
String oname = teamId+i;
if (!getAgName().equals(oname)) {
Message msg = new Message(m);
msg.setReceiver(oname);
for (int t=0; t<6; t++) {
try {
sendMsg(msg);
break; // the for
} catch (ReceiverNotFoundException e) {
logger.info("Receiver "+oname+" not found: wait and try later, "+t);
// wait and try again
Thread.sleep(500);
}
}
}
}
}
示例7: obstaclePerceived
import jason.asSemantics.Message; //导入依赖的package包/类
/** update the model with obstacle and share them with the team mates */
public void obstaclePerceived(int x, int y) {
//getTS().getLogger().info("perceived obstacle bbbb "+x+","+y+" "+model.hasObject(WorldModel.OBSTACLE, x, y));
if (! model.hasObject(WorldModel.OBSTACLE, x, y)) {
model.add(WorldModel.OBSTACLE, x, y);
//if (acView != null) acView.addObject(WorldModel.OBSTACLE, x, y);
Message m = new Message("tell", null, null, createCellPerception(x, y, aOBSTACLE));
try { broadcast(m); } catch (Exception e) { e.printStackTrace(); }
} else {
Location l = new Location(x, y);
if (ephemeralObstacle.remove(l))
logger.info("uuuuu ephemeral location "+l+" perceived! so, it is no more ephemeral.");
}
if(clModel == null)
clModel = ClusterModelFactory.getModel(teamId+myId);
clModel.insertTree(x, y);
}
示例8: broadcast
import jason.asSemantics.Message; //导入依赖的package包/类
/** change broadcast to send messages to only my team mates */
@Override
public void broadcast(Message m) throws Exception {
//String basename = getAgName().substring(0,getAgName().length()-1);
if (model == null) return;
for (int i=1; i <= model.getAgsByTeam() ; i++) {
String oname = teamId+i;
if (!getAgName().equals(oname)) {
Message msg = new Message(m);
msg.setReceiver(oname);
for (int t=0; t<6; t++) {
try {
sendMsg(msg);
//logger.info("mmmm sent "+msg.toString());
break; // the for
} catch (ReceiverNotFoundException e) {
logger.info("Receiver "+oname+" not found: wait and try later, "+t);
// wait and try again
Thread.sleep(500);
}
}
}
}
}
示例9: broadcast
import jason.asSemantics.Message; //导入依赖的package包/类
/** change broadcast to send messages to only my team mates */
@Override
public void broadcast(Message m) throws Exception {
String basename = getAgName().substring(0,getAgName().length()-1);
for (int i=1; i <= model.getAgsByTeam() ; i++) {
String oname = basename+i;
if (!getAgName().equals(oname)) {
Message msg = new Message(m);
msg.setReceiver(oname);
for (int t=0; t<6; t++) {
try {
sendMsg(msg);
break; // the for
} catch (ReceiverNotFoundException e) {
// wait and try again
Thread.sleep(500);
}
}
}
}
}
示例10: sendMsg
import jason.asSemantics.Message; //导入依赖的package包/类
public void sendMsg(Message m) throws ReceiverNotFoundException {
// actually send the message
if (m.getSender() == null) m.setSender(getAgName());
CentralisedAgArch rec = masRunner.getAg(m.getReceiver());
if (rec == null) {
if (isRunning())
throw new ReceiverNotFoundException("Receiver '" + m.getReceiver() + "' does not exist! Could not send " + m);
else
return;
}
rec.receiveMsg(m.clone()); // send a cloned message
// notify listeners
if (msgListeners != null)
for (MsgListener l: msgListeners)
l.msgSent(m);
}
示例11: ZigBeeSensorNodeSofware
import jason.asSemantics.Message; //导入依赖的package包/类
/**
* Constructor
*
* @param id
* @param logger
* @param stepTime
* @param random
*/
public ZigBeeSensorNodeSofware(String id, Logger logger, ZigBeeSensorNode hardware, double perceptionRange,
double stepTime, double maxNoise, double minNoise, MersenneTwisterFast random, ShanksSimulation sim) {
super(id, logger);
this.hardware = hardware;
this.hardware.setSoftware(this);
this.perceptionRange = perceptionRange;
this.stepTime = stepTime;
this.msgsReadyToProcess = new ArrayList<Message>();
this.consumedTimeInStep = 0.0;
this.maxNoise = maxNoise;
this.minNoise = minNoise;
this.random = random;
this.msgCounter = 0;
this.sim = sim;
}
示例12: getMessageProcessingTime
import jason.asSemantics.Message; //导入依赖的package包/类
/**
* @param msg
* @return
*/
private double getMessageProcessingTime(Message msg) {
Object content = msg.getPropCont();
String s = content.toString() + msg.getInReplyTo();
byte[] asciiBytes = new byte[0];
try {
asciiBytes = s.getBytes("ASCII");
} catch (UnsupportedEncodingException e) {
this.getLogger().warning("Impossible to get package size in bytes: " + e.getMessage());
}
int bytes = asciiBytes.length;
double bits = bytes * 8;
// 108kbps = 108bpms
// time in ms
double time = bits / 108;
return time;
}
示例13: checkMail
import jason.asSemantics.Message; //导入依赖的package包/类
@Override
public void checkMail() {
ACLMessage acl;
while ((acl = agent.getNextMessage()) != null) {
String ilForce = JasonMessage.getIlForce(acl);
String sender = acl.sender.toString();
String replyWith = acl.replyWith;
String inReplyTo = acl.inReplyTo;
Serializable content = JasonMessage.getJasonContent(acl);
if (content != null) {
Message jmsg = new Message(ilForce, sender, agent.getAid().toString(), content, replyWith);
if (inReplyTo != null)
jmsg.setInReplyTo(inReplyTo);
getTS().getC().getMailBox().add(jmsg);
}
}
}
示例14: toAclMessage
import jason.asSemantics.Message; //导入依赖的package包/类
public static ACLMessage toAclMessage(Message jmsg) {
ACLMessage acl = createForIlForce(jmsg.getIlForce());
acl.sender = new AID(jmsg.getSender());
final String jmsgReceiver = jmsg.getReceiver();
if (jmsgReceiver != null)
acl.receivers.add(new AID(jmsgReceiver));
if (jmsg.getPropCont() instanceof Term || jmsg.getPropCont() instanceof String) {
acl.content = jmsg.getPropCont().toString();
} else {
acl.contentObj = (Serializable) jmsg.getPropCont();
}
acl.replyWith = jmsg.getMsgId();
acl.language = "AgentSpeak";
if (jmsg.getInReplyTo() != null)
acl.inReplyTo = jmsg.getInReplyTo();
return acl;
}
示例15: checkMail
import jason.asSemantics.Message; //导入依赖的package包/类
public void checkMail() {
// Check incoming new argumentation
List<Message> inbox = this.getInbox();
if (inbox.size() > 0) {
this.pendingArguments = new ArrayList<Argument>();
for (Message msg : inbox) {
Argument arg = (Argument) msg.getPropCont();
this.pendingArguments.add(arg);
}
} else {
// If no message is received, the argumentation finish
}
inbox.clear();
}