コード例 #1
0
  public void removeOrganization(String key) {
    try {
      Organization org = organizations.get(key);

      // Delete all subOrganizations
      if (!org.getAllSubOrganizations().isEmpty() && org.getAllSubOrganizations().size() > 0) {
        Enumeration<String> subOrgs = org.getAllSubOrganizations().keys();
        while (subOrgs.hasMoreElements()) {
          String subOrg = (String) subOrgs.nextElement();
          removeOrganization(subOrg);
        }
      }

      Enumeration<String> orgRoleNames = org.getAllAgentRoles().keys();
      AgentRole orgRole = null;

      while (orgRoleNames.hasMoreElements()) {
        String orgRoleName = (String) orgRoleNames.nextElement();
        orgRole = org.getAgentRole(orgRoleName);
        GenericAgent agent = orgRole.getPlayer();

        Enumeration<String> aRoleNames = agent.getAllAgentRoles().keys();
        AgentRole aRole = null;
        boolean hasOtherOrgs = false;

        // Cancel the role with agents
        while (aRoleNames.hasMoreElements()) {
          String aRoleName = (String) aRoleNames.nextElement();
          aRole = agent.getAgentRole(aRoleName);

          if (aRole.getOwner() != org) {
            aRole.getOwner().getContainerController().acceptNewAgent(agent.getName(), agent);
            hasOtherOrgs = true;
            break;
          }
        }

        // When agent have not other organizations, it will be deleted
        if (!hasOtherOrgs) removeAgent(agent.getName());

        // Removes the instance of AgentRole
        org.removeAgentRole(orgRoleName);
      }

      // Delete the container on JADE and JAMDER
      org.getContainerController().kill();
      organizations.remove(key);
    } catch (ControllerException exception) {
      exception.printStackTrace();
    }
  }
コード例 #2
0
  public void addAgent(String key, GenericAgent agent) {
    try {
      if (agent instanceof Organization) return;

      AgentRole role = agent.getAllAgentRoles().values().iterator().next();
      AgentController control = role.getOwner().getContainerController().acceptNewAgent(key, agent);
      // control.start();

      if (!control.getState().getName().equals("Active")) control.start();

      agents.put(key, agent);
    } catch (ControllerException exception) {
      exception.printStackTrace();
    } catch (RuntimeException exception) {
      exception.printStackTrace();
    }
  }
コード例 #3
0
  public void removeAgent(String name) {
    try {
      GenericAgent agent = agents.get(name);
      Enumeration<String> roles = agent.getAllAgentRoles().keys();
      AgentRole role = null;

      while (roles.hasMoreElements()) {
        String roleName = (String) roles.nextElement();
        role = (AgentRole) agent.getAgentRole(roleName);
        role.getOwner().removeAgentRole(roleName);
      }

      AgentContainer ac = agent.getContainerController();
      ac.getAgent(name).kill();
      // agents.get(name).doDelete();
      agents.remove(name);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }