Ejemplo 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();
    }
  }
Ejemplo 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();
      }
    }
Ejemplo 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();
      }
    }
Ejemplo n.º 4
0
    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();
      }
    }
Ejemplo n.º 5
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();
      }
    }