コード例 #1
0
ファイル: LoadService.java プロジェクト: srvarey/postion
    /* (non-Javadoc)
     * @see jade.core.Filter#accept(jade.core.VerticalCommand)
     */
    @Override
    public final boolean accept(VerticalCommand cmd) {
      if (cmd == null) {
        return true;
      }

      String cmdName = cmd.getName();
      if (cmdName.equals(MessagingSlice.SET_PLATFORM_ADDRESSES) && myContainerMTPurl == null) {
        // --- Handle that the MTP-Address was created ------
        Object[] params = cmd.getParams();
        AID aid = (AID) params[0];
        String[] aidArr = aid.getAddressesArray();
        if (aidArr.length != 0) {
          myContainerMTPurl = aidArr[0];
          setLocalCRCReply(false);
        }
        // Veto the original SEND_MESSAGE command, if needed
        // return false;
      } else if (cmdName.equals(AgentManagementSlice.KILL_CONTAINER)) {
        Object[] params = cmd.getParams();
        ContainerID id = (ContainerID) params[0];
        String containerName = id.getName();
        loadInfo.containerLoads.remove(containerName);
        loadInfo.containerLocations.remove(containerName);

      } else if (cmdName.equals(AgentMobilityHelper.INFORM_MOVED)) {
        Object[] params = cmd.getParams();
        @SuppressWarnings("unused")
        AID aid = (AID) params[0];
      }
      // Never veto other commands
      return true;
    }
コード例 #2
0
    private void handleKillContainer(VerticalCommand cmd)
        throws IMTPException, ServiceException, NotFoundException {
      Object[] params = cmd.getParams();
      ContainerID cid = (ContainerID) params[0];

      if (myLogger.isLoggable(Logger.CONFIG)) {
        myLogger.log(
            Logger.CONFIG,
            "Source Sink consuming command KILL_CONTAINER. Container is " + cid.getName());
      }

      // Forward to the correct slice
      AgentManagementSlice targetSlice = (AgentManagementSlice) getSlice(cid.getName());
      try {
        try {
          targetSlice.exitContainer();
        } catch (IMTPException imtpe) {
          // Try to get a newer slice and repeat...
          targetSlice = (AgentManagementSlice) getFreshSlice(cid.getName());
          targetSlice.exitContainer();
        }
      } catch (NullPointerException npe) {
        // targetSlice not found --> The container does not exist
        throw new NotFoundException("Container " + cid.getName() + " not found");
      }
    }
コード例 #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
      }
    }
コード例 #4
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
      }
    }
コード例 #5
0
    private void handleRequestCreate(VerticalCommand cmd)
        throws IMTPException, JADESecurityException, NotFoundException, NameClashException,
            ServiceException {

      Object[] params = cmd.getParams();
      String name = (String) params[0];
      String className = (String) params[1];
      Object[] args = (Object[]) params[2];
      ContainerID cid = (ContainerID) params[3];
      JADEPrincipal owner = (JADEPrincipal) params[4];
      Credentials initialCredentials = (Credentials) params[5];

      if (myLogger.isLoggable(Logger.CONFIG))
        myLogger.log(
            Logger.CONFIG, "Source Sink consuming command REQUEST_CREATE. Name is " + name);
      MainContainer impl = myContainer.getMain();
      if (impl != null) {

        AID agentID = new AID(AID.createGUID(name, myContainer.getPlatformID()), AID.ISGUID);
        AgentManagementSlice targetSlice = (AgentManagementSlice) getSlice(cid.getName());
        if (targetSlice != null) {
          try {
            targetSlice.createAgent(
                agentID,
                className,
                args,
                owner,
                initialCredentials,
                AgentManagementSlice.CREATE_AND_START,
                cmd);
          } catch (IMTPException imtpe) {
            // Try to get a newer slice and repeat...
            targetSlice = (AgentManagementSlice) getFreshSlice(cid.getName());
            targetSlice.createAgent(
                agentID,
                className,
                args,
                owner,
                initialCredentials,
                AgentManagementSlice.CREATE_AND_START,
                cmd);
          }
        } else {
          throw new NotFoundException("Container " + cid.getName() + " not found");
        }
      } else {
        // Do nothing for now, but could also route the command to the main slice, thus enabling
        // e.g. AMS replication
      }
    }