コード例 #1
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
      }
    }
コード例 #2
0
  /**
   * Creates a new JADE agent, running within this container,
   *
   * @param nickname A platform-unique nickname for the newly created agent. The agent will be given
   *     a FIPA compliant agent identifier using the nickname and the ID of the platform it is
   *     running on.
   * @param className The fully qualified name of the class that implements the agent.
   * @param args An object array, containing initialization parameters to pass to the new agent.
   * @return A proxy object, allowing to call state-transition forcing methods on the real agent
   *     instance.
   */
  public AgentController createNewAgent(String nickname, String className, Object[] args)
      throws StaleProxyException {
    if (myImpl == null || myProxy == null) {
      throw new StaleProxyException();
    }

    AID agentID = new AID(AID.createGUID(nickname, myImpl.getPlatformID()), AID.ISGUID);

    try {
      myProxy.createAgent(agentID, className, args);
      return new AgentControllerImpl(agentID, myProxy, myImpl);
    } catch (Throwable t) {
      t.printStackTrace();
      throw new StaleProxyException(t);
    }
  }
コード例 #3
0
  /**
   * Get a controller (i.e. a proxy) to a local agent given its local-name or GUID.
   *
   * @param name The local name or the GUID of the desired agent.
   * @param isGuid A flag indicating whether <code>name</code> represents the local-name (<code>
   *     AID.ISLOCALNAME</code>) or the GUID (<code>AID.ISGUID</code>) of the desired agent.
   * @throws ControllerException If any problems occur obtaining this proxy or if no such agent
   *     exists in the local container.
   */
  public AgentController getAgent(String name, boolean isGuid) throws ControllerException {
    if (myImpl == null || myProxy == null) {
      throw new StaleProxyException();
    }

    if (!isGuid) {
      name = AID.createGUID(name, myImpl.getPlatformID());
    }
    AID agentID = new AID(name, AID.ISGUID);

    // Check that the agent exists
    jade.core.Agent instance = myImpl.acquireLocalAgent(agentID);
    if (instance == null) {
      throw new ControllerException("Agent " + agentID.getName() + " not found.");
    }
    myImpl.releaseLocalAgent(agentID);
    return new AgentControllerImpl(agentID, myProxy, myImpl);
  }
コード例 #4
0
  /**
   * Add an Agent to this container. Typically Agent would be some class extending Agent which was
   * instantiated and configured.
   *
   * @param nickname A platform-unique nickname for the newly created agent. The agent will be given
   *     a FIPA compliant agent identifier using the nickname and the ID of the platform it is
   *     running on.
   * @param anAgent The agent to be added to this agent container.
   * @return An AgentController, allowing to call state-transition forcing methods on the real agent
   *     instance.
   */
  public AgentController acceptNewAgent(String nickname, jade.core.Agent anAgent)
      throws StaleProxyException {
    if (myImpl == null || myProxy == null) {
      throw new StaleProxyException();
    }

    AID agentID = new AID(AID.createGUID(nickname, myImpl.getPlatformID()), AID.ISGUID);
    // FIXME: This call skips the security checks on the local container
    try {
      jade.core.NodeDescriptor nd = myImpl.getNodeDescriptor();
      // The owner of the new agent is the owner of the local container.
      // The new agent has NO initial credentials
      myImpl.initAgent(agentID, anAgent, nd.getOwnerPrincipal(), null);
    } catch (Exception e) {
      throw new StaleProxyException(e);
    }
    return new AgentControllerImpl(agentID, myProxy, myImpl);
  }