本文整理汇总了Java中jade.lang.acl.MessageTemplate.and方法的典型用法代码示例。如果您正苦于以下问题:Java MessageTemplate.and方法的具体用法?Java MessageTemplate.and怎么用?Java MessageTemplate.and使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jade.lang.acl.MessageTemplate
的用法示例。
在下文中一共展示了MessageTemplate.and方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
@Override
public void action() {
MessageTemplate mt = MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.REQUEST),
MessageTemplate.MatchContent("listGroup"));
ACLMessage message=myAgent.receive(mt);
if(message!=null && message.getPerformative()==ACLMessage.REQUEST){
System.out.println(message.getContent()+"\n");
if(message.getContent().equals("listGroup")){
System.out.println("oklistGruop\n");
myAgent.addBehaviour(new GetListGameBehaviour(myAgent,message));
}
}
}
示例2: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
@Override
public void action() {
MessageTemplate mt = MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.SUBSCRIBE),
MessageTemplate.MatchContent(Constance.roomselect_Mode));
ACLMessage message=myAgent.receive(mt);
if (message != null) {
System.out.println("subscrib received");
System.out.println(message.getContent());
if (message.getContent().equals(Constance.roomselect_Mode)) {
System.out.println("code 104 matched");
System.out.println("receive userAgent subscription");
//UserAgent ask for creating a new room
myAgent.addBehaviour(new GameManageBehaviour(myAgent, message));
}
}
}
示例3: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
@Override
public void action() {
// TODO Auto-generated method stub
MessageTemplate mts =
MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.SUBSCRIBE),
MessageTemplate.or(
MessageTemplate.MatchConversationId("register"),
MessageTemplate.MatchConversationId("unregister")));
ACLMessage subscribe_message = myAgent.receive(mts);
if(subscribe_message!=null){
if(subscribe_message.getConversationId().equals("register")){
myAgent.addMultiPlayUser(subscribe_message.getSender());
}else if(subscribe_message.getConversationId().equals("unregister")){
myAgent.removeMultiPlayUser(subscribe_message.getSender());
}
}
}
示例4: onWake
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
@Override
protected void onWake() {
final MessageTemplate mtMatchingMsgId = MessageTemplate.MatchInReplyTo(messageId);
final MessageTemplate mtMatchingPerformative = MessageTemplate.MatchPerformative(ACLMessage.PROPOSE);
final MessageTemplate mt = MessageTemplate.and(mtMatchingMsgId, mtMatchingPerformative);
final Collection<ACLMessage> proposals = new HashSet<>();
ACLMessage proposal;
while ((proposal = myAgent.receive(mt)) != null) {
proposals.add(proposal);
}
final ACLMessage bestProposal = caller.chooseProposal(conversationId, proposals);
if (bestProposal != null) {
acceptProposal(bestProposal);
final Collection<ACLMessage> others = proposals.stream().filter(p -> !p.equals(bestProposal)).collect(Collectors.toList());
rejectProposals(others);
}
}
示例5: FTPUploadRequestResponderBehaviour
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
public FTPUploadRequestResponderBehaviour(Agent a, String username, String password, InetAddress host) {
super(a, MessageTemplate.and(
MessageTemplate.MatchProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST),
MessageTemplate.MatchOntology(FTPOntology.ONTOLOGY_NAME)));
this.username = username;
this.password = password;
this.host = host;
}
示例6: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
public void action() {
MessageTemplate filtre = MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.INFORM),
MessageTemplate.MatchConversationId("NOTE"));
ACLMessage request = myAgent.receive(filtre);
if(request != null) {
ObjectMapper mapper = new ObjectMapper();
try {
NoteInformData data = mapper.readValue(request.getContent(), NoteInformData.class);
if (Constance.ENABLE_DELAY && System.currentTimeMillis() - data.getTimestamp() < Constance.MAX_MESSAGE_DELAY) {
switch(data.getAction()) {
case START_NOTE:
addBehaviour(new BeginNote(data));
break;
case STOP_NOTE:
addBehaviour(new EndNote(data));
break;
case CHANGE_INSTRUMENT:
addBehaviour(new ChangeSound(data));
break;
case DEFAULT:
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
else
block();
}
示例7: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
@Override
public void action() {
if (first) {
AID server_name = myAgent.getServerName();
if (server_name != null){
msg.addReceiver(server_name);
msg.setContent(Constance.ExitGroupMode);
msg.setConversationId(msg_conversation);
myAgent.send(msg);
first = false;
System.out.println("Ask for quiting a room sent");
} else {
System.out.println("server not found");
}
} else {
MessageTemplate mt = MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.CONFIRM),
MessageTemplate.and(MessageTemplate.MatchContent(Constance.ROOM_QUITTED), MessageTemplate.MatchConversationId(msg_conversation)));
ACLMessage message=myAgent.receive(mt);
if(message != null){
myAgent.addBehaviour(new ModeSelectBehaviour(myAgent, UserAgent.Exit_Room_Mode));
done = true;
System.out.println("room quitted, behaviour done");
myAgent.setRoomId(null);
}
}
}
示例8: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
@Override
public void action() {
if (first) {
AID server_name = myAgent.getServerName();
if (server_name != null){
msg.addReceiver(server_name);
msg.setContent(Constance.EnterGroupMode);
msg.setConversationId(msg_conversation);
MyAID sound_agent = new MyAID(myAgent.getMySoundAgent().getName(), myAgent.getMySoundAgent().getAddressesArray()[0]);
msg.setReplyWith(sound_agent.toJSON());
myAgent.send(msg);
first = false;
System.out.println("Ask for entring a room sent");
} else {
System.out.println("server not found");
}
} else {
MessageTemplate mt = MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.CONFIRM),
MessageTemplate.and(MessageTemplate.MatchContent(Constance.ROOM_ENTERED), MessageTemplate.MatchConversationId(msg_conversation)));
ACLMessage message=myAgent.receive(mt);
if(message != null){
myAgent.addBehaviour(new ModeSelectBehaviour(myAgent, Constance.roomselect_Mode));
done = true;
System.out.println("room entered, behaviour done");
myAgent.setRoomId(msg_conversation);
myAgent.addBehaviour(new LocalGameDaemonBehaviour(myAgent));
}
}
}
示例9: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void action() {
if(first){
ACLMessage multiPlayRegister = new ACLMessage(ACLMessage.SUBSCRIBE);
multiPlayRegister.setConversationId("register");
multiPlayRegister.setSender(myAgent.getAID());
multiPlayRegister.addReceiver(myAgent.getServerName());
multiPlayRegister.setContent("getting in");
myAgent.send(multiPlayRegister);
first = false;
}
if(!myAgent.isMultiple_mode()){
ACLMessage multiPlayUnregister = new ACLMessage(ACLMessage.SUBSCRIBE);
multiPlayUnregister.setConversationId("unregister");
multiPlayUnregister.setSender(myAgent.getAID());
multiPlayUnregister.addReceiver(myAgent.getServerName());
multiPlayUnregister.setContent("getting out");
myAgent.send(multiPlayUnregister);
done=true;
}
MessageTemplate mt =
MessageTemplate.and(MessageTemplate.MatchConversationId("updateDICT"),
MessageTemplate.MatchPerformative(ACLMessage.INFORM));
ACLMessage update_message = myAgent.receive(mt);
if(update_message!=null){
System.out.println("receive update dict");
if(update_message.getPerformative()==ACLMessage.INFORM){
try {
myAgent.setDict((DefaultListModel<String>)update_message.getContentObject());
} catch (UnreadableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
示例10: setup
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
protected void setup() {
MessageTemplate informOrConfirm =
MessageTemplate.or(MessageTemplate.MatchPerformative(ACLMessage.INFORM),
MessageTemplate.MatchPerformative(ACLMessage.CONFIRM));
MessageTemplate mt =
MessageTemplate.and(informOrConfirm,
MessageTemplate.MatchOntology(WmiiOntology.ONTOLOGY_NAME));
addBehaviour(new MessageReceiverFacade(this, this, mt));
subscribeToEvents();
}
示例11: templateAssemble
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
public static MessageTemplate templateAssemble(MessageTemplate ... templates)
{
MessageTemplate result = null;
for(MessageTemplate part : templates)
if(result == null)
result = part;
else
result = MessageTemplate.and(result, part);
return result;
}
示例12: moveToContainer
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
public void moveToContainer(String containerName)
{
myAgent.getContentManager().registerLanguage(new SLCodec());
myAgent.getContentManager().registerOntology(MobilityOntology.getInstance());
try {
Hashtable<String, Location> locations = new Hashtable<String, Location>();
// Get available locations with AMS
sendRequest(new Action(myAgent.getAMS(), new QueryPlatformLocationsAction()));
//Receive response from AMS
MessageTemplate mt = MessageTemplate.and(
MessageTemplate.MatchSender(myAgent.getAMS()),
MessageTemplate.MatchPerformative(ACLMessage.INFORM));
ACLMessage resp = myAgent.blockingReceive(mt);
ContentElement ce = myAgent.getContentManager().extractContent(resp);
Result result = (Result) ce;
jade.util.leap.Iterator it = result.getItems().iterator();
while (it.hasNext()) {
Location loc = (Location)it.next();
locations.put(loc.getName(), loc);
}
Location dest = locations.get(containerName);
myAgent.doMove(dest);
}
catch (Exception e) { e.printStackTrace(); }
}
示例13: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的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;
}
}
示例14: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
public void action() {
MessageTemplate filtre = MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.INFORM),
MessageTemplate.MatchConversationId("BACKGROUND"));
ACLMessage request = myAgent.receive(filtre);
if(request != null) {
ObjectMapper mapper = new ObjectMapper();
try {
BackgroundMusicData data = mapper.readValue(request.getContent(), BackgroundMusicData.class);
switch(data.getAction()) {
case START_BACKGROUND:
player.Start();
break;
case PAUSE_BACKGROUND:
player.Pause();
break;
case RESTART_BACKGROUND:
player.Restart();
break;
case STOP_BACKGROUND:
player.Stop();
break;
case CHANGE_BACKGROUND:
if (player!=null){
player.Stop();
player=null;
}
player = MusicPlayer.getMusicPlayer("effect/short.mp3");
player.Start();
player = MusicPlayer.getMusicPlayer(data.getPath());
break;
case CHANGE_VOLUME:
player.SetVolume(data.getVolume());
break;
case DEFAULT:
break;
default:
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
else
block();
}
示例15: action
import jade.lang.acl.MessageTemplate; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void action() {
if (first_run) {
AID server_name = myAgent.getServerName();
if(server_name !=null){
msg.addReceiver(server_name);
msg.setContent("listGroup");
myAgent.send(msg);
System.out.println("getlistgroupbehaviour envoie demande au multiAgent\n");
first_run = false;
} else {
System.out.println("server not found, retry...");
}
} else {
MessageTemplate mt = MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.INFORM),
MessageTemplate.MatchConversationId(Constance.GROUP_CREATED));
ACLMessage message= myAgent.receive(mt);
if(message!=null){
/*String[] list=message.getContent().split(",");
DefaultListModel<String> dict=new DefaultListModel<String>();
for(String s:list){
dict.addElement(s);
}*/
//myAgent.setDict(dict);
System.out.println("userAgent recu et refresh list\n");
try {
myAgent.setDict((DefaultListModel<String>)message.getContentObject());
//myAgent.getRoom_view().getList_room().setModel((DefaultListModel<String>) message.getContentObject());
done = true;
} catch (UnreadableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}