Package jade.domain.FIPAAgentManagement

Examples of jade.domain.FIPAAgentManagement.Envelope


      if(gmsg.getPayload()==null){
        // If a real ACLMessage is present, just do nothing!
        return true;
      }
      else {
        Envelope env = gmsg.getEnvelope();
        byte[] payload = gmsg.getPayload();
        ACLMessage msg ;
        try{
          msg = decodeMessage(env,payload);
          msg.setEnvelope(env);
         
          if (env!=null){
            // If the 'sender' AID has no addresses, replace it with the
            // 'from' envelope slot
            AID sender = msg.getSender();
            if(sender == null) {
              System.err.println("ERROR: Trying to dispatch a message with a null sender.");
              System.err.println("Aborting send operation...");
              return true;
            }
            Iterator itSender = sender.getAllAddresses();
            if(!itSender.hasNext())
              msg.setSender(env.getFrom());
          }
          ((GenericMessage)params[1]).update(msg,null,null);
        } catch (MessagingService.UnknownACLEncodingException ee){
          ee.printStackTrace();
          cmd.setReturnValue(ee);
View Full Code Here


      }
     
      // Encode the message using the specified encoding
      try{
        byte[] payload = encodeMessage(msg);
        Envelope env =  msg.getEnvelope();
        if (env!=null)
          env.setPayloadLength(new Long(payload.length));
       
        // Update the ACLMessage: some information is kept because it is
        // required in other services
        ((GenericMessage)cmd.getParams()[1]).update(msg,env,payload);
       
View Full Code Here

 
  /**
   * This method puts into the envelope the missing information if required
   */
  public void prepareEnvelope(ACLMessage msg, AID receiver, GenericMessage gmsg) {
    Envelope env = msg.getEnvelope();
    String defaultRepresentation = null;
    if (myService.livesHere(receiver)) {
      // The agent lives in the platform
      if (env == null) {
        // Nothing to do
        return;
      }
      else {
        defaultRepresentation = LEAPACLCodec.NAME;
      }
    }
    else {
      // The agent lives outside the platform
      gmsg.setForeignReceiver(true);
      if (env == null) {
        msg.setDefaultEnvelope();
        env = msg.getEnvelope();
      }
      else {
        defaultRepresentation = StringACLCodec.NAME;
      }
    }
   
    // If no ACL representation is set, use the default one ("LEAP" for
    // local receivers and "String" for foreign receivers)
    String rep = env.getAclRepresentation();
    if(rep == null)
      env.setAclRepresentation(defaultRepresentation);
   
    // If no 'to' slot is present, copy the 'to' slot from the
    // 'receiver' slot of the ACL message
    Iterator itTo = env.getAllTo();
    if(!itTo.hasNext()) {
      Iterator itReceiver = msg.getAllReceiver();
      while(itReceiver.hasNext())
        env.addTo((AID)itReceiver.next());
    }
   
    // If no 'from' slot is present, copy the 'from' slot from the
    // 'sender' slot of the ACL message
    AID from = env.getFrom();
    if(from == null) {
      env.setFrom(msg.getSender());
    }
   
    // Set the 'date' slot to 'now' if not present already
    Date d = env.getDate();
    if(d == null)
      env.setDate(new Date());
   
    // Write 'intended-receiver' slot as per 'FIPA Agent Message
    // Transport Service Specification': this ACC splits all
    // multicasts, since JADE has already split them in the
    // handleSend() method
    env.clearAllIntendedReceiver();
    env.addIntendedReceiver(receiver);
   
    Long payloadLength = env.getPayloadLength();
    if(payloadLength == null)
      env.setPayloadLength(new Long(-1));
  }
View Full Code Here

   * @param msg the message to be encoded
   * @return the payload of the message
   */
  public byte[] encodeMessage(ACLMessage msg) throws MessagingService.UnknownACLEncodingException{
   
    Envelope env = msg.getEnvelope();
    String enc = (env != null ? env.getAclRepresentation() : LEAPACLCodec.NAME);
   
    if(enc != null) { // A Codec was selected
      ACLCodec codec =(ACLCodec)messageEncodings.get(enc.toLowerCase());
      if(codec!=null) {
        // Supported Codec
        // FIXME: should verify that the receivers supports this Codec
        String charset; 
        if ((env == null) ||
            ((charset = env.getPayloadEncoding()) == null)) {
          charset = ACLCodec.DEFAULT_CHARSET;
        }
        return codec.encode(msg,charset);
      }
      else {
View Full Code Here

   fill in the envelope.
   @see jade.lang.acl#setEnvelope(Envelope e)
   @see jade.lang.acl#getEnvelope()
   */
  public void setDefaultEnvelope() {
    messageEnvelope = new Envelope();
    messageEnvelope.setFrom(source);
    //#MIDP_EXCLUDE_BEGIN
    Iterator it = dests.iterator();
    //#MIDP_EXCLUDE_END
    /*#MIDP_INCLUDE_BEGIN
 
View Full Code Here

   last.
   */
  public Iterator getAllIntendedReceiver() {
    Iterator it = null;
    //#CUSTOM_EXCLUDE_BEGIN
    Envelope env = getEnvelope();
    if (env != null) {
      it = env.getAllIntendedReceiver();
      if (!it.hasNext()) {
        // The ":intended-receiver" field is empty --> try with the ":to" field
        it = env.getAllTo();
      }
    }
    //#CUSTOM_EXCLUDE_END
    if (it == null || !it.hasNext()) {
      // Both the ":intended-receiver" and the ":to" fields are empty -->
View Full Code Here

   */
  private void serializeACL(ACLMessage msg) throws IOException, LEAPSerializationException {
    LEAPACLCodec.serializeACL(msg, this);
    //#CUSTOM_EXCLUDE_BEGIN
    // NOTE that the above call does not serialize the envelope
    Envelope env = msg.getEnvelope();
    if (env != null) {
        writeBoolean(true);
        serializeEnvelope(env);
    }
    else {
View Full Code Here

TOP

Related Classes of jade.domain.FIPAAgentManagement.Envelope

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.