Esempio n. 1
0
  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();
    }
  }
Esempio n. 2
0
    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();
      }
    }
Esempio n. 3
0
    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();
      }
    }
Esempio n. 4
0
    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();
      }
    }