当前位置: 首页>>代码示例>>Java>>正文


Java ACLMessage.getSender方法代码示例

本文整理汇总了Java中jade.lang.acl.ACLMessage.getSender方法的典型用法代码示例。如果您正苦于以下问题:Java ACLMessage.getSender方法的具体用法?Java ACLMessage.getSender怎么用?Java ACLMessage.getSender使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jade.lang.acl.ACLMessage的用法示例。


在下文中一共展示了ACLMessage.getSender方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: action

import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action() {
	ACLMessage message = receive();

	if (message != null && message.getPerformative() == ACLMessage.INFORM) {
		AID sender = message.getSender();

		if (message.getContent().equals(Message.FINISH_SIMULATION)){
			countSoundSourcesFinished++;
			if(countSoundSourcesFinished==ambient.getSoundSources().size()){
				finishSimulation();
				System.out.println("Simulation finished.");
				countSoundSourcesFinished=0;
			}
		}
		else {
			send(Message.getAnswerOfANotUnderstoodMessage(sender));					
		}
	}
}
 
开发者ID:gabriel-augusto,项目名称:AcSimus,代码行数:21,代码来源:Ambient.java

示例2: action

import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action() {
	
	ACLMessage msg = myAgent.receive();			
	if (msg!=null) {
		
		AID sender = msg.getSender();
		
		// ---- extract content -----------------------------
		Object msgContent = null;
		try {
			msgContent = msg.getContentObject();
		} catch (UnreadableException e) {
			msgContent = null;
		}
		
		localEnvModelNew.put(sender.getLocalName(), (Integer) msgContent);
		if (localEnvModelNew.size()==localEnvModel.size()) {
			
			gui.updateGUI(localEnvModelNew);
			localEnvModel = localEnvModelNew;
			localEnvModelNew = new HashMap<String, Integer>();
			
			if (gui.slider.getValue()>0) {
				myAgent.doWait(gui.slider.getValue());
			}
			
			// --- Den n�chsten Schritt ausf�hren ----
			myAgent.addBehaviour(new StepBehaviour());
		}
		
	}
	else {
		block();
	}			
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:37,代码来源:SimulationManagerAgent.java

示例3: action

import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action() {
	ACLMessage message = receive();

	if (message != null && message.getPerformative() == ACLMessage.INFORM) {
		AID sender = message.getSender();

		if (message.getContent().equals(Message.STOP_RESUMED)){
			send(soundSource.stopSimulation(Message.STOP_RESUMED));
			System.out.println("Simulation stoped.");
		}
              else if (message.getContent().equals(Message.STOP_PAUSED)){
			send(soundSource.stopSimulation(Message.STOP_PAUSED));
			System.out.println("Simulation stoped.");
		}
		else if(message.getContent().equals(Message.PAUSE)){
			send(soundSource.suspendAllSounds());
		}
		else if(message.getContent().equals(Message.RESUME)){
			soundSource.resumeAllSounds();
		}
		else if(message.getContent().equals(Message.RUN)){
			soundSource.emitSoundPulse();
		}
		else if(message.getLanguage().equals(Language.FINISH)){
			soundSource.getSounds().remove(message.getContent());
			if(soundSource.getSounds().isEmpty()){
				send(Message.prepareMessage(ACLMessage.INFORM, null, Message.FINISH_SIMULATION, soundSource.getAmbient()));
			}
		}
		else {
			send(Message.getAnswerOfANotUnderstoodMessage(sender));					
		}
	}

}
 
开发者ID:gabriel-augusto,项目名称:AcSimus,代码行数:37,代码来源:SoundSource.java

示例4: 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();
}
 
开发者ID:ROSAPL,项目名称:2APL_fork,代码行数:13,代码来源:MessageBehaviour.java

示例5: action

