private void bornAgent(
        AID name, ContainerID cid, JADEPrincipal principal, Credentials credentials)
        throws NameClashException, NotFoundException {
      MainContainer impl = myContainer.getMain();
      if (impl != null) {
        // Retrieve the ownership from the credentials
        String ownership = "NONE";
        if (credentials != null) {
          JADEPrincipal ownerPr = credentials.getOwner();
          if (ownerPr != null) {
            ownership = ownerPr.getName();
          }
        }
        try {
          // If the name is already in the GADT, throws NameClashException
          impl.bornAgent(name, cid, principal, ownership, false);
        } catch (NameClashException nce) {
          // #CUSTOMJ2SE_EXCLUDE_BEGIN
          try {
            ContainerID oldCid = impl.getContainerID(name);
            if (oldCid != null) {
              Node n = impl.getContainerNode(oldCid).getNode();

              // Perform a non-blocking ping to check...
              n.ping(false);

              // Ping succeeded: rethrow the NameClashException
              throw nce;
            } else {
              // The old agent is registered with the AMS, but does not live in the platform -->
              // cannot check if it still exists
              throw nce;
            }
          } catch (NameClashException nce2) {
            // This is the re-thrown NameClashException --> let it through
            throw nce2;
          } catch (Exception e) {
            // Either the old agent disappeared in the meanwhile or the Ping failed: forcibly
            // replace the old agent...
            impl.bornAgent(name, cid, principal, ownership, true);
          }
          // #CUSTOMJ2SE_EXCLUDE_END
          /*#CUSTOMJ2SE_INCLUDE_BEGIN
          try {
          //System.out.println("Replacing old agent "+name.getName());
           if(myLogger.isLoggable(Logger.INFO))
           myLogger.log(Logger.INFO,"Replacing old agent "+name.getName());
           dyingAgents.add(name);
           ((jade.core.AgentManager) impl).kill(name, principal, credentials);
           waitUntilDead(name);
           impl.bornAgent(name, cid, principal, ownership, false);
           }
           catch (Exception e) {
           dyingAgents.remove(name);
           impl.bornAgent(name, cid, principal, ownership, true);
           }
           #CUSTOMJ2SE_INCLUDE_END*/
        }
      }
    }
    private void handleRequestStateChange(VerticalCommand cmd)
        throws IMTPException, JADESecurityException, NotFoundException, ServiceException {

      Object[] params = cmd.getParams();
      AID agentID = (AID) params[0];
      AgentState as = (AgentState) params[1];

      int newState = Agent.AP_MIN;
      if (as.equals(jade.domain.FIPAAgentManagement.AMSAgentDescription.SUSPENDED)) {
        newState = Agent.AP_SUSPENDED;
      } else if (as.equals(jade.domain.FIPAAgentManagement.AMSAgentDescription.WAITING)) {
        newState = Agent.AP_WAITING;
      } else if (as.equals(jade.domain.FIPAAgentManagement.AMSAgentDescription.ACTIVE)) {
        newState = Agent.AP_ACTIVE;
      }

      MainContainer impl = myContainer.getMain();
      if (impl != null) {
        ContainerID cid = impl.getContainerID(agentID);
        // Note that since getContainerID() succeeded, targetSlice can't be null
        AgentManagementSlice targetSlice = (AgentManagementSlice) getSlice(cid.getName());
        try {
          targetSlice.changeAgentState(agentID, newState);
        } catch (IMTPException imtpe) {
          // Try to get a newer slice and repeat...
          targetSlice = (AgentManagementSlice) getFreshSlice(cid.getName());
          targetSlice.changeAgentState(agentID, newState);
        }
      } else {
        // Do nothing for now, but could also route the command to the main slice, thus enabling
        // e.g. AMS replication
      }
    }
    private void handleRequestKill(VerticalCommand cmd)
        throws IMTPException, JADESecurityException, NotFoundException, ServiceException {

      Object[] params = cmd.getParams();
      AID agentID = (AID) params[0];

      // log("Source Sink consuming command REQUEST_KILL. Name is "+agentID.getName(), 3);
      if (myLogger.isLoggable(Logger.CONFIG))
        myLogger.log(
            Logger.CONFIG,
            "Source Sink consuming command REQUEST_KILL. Name is " + agentID.getName());

      MainContainer impl = myContainer.getMain();
      if (impl != null) {
        ContainerID cid = impl.getContainerID(agentID);
        // Note that since getContainerID() succeeded, targetSlice can't be null
        AgentManagementSlice targetSlice = (AgentManagementSlice) getSlice(cid.getName());
        try {
          targetSlice.killAgent(agentID, cmd);
        } catch (IMTPException imtpe) {
          // Try to get a newer slice and repeat...
          targetSlice = (AgentManagementSlice) getFreshSlice(cid.getName());
          targetSlice.killAgent(agentID, cmd);
        }
      } else {
        // Do nothing for now, but could also route the command to the main slice, thus enabling
        // e.g. AMS replication
      }
    }
 private void deadAgent(AID name) throws NotFoundException {
   MainContainer impl = myContainer.getMain();
   if (impl != null) {
     impl.deadAgent(name, false);
     /*#CUSTOMJ2SE_INCLUDE_BEGIN
     notifyDead(name);
     #CUSTOMJ2SE_INCLUDE_END*/
   }
 }
    private void handleRemoveTool(VerticalCommand cmd) {
      Object[] params = cmd.getParams();
      AID tool = (AID) params[0];

      MainContainer impl = myContainer.getMain();
      if (impl != null) {
        impl.toolRemoved(tool);
      } else {
        // Do nothing for now, but could also route the command to the main slice, thus enabling
        // e.g. AMS replication
      }
    }
예제 #6
0
  /* (non-Javadoc)
   * @see jade.core.BaseService#init(jade.core.AgentContainer, jade.core.Profile)
   */
  @Override
  public void init(AgentContainer ac, Profile p) throws ProfileException {

    super.init(ac, p);
    myContainer = ac;
    myMainContainer = ac.getMain();
    // --- Create filters -----------------------------
    outFilter = new CommandOutgoingFilter();
    incFilter = new CommandIncomingFilter();
    // --- Create local slice -------------------------
    localSlice = new ServiceComponent();

    if (myContainer != null) {
      logger.info("Starting LoadService: My-Container: " + myContainer.toString());
    }
    if (myMainContainer != null) {
      logger.info("Main-Container: " + myMainContainer.toString());
    }
    // --- Start the Load-Measurements on this Node ---
    new LoadMeasureThread().start();
  }
 private void resumedAgent(AID name) throws NotFoundException {
   MainContainer impl = myContainer.getMain();
   if (impl != null) {
     impl.resumedAgent(name);
   }
 }