Ejemplo n.º 1
0
 protected ACLMessage prepareResultNotification(ACLMessage request, ACLMessage response) {
   System.out.println(controller.getLocalName() + ": Replying with parameters");
   ACLMessage inform = request.createReply();
   inform.setPerformative(ACLMessage.INFORM);
   // send APS parameters
   try {
     // TODO Check if myParams has been filled
     myAgent.getContentManager().fillContent(inform, controller.getMyParams());
     // subscribing to the Power Producer for daily plans commands
     myAgent.addBehaviour(new PowerPlansSubscriptionBehaviour(controller, request.getSender()));
   } catch (CodecException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (OntologyException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return inform;
 }
Ejemplo n.º 2
0
  private Location parseAMSResponse(ACLMessage response) {
    Result results = null;

    try {
      results = (Result) getContentManager().extractContent(response);
    } catch (UngroundedException e) {
      e.printStackTrace();
    } catch (CodecException e) {
      e.printStackTrace();
    } catch (OntologyException e) {
      e.printStackTrace();
    }

    Iterator it = results.getItems().iterator();

    Location loc = null;

    if (it.hasNext()) loc = (Location) it.next();

    return loc;
  }
Ejemplo n.º 3
0
  private ACLMessage prepareRequest(AID agent) {
    ACLMessage request = new ACLMessage(ACLMessage.REQUEST);
    request.addReceiver(getAMS());
    request.setLanguage(FIPANames.ContentLanguage.FIPA_SL0);
    request.setOntology(MobilityOntology.NAME);
    request.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);

    Action act = new Action();
    act.setActor(getAMS());

    WhereIsAgentAction action = new WhereIsAgentAction();
    action.setAgentIdentifier(agent);
    act.setAction(action);

    try {
      getContentManager().fillContent(request, act);
    } catch (CodecException e) {
      e.printStackTrace();
    } catch (OntologyException e) {
      e.printStackTrace();
    }

    return request;
  }
  protected ACLMessage prepareResultNotification(ACLMessage msg, ACLMessage response)
      throws FailureException {
    boolean performed = false;
    ContentElement content;
    Concept action = null;

    System.out.println("pRN");

    try {
      content = myAgent.getContentManager().extractContent(msg);
      action = ((Action) content).getAction();

      if (action instanceof AssignPowerRequest) {
        AssignPowerRequest apr = (AssignPowerRequest) action;
        System.out.println("Performing AssignPowerRequest");
        System.out.println("Requester assigned power: " + apr.getAssignedPower());
        if (windTurbine.setAssignedPower(apr.getAssignedPower())) {
          System.out.println("Check passed, power assigned");
          performed = true;
        } else {
          System.out.println("Out of bounds, power not assigned");
          performed = false;
        }
      }

      if (action instanceof BeginPowerTransitionRequest) {
        BeginPowerTransitionRequest bptr = (BeginPowerTransitionRequest) action;
        boolean isOk = true;
        System.out.println("Performing BeginPowerTransitionRequest");
        if (bptr.getAssignedPowerIsValid()) {
          System.out.println("Requester assigned power: " + bptr.getAssignedPower());
          if (windTurbine.setAssignedPower(bptr.getAssignedPower())) {
            System.out.println("Check passed, power assigned");
          } else {
            System.out.println("Out of bounds, power not assigned");
            isOk = false;
          }
        } else {
          System.out.println("Requester did not assigned new power");
        }

        if (isOk) {
          windTurbine.change_power();
        }

        performed = isOk;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (performed) {
      ACLMessage inform = msg.createReply();
      Message sm = new Message();
      TimeDelay td = new TimeDelay();
      td.setTime(windTurbine.time_delay());
      System.out.println(
          "Agent "
              + myAgent.getLocalName()
              + ": Action successfully performed, time delay is "
              + windTurbine.time_delay());
      sm.setMsg(td);
      try {
        myAgent.getContentManager().fillContent(inform, new Action(msg.getSender(), sm));
      } catch (CodecException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (OntologyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      inform.setPerformative(ACLMessage.INFORM);
      return inform;
    } else {
      throw new FailureException("out of bounds");
    }
  }