/** * create a new ACLMessage that is a reply to this message. In particular, it sets the following * parameters of the new message: receiver, language, ontology, protocol, conversation-id, * in-reply-to, reply-with. The programmer needs to set the communicative-act and the content. Of * course, if he wishes to do that, he can reset any of the fields. * * @return the ACLMessage to send as a reply */ public ACLMessage createReply() { ACLMessage m = new ACLMessage(getPerformative()); Iterator it = getAllReplyTo(); while (it.hasNext()) m.addReceiver((AID) it.next()); if ((reply_to == null) || reply_to.isEmpty()) m.addReceiver(getSender()); m.setLanguage(getLanguage()); m.setOntology(getOntology()); m.setProtocol(getProtocol()); m.setInReplyTo(getReplyWith()); if (source != null) m.setReplyWith(source.getName() + java.lang.System.currentTimeMillis()); else m.setReplyWith("X" + java.lang.System.currentTimeMillis()); m.setConversationId(getConversationId()); // Copy only well defined user-def-params String trace = getUserDefinedParameter(TRACE); if (trace != null) { m.addUserDefinedParameter(TRACE, trace); } // #CUSTOM_EXCLUDE_BEGIN // Set the Aclrepresentation of the reply message to the aclrepresentation of the sent message if (messageEnvelope != null) { m.setDefaultEnvelope(); String aclCodec = messageEnvelope.getAclRepresentation(); if (aclCodec != null) m.getEnvelope().setAclRepresentation(aclCodec); } else m.setEnvelope(null); // #CUSTOM_EXCLUDE_END return m; }
public void requestSwapAppointments() { String conversationId = "request-swap"; if (patientAgent.highPriorityAppointmentOwner != null) { System.out.println( patientAgent.getName() + " proposing to swap slot " + (patientAgent.allocatedAppointment + 1) + " with " + (patientAgent.swapSlot + 1)); ACLMessage request = new ACLMessage(ACLMessage.PROPOSE); request.addReceiver(patientAgent.highPriorityAppointmentOwner); try { request.setContentObject( new SwapInfo(patientAgent.allocatedAppointment, patientAgent.swapSlot)); } catch (IOException e) { e.printStackTrace(); } request.setSender(patientAgent.getAID()); request.setConversationId(conversationId); request.setReplyWith(conversationId + " " + System.currentTimeMillis()); patientAgent.send(request); reqTemplate = MessageTemplate.and( MessageTemplate.MatchConversationId(conversationId), MessageTemplate.MatchInReplyTo(request.getReplyWith())); state = 1; } }
private void informHospital(AID swapPatientAgentAID, int currentSlot, int swapSlot) throws IOException { String conversationId = "inform-swap-to-hospital"; ACLMessage request = new ACLMessage(ACLMessage.INFORM); request.addReceiver(patientAgent.allocationAgent); request.setSender(patientAgent.getAID()); request.setContentObject(new SwapInfoForHospital(currentSlot, swapSlot, swapPatientAgentAID)); request.setConversationId(conversationId); request.setReplyWith(conversationId + " " + System.currentTimeMillis()); System.out.println(patientAgent.getAID().getName() + " sending confirmation to hospital"); patientAgent.send(request); }
/** * @param out * @param parser * @param sender the sender of the message * @param receiver the receiver of the message * @param actionName the action requested * @param parentDF the df to wich request an action (used for federate action) */ JADEAppletRequestProto( DFAppletCommunicator communicator, AID receiver, String actionName, Object description, Object parentDF, SearchConstraints constraints) throws FIPAException { super(communicator.getStream(), communicator.getParser(), new ACLMessage(ACLMessage.REQUEST)); this.gui = communicator.getGUI(); this.dfApplet = communicator; ACLMessage request = new ACLMessage(ACLMessage.REQUEST); // request.setSender(sender); request.addReceiver(receiver); request.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST); request.setLanguage(FIPANames.ContentLanguage.FIPA_SL); request.setOntology(DFAppletOntology.NAME); request.setReplyWith("rw" + (new Date()).getTime()); request.setConversationId("conv" + (new Date()).getTime()); this.reqMsg = (ACLMessage) request.clone(); this.action = actionName; this.receiver = receiver; this.parent = (AID) parentDF; Action act = new Action(); act.setActor(receiver); if (actionName.equalsIgnoreCase(DFAppletVocabulary.FEDERATE)) { Federate action = new Federate(); action.setDf((AID) parentDF); action.setDescription((DFAgentDescription) description); act.setAction(action); } else if (actionName.equalsIgnoreCase(DFAppletVocabulary.GETDESCRIPTION)) act.setAction(new GetDescription()); else if (actionName.equalsIgnoreCase(DFAppletVocabulary.GETPARENTS)) act.setAction(new GetParents()); else if (actionName.equalsIgnoreCase(DFAppletVocabulary.GETDESCRIPTIONUSED)) { GetDescriptionUsed action = new GetDescriptionUsed(); action.setParentDF((AID) parentDF); act.setAction(action); } else if (actionName.equalsIgnoreCase(DFAppletVocabulary.DEREGISTERFROM)) { DeregisterFrom action = new DeregisterFrom(); action.setDf((AID) parentDF); action.setDescription((DFAgentDescription) description); act.setAction(action); } else if (actionName.equalsIgnoreCase(DFAppletVocabulary.REGISTERWITH)) { RegisterWith action = new RegisterWith(); action.setDf((AID) parentDF); action.setDescription((DFAgentDescription) description); act.setAction(action); } else if (actionName.equalsIgnoreCase(DFAppletVocabulary.SEARCHON)) { SearchOn action = new SearchOn(); action.setDf((AID) parentDF); action.setDescription((DFAgentDescription) description); action.setConstraints(constraints); act.setAction(action); } else if (actionName.equalsIgnoreCase(DFAppletVocabulary.MODIFYON)) { ModifyOn action = new ModifyOn(); action.setDf((AID) parentDF); action.setDescription((DFAgentDescription) description); act.setAction(action); } else throw new UnsupportedFunction(); // initialize SL0 Codec and FIPAAgentManagementOntology // FIXME for applet I have not the agent c = sender.lookupLanguage(SL0Codec.NAME); // if (c == null) c = new SLCodec(); // Write the action in the :content slot of the request List content = new ArrayList(); content.add(act); try { String s = ((SLCodec) c).encode(o, (AbsContentElement) o.fromObject(act)); this.reqMsg.setContent(s); } catch (OntologyException oe) { oe.printStackTrace(); throw new FIPAException("Ontology error: " + oe.getMessage()); } catch (Exception e) { e.printStackTrace(); } }