コード例 #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
      }
    }
コード例 #2
0
    private void handleInformStateChanged(VerticalCommand cmd) {

      Object[] params = cmd.getParams();
      AID target = (AID) params[0];
      AgentState from = (AgentState) params[1];
      AgentState to = (AgentState) params[2];

      if (to.equals(jade.domain.FIPAAgentManagement.AMSAgentDescription.SUSPENDED)) {
        try {
          // Notify the main container through its slice
          AgentManagementSlice mainSlice = (AgentManagementSlice) getSlice(MAIN_SLICE);

          try {
            mainSlice.suspendedAgent(target);
          } catch (IMTPException imtpe) {
            // Try to get a newer slice and repeat...
            mainSlice = (AgentManagementSlice) getFreshSlice(MAIN_SLICE);
            mainSlice.suspendedAgent(target);
          }
        } catch (IMTPException re) {
          re.printStackTrace();
        } catch (NotFoundException nfe) {
          nfe.printStackTrace();
        } catch (ServiceException se) {
          se.printStackTrace();
        }
      } else if (from.equals(jade.domain.FIPAAgentManagement.AMSAgentDescription.SUSPENDED)) {
        try {
          // Notify the main container through its slice
          AgentManagementSlice mainSlice = (AgentManagementSlice) getSlice(MAIN_SLICE);

          try {
            mainSlice.resumedAgent(target);
          } catch (IMTPException imtpe) {
            // Try to get a newer slice and repeat...
            mainSlice = (AgentManagementSlice) getFreshSlice(MAIN_SLICE);
            mainSlice.resumedAgent(target);
          }
        } catch (IMTPException re) {
          re.printStackTrace();
        } catch (NotFoundException nfe) {
          nfe.printStackTrace();
        } catch (ServiceException se) {
          se.printStackTrace();
        }
      }
    }