void replyNotUnderstood(ACLMessage msg) {
    // -----------------------------------------

    try {
      ContentElement content = getContentManager().extractContent(msg);
      ACLMessage reply = msg.createReply();
      reply.setPerformative(ACLMessage.NOT_UNDERSTOOD);
      getContentManager().fillContent(reply, content);
      send(reply);
      System.out.println("Not understood!");
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
 public void action() {
   // Receives information about people joining and leaving
   // the chat from the ChatManager agent
   ACLMessage msg = myAgent.receive(template);
   if (msg != null) {
     if (msg.getPerformative() == ACLMessage.INFORM) {
       try {
         AbsPredicate p = (AbsPredicate) myAgent.getContentManager().extractAbsContent(msg);
         if (p.getTypeName().equals(ChatOntology.JOINED)) {
           // Get new participants, add them to the list of participants
           // and notify the gui
           AbsAggregate agg = (AbsAggregate) p.getAbsTerm(ChatOntology.JOINED_WHO);
           if (agg != null) {
             Iterator it = agg.iterator();
             while (it.hasNext()) {
               AbsConcept c = (AbsConcept) it.next();
               participants.add(BasicOntology.getInstance().toObject(c));
             }
           }
           myGui.notifyParticipantsChanged(getParticipantNames());
         }
         if (p.getTypeName().equals(ChatOntology.LEFT)) {
           // Get old participants, remove them from the list of participants
           // and notify the gui
           AbsAggregate agg = (AbsAggregate) p.getAbsTerm(ChatOntology.JOINED_WHO);
           if (agg != null) {
             Iterator it = agg.iterator();
             while (it.hasNext()) {
               AbsConcept c = (AbsConcept) it.next();
               participants.remove(BasicOntology.getInstance().toObject(c));
             }
           }
           myGui.notifyParticipantsChanged(getParticipantNames());
         }
       } catch (Exception e) {
         Logger.println(e.toString());
         e.printStackTrace();
       }
     } else {
       handleUnexpected(msg);
     }
   } else {
     block();
   }
 }
Example #3
0
  /**
   * The main is here only for debugging. You can test your conversion by executing the following
   * command:
   *
   * <p><code> java jade.lang.acl.ISO8601 <yourtoken> </code>
   */
  public static void main(String argv[]) {

    System.out.println(localCal);

    System.out.println("USAGE: java ISO8601 DateTimetoken");
    System.out.println(argv[0]);
    try {
      System.out.println("Testing default behaviour (using UTC DateTime):");
      System.out.println("  ISO8601.toDate(" + argv[0] + ") returns:" + ISO8601.toDate(argv[0]));
      System.out.println(
          "  converting that back to a string gives:" + ISO8601.toString(ISO8601.toDate(argv[0])));
      Date d1 = new Date();
      System.out.println("  ISO8601.toString( new Date() ) returns:" + ISO8601.toString(d1));
      System.out.println(
          "  converting that back to a date gives:" + ISO8601.toDate(ISO8601.toString(d1)));

      System.out.println("Testing local time (for backwards compatability):");
      // ISO8601.useUTCtime = false;
      System.out.println("  ISO8601.toDate(" + argv[0] + ") returns:" + ISO8601.toDate(argv[0]));
      System.out.println(
          "  converting that back to a string gives:"
              + ISO8601.toString(ISO8601.toDate(argv[0]), false));
      System.out.println(
          "  ISO8601.toString( new Date(), false ) returns:" + ISO8601.toString(d1, false));
      System.out.println(
          "  converting that back to a date gives:" + ISO8601.toDate(ISO8601.toString(d1, false)));
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      System.out.println(
          "ISO8601.toRelativeTimeString("
              + argv[0]
              + ") returns:"
              + ISO8601.toRelativeTimeString(Long.parseLong(argv[0])));

      Date d = new Date(Integer.parseInt(argv[0]));
      System.out.println(
          "ISO8601.toString(" + d + ", false) returns:" + ISO8601.toString(d, false));
    } catch (Exception e1) {
    }
  }
    public void action() {

      try {
        ContentElement content = getContentManager().extractContent(query);
        Information info = (Information) ((Action) content).getAction();
        Object obj = processInformation(info);
        if (obj == null) replyNotUnderstood(query);
        else {
          ACLMessage reply = query.createReply();
          reply.setPerformative(ACLMessage.INFORM);
          Result result = new Result((Action) content, obj);
          getContentManager().fillContent(reply, result);
          send(reply);
          System.out.println("Information processed.");
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
    public void action() {

      try {
        ContentElement content = getContentManager().extractContent(request);
        CreateAccount ca = (CreateAccount) ((Action) content).getAction();
        Account acc = new Account();
        String id = generateId();
        acc.setId(id);
        acc.setName(ca.getName());
        Result result = new Result((Action) content, acc);
        ACLMessage reply = request.createReply();
        reply.setPerformative(ACLMessage.INFORM);
        getContentManager().fillContent(reply, result);
        send(reply);
        accounts.put(id, acc);
        operations.put(id, new ArrayList());
        System.out.println("Account [" + acc.getName() + " # " + acc.getId() + "] created!");
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
    public void action() {

      ServiceDescription sd = new ServiceDescription();
      sd.setType(SERVER_AGENT);
      sd.setName(getName());
      sd.setOwnership("Prof6802");
      DFAgentDescription dfd = new DFAgentDescription();
      dfd.setName(getAID());
      dfd.addServices(sd);
      try {
        DFAgentDescription[] dfds = DFService.search(myAgent, dfd);
        if (dfds.length > 0) {
          DFService.deregister(myAgent, dfd);
        }
        DFService.register(myAgent, dfd);
        System.out.println(getLocalName() + " is ready.");
      } catch (Exception ex) {
        System.out.println("Failed registering with DF! Shutting down...");
        ex.printStackTrace();
        doDelete();
      }
    }
    public void action() {

      ACLMessage msg = receive();
      if (msg == null) {
        block();
        return;
      }
      try {
        ContentElement content = getContentManager().extractContent(msg);
        Concept action = ((Action) content).getAction();

        switch (msg.getPerformative()) {
          case (ACLMessage.REQUEST):
            System.out.println("Request from " + msg.getSender().getLocalName());

            if (action instanceof CreateAccount)
              addBehaviour(new HandleCreateAccount(myAgent, msg));
            else if (action instanceof MakeOperation)
              addBehaviour(new HandleOperation(myAgent, msg));
            else replyNotUnderstood(msg);
            break;

          case (ACLMessage.QUERY_REF):
            System.out.println("Query from " + msg.getSender().getLocalName());

            if (action instanceof Information) addBehaviour(new HandleInformation(myAgent, msg));
            else replyNotUnderstood(msg);
            break;

          default:
            replyNotUnderstood(msg);
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }