Beispiel #1
0
 // #APIDOC_EXCLUDE_BEGIN
 public static void notifyFailureToSender(ACLMessage msg, String sender, String error) {
   if (myFrontEnd != null) {
     // Send back a failure message
     try {
       Iterator it = msg.getAllReceiver();
       while (it.hasNext()) {
         AID receiver = (AID) it.next();
         // If this receiver is local, the message has certainly been delivered
         // successfully --> Do not send any FAILURE back for this receiver
         if (myFrontEnd.getLocalAgent(receiver.getLocalName()) == null) {
           ACLMessage failure = msg.createReply();
           failure.setPerformative(ACLMessage.FAILURE);
           failure.setSender(myFrontEnd.getAMS());
           failure.setLanguage(FIPANames.ContentLanguage.FIPA_SL);
           String content = "( (action " + sender;
           content = content + " (ACLMessage) ) (MTS-error " + receiver + " \"" + error + "\") )";
           failure.setContent(content);
           myFrontEnd.messageIn(failure, sender);
         }
       }
     } catch (Exception e1) {
       logger.log(Logger.SEVERE, "Error delivering FAILURE message.", e1);
     }
   }
 }
    protected void setup() {
      Object[] args = getArguments();
      if (args != null && args.length == 1) {
        myReceiver = new AID((String) args[0], AID.ISLOCALNAME);
      } else {
        System.out.println("Missing receiver name !!!!!");
        doDelete();
        return;
      }
      msg.addReceiver(myReceiver);
      msg.setByteSequenceContent(content);
      myTemplate = MessageTemplate.MatchSender(myReceiver);

      System.out.println(
          "RTT-Sender " + getName() + " ready: my receiver is " + myReceiver.getName());
      notifyReady();

      if (timeInterval > 0) {
        addBehaviour(
            new TickerBehaviour(this, timeInterval) {
              public void onTick() {
                job();
              }
            });
      } else {
        addBehaviour(
            new CyclicBehaviour(this) {
              public void run() {
                job();
              }
            });
      }
    }
Beispiel #3
0
 private boolean isExplicitReceiver(ACLMessage msg, AID receiver) {
   Iterator it = msg.getAllIntendedReceiver();
   while (it.hasNext()) {
     if (receiver.equals(it.next())) {
       return true;
     }
   }
   return false;
 }
Beispiel #4
0
  /**
   * Dispatch a message to an agent in the FrontEnd. If this method is called by a thread that is
   * serving a message sent by an agent in the FrontEnd too, nothing is done as the dispatch has
   * already taken place in the FrontEnd (see messageOut()).
   */
  public boolean postMessageToLocalAgent(ACLMessage msg, AID receiverID) {

    // Try first in the LADT
    boolean found = super.postMessageToLocalAgent(msg, receiverID);
    if (found) {
      return found;
    } else {
      // The receiver must be in the FrontEnd
      AgentImage image = (AgentImage) agentImages.get(receiverID);
      if (image != null) {
        if (agentImages.containsKey(msg.getSender()) && isExplicitReceiver(msg, receiverID)) {
          // The message was sent by an agent living in the FrontEnd. The
          // receiverID (living in the FrontEnd too) has already received
          // the message.
          // The second part of the condition ensures that, if the
          // message was not directly sent to the receiver (e.g. it was sent to a topic
          // or an alias), message delivery occurs normally.
          // FIXME: This does not take into account that an agent not living
          // in the FrontEnd may send a message on behalf of an agent living
          // in the FrontEnd.
          return true;
        }

        try {
          // Forward the message to the FrontEnd
          int size;
          if (msg.hasByteSequenceContent()) {
            size = msg.getByteSequenceContent().length;
          } else {
            size = msg.getContent() != null ? msg.getContent().length() : 0;
          }
          myLogger.log(
              Logger.INFO,
              getID()
                  + " - Delivering IN message "
                  + ACLMessage.getPerformative(msg.getPerformative())
                  + ", size="
                  + size);
          myFrontEnd.messageIn(msg, receiverID.getLocalName());
          handlePosted(receiverID, msg);
          return true;
        } catch (NotFoundException nfe) {
          System.out.println("WARNING: Missing agent in FrontEnd");
          return false;
        } catch (IMTPException imtpe) {
          System.out.println("WARNING: Can't deliver message to FrontEnd");
          return false;
        }
      } else {
        // Agent not found
        System.out.println("WARNING: Agent " + receiverID + " not found on BackEnd container");
        return false;
      }
    }
  }
Beispiel #5
0
 /** An agent has just died on the FrontEnd. Remove its image and notify the Main */
 public void deadAgent(String name) throws IMTPException {
   AID id = new AID(name, AID.ISLOCALNAME);
   myLogger.log(Logger.INFO, getID() + " - Handling termination of agent " + id.getLocalName());
   handleEnd(id);
 }
Beispiel #6
0
  public boolean connect() {
    try {
      // Initialize the BackEndManager if required
      if (myProfile.getBooleanProperty(USE_BACKEND_MANAGER, false)) {
        theBEManager = initBEManager();
      }

      Vector agentSpecs =
          Specifier.parseSpecifierList(myProfile.getParameter(Profile.AGENTS, null));
      myProfile.setParameter(Profile.AGENTS, null);

      myFrontEnd = myConnectionManager.getFrontEnd(this, null);
      myLogger.log(
          Logger.FINE,
          "BackEnd container "
              + myProfile.getParameter(Profile.CONTAINER_NAME, null)
              + " joining the platform ... (FrontEnd version: "
              + myProfile.getParameter(JICPProtocol.VERSION_KEY, "not available")
              + ")");

      Runtime.instance().beginContainer();
      boolean connected = joinPlatform();
      if (connected) {
        myLogger.log(Logger.FINE, "Join platform OK");
        AID amsAID = getAMS();
        myProfile.setParameter(Profile.PLATFORM_ID, amsAID.getHap());
        String[] addresses = amsAID.getAddressesArray();
        if (addresses != null) {
          StringBuffer sb = new StringBuffer();
          for (int i = 0; i < addresses.length; i++) {
            sb.append(addresses[i]);
            if (i < addresses.length - 1) {
              sb.append(';');
            }
          }
          myProfile.setParameter(MicroRuntime.PLATFORM_ADDRESSES_KEY, sb.toString());
        }
        if ("true".equals(myProfile.getParameter(RESYNCH, "false"))) {
          myLogger.log(
              Logger.INFO,
              "BackEnd container "
                  + myProfile.getParameter(Profile.CONTAINER_NAME, null)
                  + " activating re-synch ...");
          resynch();
        } else {
          // Notify the main container about bootstrap agents on the FE.
          for (int i = 0; i < agentSpecs.size(); i++) {
            Specifier sp = (Specifier) agentSpecs.elementAt(i);
            try {
              String name = bornAgent(sp.getName());
              sp.setClassName(name);
              sp.setArgs(null);
            } catch (Exception e) {
              myLogger.log(Logger.SEVERE, "Error creating agent " + sp.getName(), e);
              sp.setClassName(e.getClass().getName());
              sp.setArgs(new Object[] {e.getMessage()});
            }
          }
          myProfile.setParameter(Profile.AGENTS, Specifier.encodeSpecifierList(agentSpecs));
        }
      }
      return connected;
    } catch (Exception e) {
      // Should never happen
      e.printStackTrace();
      return false;
    }
  }