Package jade.lang.acl

Examples of jade.lang.acl.ACLMessage


    else {
      throw new UnsupportedFunction();
    }

    // Prepare the notification
    ACLMessage notification = request.createReply();
    notification.setPerformative(ACLMessage.INFORM);
    Predicate p = null;
    if (resultNeeded) {
      // The action produced a result
      p = new Result(slAction, result);
    }
View Full Code Here


      listenSniffTemplate = MessageTemplate.MatchConversationId(getName() + "-event");
    }

    public void action() {

      ACLMessage current = receive(listenSniffTemplate);
      if(current != null) {

        try {
          Occurred o = (Occurred)getContentManager().extractContent(current);
          EventRecord er = o.getWhat();
          Event ev = er.getWhat();
          String content = null;
          Envelope env = null;
          AID unicastReceiver = null;
          if(ev instanceof SentMessage) {
            content = ((SentMessage)ev).getMessage().getPayload();
            env = ((SentMessage)ev).getMessage().getEnvelope();
            unicastReceiver = ((SentMessage)ev).getReceiver();
          } else if(ev instanceof PostedMessage) {
            content = ((PostedMessage)ev).getMessage().getPayload();
            env = ((PostedMessage)ev).getMessage().getEnvelope();
            unicastReceiver = ((PostedMessage)ev).getReceiver();
            AID sender = ((PostedMessage)ev).getSender();
            // If the sender is currently under sniff, then the message was already
            // displayed when the 'sent-message' event occurred --> just skip this message.
            if(agentsUnderSniff.contains(new Agent(sender))) {
              return;
            }
          } else {
            return;
          }

          ACLCodec codec = new StringACLCodec();
          String charset = null
          if ((env == null) || ((charset = env.getPayloadEncoding()) == null)) {
            charset = ACLCodec.DEFAULT_CHARSET;
          }
          ACLMessage tmp = codec.decode(content.getBytes(charset),charset);
          tmp.setEnvelope(env);
          Message msg = new Message(tmp, unicastReceiver);

          /* If this is a 'posted-message' event and the sender is
          // currently under sniff, then the message was already
          // displayed when the 'sent-message' event occurred. In that
View Full Code Here

          // This message is directed to a Topic
          AID topic = receiver;
          if (myLogger.isLoggable(Logger.FINE)) {
            myLogger.log(Logger.FINE, "Handling message about topic "+topic.getLocalName());
          }
          ACLMessage msg = gMsg.getACLMessage();
          Collection interestedAgents = topicTable.getInterestedAgents(topic, msg);
          if (interestedAgents.size() > 0) {
            // Forward the message to all agents interested in that topic.
            // Note that if no agents are currently listening to this topic, the message is simply swallowed
            msg.addUserDefinedParameter(ACLMessage.IGNORE_FAILURE, "true");
            gMsg.setModifiable(false);
            Iterator it = interestedAgents.iterator();
            while (it.hasNext()) {
              AID target = (AID) it.next();
              if (myLogger.isLoggable(Logger.FINE)) {
View Full Code Here

      // We serve REQUEST messages refering to the JADE Management Ontology
      super(Sniffer.this, MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.REQUEST),MessageTemplate.MatchOntology(JADEManagementOntology.NAME)));
    }

    protected ACLMessage prepareResponse (ACLMessage request) {
      ACLMessage response = request.createReply();
      try {     
        requestAction = (Action) getContentManager().extractContent(request);
        aa = (AgentAction) requestAction.getAction();
        if (aa instanceof SniffOn || aa instanceof SniffOff) {
          if (getAID().equals(requestAction.getActor())) {
            response.setPerformative(ACLMessage.AGREE);
            response.setContent(request.getContent());
          }
          else {
            response.setPerformative(ACLMessage.REFUSE);
            response.setContent("((unrecognised-parameter-value actor "+requestAction.getActor()+"))");
          }
        }
        else {
          response.setPerformative(ACLMessage.REFUSE)
          response.setContent("((unsupported-act "+aa.getClass().getName()+"))");
        }
      }
      catch (Exception e) {
        e.printStackTrace();
        response.setPerformative(ACLMessage.NOT_UNDERSTOOD)
      }
      return response;                            
    }
View Full Code Here

          removeAgent(aid);
        }
      }

      // Send back the notification
      ACLMessage result = request.createReply();
      result.setPerformative(ACLMessage.INFORM);
      Done d = new Done(requestAction);
      try {
        myAgent.getContentManager().fillContent(result, d);
      }
      catch (Exception e) {
View Full Code Here

      // If the CANCEL message has a meaningful content, use it.
      // Otherwise deregister the Subscription with the same convID (default)
      protected ACLMessage handleCancel(ACLMessage cancel) throws FailureException {
        try {
          Action act = (Action) myAgent.getContentManager().extractContent(cancel);
          ACLMessage subsMsg = (ACLMessage)act.getAction();
          Subscription s = getSubscription(subsMsg);
          if (s != null) {
            mySubscriptionManager.deregister(s);
            s.close();
          }
View Full Code Here

  /**
   Send the notification related to an action that has been processed
   by a Behaviour.
   */
  private void sendPendingNotification(Concept action, Object result) {
    ACLMessage request = (ACLMessage) pendingRequests.remove(action);
    if (request != null) {
      ACLMessage notification = request.createReply();
      ContentElement ce = null;
      Action act = new Action(getAID(), action);
      if (result instanceof InternalError) {
        // Some error occurred during action processing
        notification.setPerformative(ACLMessage.FAILURE);
        ContentElementList cel = new ContentElementList();
        cel.add(act);
        cel.add((Predicate) result);
        ce = cel;
      }
      else {
        // Action processing was OK
        notification.setPerformative(ACLMessage.INFORM);
        if (result != null) {
          ce = new Result(act, result);
        }
        else {
          ce = new Done(act);
        }
      }
      try {
        getContentManager().fillContent(notification, ce);
        send(notification);
        AID receiver = (AID) notification.getAllReceiver().next();
        if(logger.isLoggable(Logger.FINE))
          logger.log(Logger.FINE,"Notification sent back to "+receiver.getName());
      }
      catch (Exception e) {
        // Should never happen
View Full Code Here

      GenericMessage msg = (GenericMessage)params[0];
      AID receiver = (AID)params[1];
      InternalError ie = (InternalError)params[2];
     
      // The acl message contained inside the GenericMessage cannot be null; the notifyFailureToSender() method already checks that
      ACLMessage aclmsg = msg.getACLMessage();
      if((aclmsg.getSender()==null) || (aclmsg.getSender().equals(myContainer.getAMS()))) // sanity check to avoid infinite loops
        return;
     
      // Send back a failure message
      final ACLMessage failure = aclmsg.createReply();
      failure.setPerformative(ACLMessage.FAILURE);
      final AID theAMS = myContainer.getAMS();
      failure.setSender(theAMS);
      failure.setLanguage(FIPANames.ContentLanguage.FIPA_SL);
     
      // FIXME: the content is not completely correct, but that should
      // also avoid creating wrong content
      String content = "( (action " + msg.getSender().toString();
      content = content + " (ACLMessage) ) (MTS-error "+receiver+" "+ie.getMessage() + ") )";
      failure.setContent(content);
     
      try {
        GenericCommand command = new GenericCommand(MessagingSlice.SEND_MESSAGE, MessagingSlice.NAME, null);
        command.addParam(theAMS);
        GenericMessage gm = new GenericMessage(failure);
        gm.setAMSFailure(true);
        command.addParam(gm);
        command.addParam((AID)(failure.getAllReceiver().next()));
        // FIXME: We should set the AMS principal and credentials
       
        submit(command);
      }
      catch(ServiceException se) {
View Full Code Here

    /**
     We broadcast the search REQUEST to all children (federated) DFs in parallel.
     */
    protected Vector prepareRequests(ACLMessage request) {
      Vector requests = null;
      ACLMessage incomingRequest = (ACLMessage) pendingRequests.get(action);
      if (incomingRequest != null) {
        Date deadline = incomingRequest.getReplyByDate();
        if (deadline == null) {
          deadline = new Date(System.currentTimeMillis() + DEFAULTTIMEOUT);
        }
        requests = new Vector(children.size());
        Iterator it = children.iterator();
        while (it.hasNext()) {
          AID childDF = (AID) it.next();
          ACLMessage msg = DFService.createRequestMessage(myAgent, childDF, FIPAManagementVocabulary.SEARCH, template, constraints);
          msg.setReplyByDate(deadline);
          requests.addElement(msg);
        }
      }
      return requests;
    }
View Full Code Here

      throw new UnsupportedFunction();
    }
   
    if (!asynchNotificationRequired) {
      // The requested action has been completed. Prepare the notification
      ACLMessage notification = request.createReply();
      notification.setPerformative(ACLMessage.INFORM);
      Predicate p = null;
      if (result != null) {
        // The action produced a result
        p = new Result(slAction, result);
      }
View Full Code Here

TOP

Related Classes of jade.lang.acl.ACLMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.