import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
public void action() {
    switch (step) {
    case 0:
        // Send the cfp to all sellers
        ACLMessage cfp = new ACLMessage(ACLMessage.CFP);
        for (int i = 0; i < sellerAgents.length; ++i) {
            cfp.addReceiver(sellerAgents[i]);
        }
        cfp.setContent(targetBookTitle);
        cfp.setConversationId("book-trade");
        cfp.setReplyWith("cfp"+System.currentTimeMillis()); // Unique value
        myAgent.send(cfp);
        // Prepare the template to get proposals
        mt = MessageTemplate.and(MessageTemplate.MatchConversationId("book-trade"),
                                 MessageTemplate.MatchInReplyTo(cfp.getReplyWith()));
        step = 1;
        break;
    case 1:
        // Receive all proposals/refusals from seller agents
        ACLMessage reply = myAgent.receive(mt);
        if (reply != null) {
            // Reply received
            if (reply.getPerformative() == ACLMessage.PROPOSE) {
                // This is an offer
                int price = Integer.parseInt(reply.getContent());
                if (bestSeller == null || price < bestPrice) {
                    // This is the best offer at present
                    bestPrice = price;
                    bestSeller = reply.getSender();
                }
            }
            repliesCnt++;
            if (repliesCnt >= sellerAgents.length) {
                // We received all replies
                step = 2;
            }
        } else {
            block();
        }
        break;
    case 2:
        // Send the purchase order to the seller that provided the best offer
        ACLMessage order = new ACLMessage(ACLMessage.ACCEPT_PROPOSAL);
        order.addReceiver(bestSeller);
        order.setContent(targetBookTitle);
        order.setConversationId("book-trade");
        order.setReplyWith("order"+System.currentTimeMillis());
        myAgent.send(order);
        // Prepare the template to get the purchase order reply
        mt = MessageTemplate.and(MessageTemplate.MatchConversationId("book-trade"),
                                 MessageTemplate.MatchInReplyTo(order.getReplyWith()));
        step = 3;
        break;
    case 3:
        // Receive the purchase order reply
        reply = myAgent.receive(mt);
        if (reply != null) {
            // Purchase order reply received
            if (reply.getPerformative() == ACLMessage.INFORM) {
                // Purchase successful. We can terminate
                System.out.println(targetBookTitle+" successfully purchased from agent "+reply.getSender().getName());
                System.out.println("Price = "+bestPrice);
                myAgent.doDelete();
            } else {
                System.out.println("Attempt failed: requested book already sold.");
            }

            step = 4;
        } else {
            block();
        }
        break;
    }
}
 
开发者ID:jason-lang,项目名称:jason,代码行数:75,代码来源:BookBuyerAgent.java

示例6: 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();
	}
}
 
开发者ID:autarchprinceps,项目名称:Multiagent-Warehouse,代码行数:55,代码来源:OrderPicker.java

示例7: action

import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action() {

	ACLMessage message = myAgent.receive(MessageTemplate
			.MatchProtocol("request-robot"));

	if (message != null) {

		ACLMessage response = message.createReply();

		switch (message.getPerformative()) {
		case ACLMessage.REQUEST:

			if (isIdle && !promisedProposal) {

				response.setPerformative(ACLMessage.PROPOSE);
				send(response);
				promisedProposal = true;

			} else {
				response.setPerformative(ACLMessage.REFUSE);
				send(response);
			}

			break;

		case ACLMessage.ACCEPT_PROPOSAL:

			// TRANSPORT THAT SHELF
			isIdle = false;
			currentShelf = message.getSender();
			myAgent.addBehaviour(new TransportShelfToOrderPicker());
			break;

		case ACLMessage.REJECT_PROPOSAL:
			promisedProposal = false;
			break;

		case ACLMessage.INFORM:

			// SHELF INFORMS US THAT IT WANTS HOME
			if (!isIdle) {
				myAgent.addBehaviour(new TransportShelfHome());
			}

			break;
		}

	} else {
		block();
	}

}
 
开发者ID:autarchprinceps,项目名称:Multiagent-Warehouse,代码行数:54,代码来源:RobotAgent.java

示例8: action

import jade.lang.acl.ACLMessage; //导入方法依赖的package包/类
@Override
public void action() {
	ACLMessage message = myAgent.receive(MessageTemplate
			.MatchProtocol("request-robot"));

	if (message != null) {
		ACLMessage response = message.createReply();

		switch (message.getPerformative()) {

		case ACLMessage.PROPOSE:

			if (currentState != State.waitForRobot) {

				// WE ALREADY HAVE A ROBOT
				response.setPerformative(ACLMessage.REJECT_PROPOSAL);
				send(response);

			} else {

				// GOT A ROBOT
				log("ACCEPT_PROPOSAL with "
						+ message.getSender().getLocalName());
				response.setPerformative(ACLMessage.ACCEPT_PROPOSAL);
				send(response);

				broadcastRobots.stop();
				removeBehaviour(broadcastRobots);

				// WAIT FOR ARRIVAL
				currentState = State.travelToOrderPicker;
				currentRobot = message.getSender();

			}
			break;

		case ACLMessage.INFORM:

			if (currentState == State.travelToOrderPicker) {

				// ARRIVAL AT THE ORDER PICKER
				log("INFORM arrived at "
						+ currentOrderPicker.getLocalName());
				currentState = State.serveOrderPicker;
				addBehaviour(new ArriveAtOrderPicker());

			} else if (currentState == State.travelBackHome) {

				// ARRIVAL HOME
				currentPickupWaitBehaviour.stop();
				currentState = State.idle;
			}
			break;
		}

	} else {
		block();
	}

}
 
开发者ID:autarchprinceps,项目名称:Multiagent-Warehouse,代码行数:61,代码来源:ShelfAgent.java


注:本文中的jade.lang.acl.ACLMessage.getSender方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。