Ejemplo n.º 1
0
    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
      }
    }
Ejemplo n.º 2
0
    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*/
        }
      }
    }
Ejemplo n.º 3
0
    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
      }
    }