protected void handleInform(ACLMessage msg) {
    try {
      notYetReady = false;
      lastMsg = (ACLMessage) msg.clone();
      if (this.action.equalsIgnoreCase(DFAppletVocabulary.FEDERATE)) {
        gui.showStatusMsg("Request processed. Ready for new  request.");
        gui.addParent(this.parent);
      } else if (this.action.equalsIgnoreCase(DFAppletVocabulary.GETDESCRIPTION)) {
        // UPDATE the thisDf variable.
        try {
          List result = getResult();
          dfApplet.setDescription((DFAgentDescription) result.get(0));
        } catch (NotYetReady nyr) {
          // FIXME: what should happen in this case ?
          nyr.printStackTrace();
        }
      } else if (this.action.equalsIgnoreCase(DFAppletVocabulary.GETPARENTS))
        gui.showStatusMsg("Request processed. Ready for new Request.");
      else if (this.action.equalsIgnoreCase(DFAppletVocabulary.DEREGISTERFROM)) {
        gui.showStatusMsg("Request processed. Ready for a new request");
        gui.removeParent(this.parent);
      } else if (this.action.equalsIgnoreCase(DFAppletVocabulary.REGISTERWITH))
        gui.showStatusMsg("Request processed. Ready for new request.");
      else if (this.action.equalsIgnoreCase(DFAppletVocabulary.SEARCHON)) {
        gui.refreshLastSearchResults(getResult(), (AID) parent);
        gui.showStatusMsg("Request processed. Ready for new request.");
      } else if (this.action.equalsIgnoreCase(DFAppletVocabulary.MODIFYON))
        gui.showStatusMsg("Request processed. Ready for new request.");

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 protected void handleAgree(ACLMessage msg) {
   try {
     lastMsg = (ACLMessage) msg.clone();
     gui.showStatusMsg("Process your request & waiting for result...");
   } catch (Exception e) {
   }
 }
 protected void handleFailure(ACLMessage msg) {
   try {
     notYetReady = false;
     lastMsg = (ACLMessage) msg.clone();
     gui.showStatusMsg("Request refused.");
     // FIXME: if no default description returned what should happen ?
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 4
0
 /**
  * Sets the Message attribute of the MessageNode object
  *
  * @param msg The new Message value
  */
 public void setMessage(ACLMessage msg) {
   theMessage = (ACLMessage) msg.clone();
 }
  /**
   * @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();
    }
  }
 protected void handleRefuse(ACLMessage msg) {
   notYetReady = false;
   lastMsg = (ACLMessage) msg.clone();
 }
 protected void handleNotUnderstood(ACLMessage msg) {
   notYetReady = false;
   lastMsg = (ACLMessage) msg.clone();
 }