本文整理汇总了Java中jade.lang.acl.ACLMessage.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java ACLMessage.getContent方法的具体用法?Java ACLMessage.getContent怎么用?Java ACLMessage.getContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jade.lang.acl.ACLMessage
的用法示例。
在下文中一共展示了ACLMessage.getContent方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: handleServiceTypeRequest
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public ACLMessage handleServiceTypeRequest(ACLMessage serviceTypeRequest) {
if (serviceTypeRequest == null || serviceTypeRequest.getContent() == null) {
return failureMessage(serviceTypeRequest);
}
String serviceType = serviceTypeRequest.getContent();
if (serviceType.equals(ServiceType.TAKE_BLOCK.name())) {
return handleTakeBlockRequest(serviceTypeRequest);
} else if (serviceType.equals(ServiceType.I_OCCUPY.name())) {
return handleOccupyRequest(serviceTypeRequest);
} else if (serviceType.equals(ServiceType.FINISH_BLOCK.name())) {
return handleFinishBlockRequest(serviceTypeRequest);
} else {
return handleGiveBlockRequest(serviceTypeRequest);
}
}
示例3: handleServiceTypeRequest
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public ACLMessage handleServiceTypeRequest(ACLMessage serviceTypeRequest) {
if (serviceTypeRequest == null || serviceTypeRequest.getContent() == null) {
return failureMessage(serviceTypeRequest);
}
String serviceType = serviceTypeRequest.getContent();
if (!serviceType.equals(ServiceType.TAKE_BLOCK.name())) {
return failureMessage(serviceTypeRequest);
}
Block block = sourcePalette.takeBlock();
return addBlockToMessage(informMessage(serviceTypeRequest), block);
}
示例4: action
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action() {
ACLMessage recMsg = receive(MessageTemplate.MatchPerformative(ACLMessage.INFORM));
if(recMsg != null) {
JSONArray arr = new JSONArray(recMsg.getContent());
for(int i = 0; i < arr.length(); i++) {
JSONObject elem = new JSONObject(arr.getString(i));
Pair<String, Integer> p = Pair.convert(elem);
if(items.containsKey(p)) {
if(items.get(p)) {
failure();
return;
} else {
items.put(p, true);
}
} else {
failure();
return;
}
}
items.forEach((Pair<String, Integer> K, Boolean V) -> {
if(!V) {
failure();
return;
}
});
success();
} else {
block();
}
}
示例5: action
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action() {
ACLMessage recMsg = receive(MessageTemplate.MatchPerformative(ACLMessage.REQUEST));
if(recMsg != null) {
JSONObject js = new JSONObject(recMsg.getContent());
JSONArray json = js.getJSONArray("products");
Order ordr = new Order();
ordr.id = js.getInt("id");
// Confirm Order
ACLMessage response = new ACLMessage(ACLMessage.AGREE);
Iterator<AID> replyTo = recMsg.getAllReplyTo();
while(replyTo.hasNext()) {
AID tmpAID = replyTo.next();
ordr.requestingAgents.add(tmpAID);
response.addReceiver(tmpAID);
}
response.setLanguage("JSON");
response.setContent("{id:" + ordr.id + "}");
send(response);
// Process Order
for(int i = 0; i < json.length(); i++) {
JSONObject pair = json.getJSONObject(i);
ordr.items.add(Pair.convert(pair));
}
// Create Order Agent and hand over data
String orderAgentName = "Order" + ordr.id;
try {
AgentController ac = getContainerController().createNewAgent(orderAgentName, "warehouse.agents.OrderAgent", new Object[]{
ordr.items
});
ac.start();
} catch(Exception ex) {
System.err.println("Could not start OrderAgent: " + ordr.id + " " + ex.toString() + ": " + ex.getMessage());
}
ordr.handlingAgentAddress = new AID(orderAgentName, AID.ISLOCALNAME);
unfinishedOrders.put(ordr.handlingAgentAddress, ordr);
} else {
block();
}
}
示例6: requestShelfAgents
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
private void requestShelfAgents() {
DFAgentDescription template = new DFAgentDescription();
ServiceDescription sd = new ServiceDescription();
sd.setType("giveProduct");
template.addServices(sd);
ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
try {
DFAgentDescription[] result = DFService.search(myAgent,
template);
for (DFAgentDescription agent : result) {
msg.addReceiver(agent.getName());
}
for (String s : order) {
if (msg.getContent() == null) {
msg.setContent(s);
} else {
msg.setContent(msg.getContent() + ", " + s);
}
}
send(msg);
} catch (FIPAException fe) {
fe.printStackTrace();
}
}
示例7: action
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
public void action()
{
MessageAgent agent = (MessageAgent)myAgent;
ACLMessage msg = myAgent.receive();
while (msg != null) {
String title = msg.getContent();
AID sender = msg.getSender();
agent.incomingMessage(toAPLMessage(msg,agent.getLocalName()));
msg = myAgent.receive();
}
block();
}
示例8: action
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action()
{
ACLMessage message = myAgent.receive();
if (null != message)
{
System.out.println(myAgent.getLocalName() + " received " + message.getContent() + " from " + message.getSender().getLocalName());
switch (message.getOntology())
{
case GameVocabulary.ONTOLOGY:
switch (message.getContent())
{
case GameVocabulary.START:
case GameVocabulary.CONTINUE:
((PacmanAgent) myAgent).setGameRunning(true);
break;
case GameVocabulary.PAUSE:
((PacmanAgent) myAgent).setGameRunning(false);
break;
case GameVocabulary.MOVE_YOUR_BODY:
if (!((PacmanAgent) myAgent).isMoving())
{
((PacmanAgent) myAgent).setMoving(true);
myAgent.addBehaviour(new PacmanMovementBehaviour(message, board, myCell));
}
break;
default:
block();
}
break;
default:
block();
}
}
else
{
block();
}
}
示例9: action
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action()
{
ACLMessage message = myAgent.receive();
if (null != message)
{
System.out.println(myAgent.getLocalName() + " received " + message.getContent() + " from " + message.getSender().getLocalName());
switch (message.getOntology())
{
case GameVocabulary.ONTOLOGY:
switch (message.getContent())
{
case GameVocabulary.CONTINUE:
((GhostAgent) myAgent).setGameRunning(true);
break;
case GameVocabulary.MOVE_YOUR_BODY:
if (!((GhostAgent) myAgent).isMoving())
{
((GhostAgent) myAgent).setMoving(true);
myAgent.addBehaviour(new GhostMovementBehaviour(message, board, myCell));
}
else
{
System.out.println(myAgent.getLocalName() + " is already moving...");
}
break;
case GameVocabulary.PAUSE:
((GhostAgent) myAgent).setGameRunning(false);
break;
case GameVocabulary.START:
((GhostAgent) myAgent).setGameRunning(true);
myAgent.addBehaviour(new GhostLeaveHouseFirstBehaviour(myAgent, board, myCell));
break;
default:
block();
}
break;
case GhostVocabulary.ONTOLOGY:
switch (message.getContent())
{
case GhostVocabulary.LEAVE_THE_HOUSE:
myAgent.addBehaviour(new GhostLeaveHouseNextBehaviour(myAgent, board, myCell));
break;
case GhostVocabulary.GET_OUT_OF_MY_WAY:
((GhostAgent) myAgent).setReverseDirection(true);
break;
case GhostVocabulary.THE_MOTHERFUCKER_IS_DEAD:
((GhostAgent) myAgent).setGameRunning(false);
System.out.println("YAAAAAY! " + myAgent.getLocalName() + " is happy because "
+ "Pacman is finally dead!");
break;
case GhostVocabulary.THE_MOTHERFUCKER_KILLED_ME:
System.out.println("Oh, no... " + message.getSender().getLocalName() + " was killed by the motherfucker... :(~");
// TODO: Run away from Pacman (if a ghost was killed, it means Pacman is powerful)
break;
default:
block();
}
default:
block();
}
}
else
{
block();
}
}
示例10: action
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action()
{
MessageTemplate mt = MessageTemplate.MatchOntology(GameVocabulary.ONTOLOGY);
ACLMessage message = myAgent.receive(mt);
if (null != message)
{
System.out.println(myAgent.getLocalName() + " received " + message.getContent() + " from " + message.getSender().getLocalName());
switch (message.getContent())
{
case GameVocabulary.AGENT_INITIALIZED:
handleAgentInitialized();
break;
case GameVocabulary.END_PACMAN_WINS:
pacmanWins = true;
((GameAgent) myAgent).setGameEnded(true);
break;
case GameVocabulary.GHOST_KILLED:
handleAgentKilled(message.getSender());
break;
case GameVocabulary.MOVED_MY_BODY:
handleAgentMovement(message.getSender());
break;
case GameVocabulary.PACMAN_KILLED:
pacmanWins = false;
((GameAgent) myAgent).setGameEnded(true);
handleAgentKilled(message.getSender());
break;
default:
block();
}
}
else
{
block();
}
}
示例11: action
import jade.lang.acl.ACLMessage; //导入方法依赖的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.
}
}
示例12: action
import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action()
{
ACLMessage request = receive(MessageTemplate.MatchPerformative(ACLMessage.REQUEST));
if (request != null)
{
if (OrderPicker.this.isIdle)
{
if (request.getLanguage().equals("JSON"))
{
OrderPicker.this.isIdle = false;
OrderPicker.this.currentOrderAgent = request.getSender();
ACLMessage agree = request.createReply();
agree.setPerformative(ACLMessage.AGREE);
agree.setLanguage("JSON");
agree.setProtocol("JSON");
agree.setContent(new JSONObject().put(getLocalName(), true).toString());
send(agree);
OrderPicker.this.orderIncoming = new JSONArray(request.getContent());
OrderPicker.this.shelfInteraction = new ShelfInteraction();
addBehaviour(OrderPicker.this.shelfInteraction);
initLogFile(OrderPicker.this.currentOrderAgent);
for (int i = 0; i < OrderPicker.this.orderIncoming.length(); i++)
{
Pair<String, Integer> item = Pair.convert(OrderPicker.this.orderIncoming.getJSONObject(i));
OrderPicker.this.itemStatus.put(item, ItemStatus.BROADCASTED);
}
logItemStatus();
Behaviour incomingOrderBC = new Broadcaster(OrderPicker.this.orderIncoming);
addBehaviour(incomingOrderBC);
OrderPicker.this.abortOrder = new AbortOrder(this.myAgent);
addBehaviour(OrderPicker.this.abortOrder);
}
}
else
{
ACLMessage cancel = request.createReply();
cancel.setPerformative(ACLMessage.CANCEL);
cancel.setLanguage("JSON");
cancel.setProtocol("JSON");
cancel.setContent(new JSONObject().put(getLocalName(), false).toString());
send(cancel);
}
}
else
{
block();
}
}