Exemple #1
0
  /**
   * This method returns a default configuration for a new remote container.
   *
   * @param preventUsageOfAlreadyUsedComputers the prevent usage of already used computers
   * @return the default RemoteContainerConfig
   */
  private RemoteContainerConfig getRemoteContainerConfigAuto() {

    // --- Variable for the new container name ------------------
    String newContainerPrefix = "remote";
    String newContainerName;
    // --- Get the local IP-Address -----------------------------
    String myIP = myContainer.getNodeDescriptor().getContainer().getAddress();
    // --- Get the local port of JADE ---------------------------
    String myPort = myContainer.getNodeDescriptor().getContainer().getPort();

    // --- Get the List of services started here ----------------
    String myServices = "";
    List<?> services = myContainer.getServiceManager().getLocalServices();
    Iterator<?> it = services.iterator();
    while (it.hasNext()) {
      ServiceDescriptor serviceDesc = (ServiceDescriptor) it.next();
      String service = serviceDesc.getService().getClass().getName() + ";";
      myServices += service;
    }

    newContainerName = newContainerPrefix + getSuffixNo(newContainerPrefix);

    logger.info("-- Infos to start the remote container ------------");
    logger.info("=> Services2Start:   " + myServices);
    logger.info("=> NewContainerName: " + newContainerName);
    logger.info("=> ThisAddresses:    " + myIP + " - Port: " + myPort);

    // --- Define the 'RemoteContainerConfig' - Object ----------
    RemoteContainerConfig remConf = new RemoteContainerConfig();
    remConf.setJadeServices(myServices);
    remConf.setJadeIsRemoteContainer(true);
    remConf.setJadeHost(myIP);
    remConf.setJadePort(myPort);
    remConf.setJadeContainerName(newContainerName);
    remConf.setJadeShowGUI(true);

    // --- Apply defaults, if set -------------------------------
    if (this.defaults4RemoteContainerConfig != null) {
      remConf.setJadeShowGUI(this.defaults4RemoteContainerConfig.getJadeShowGUI());
      remConf.setJvmMemAllocInitial(this.defaults4RemoteContainerConfig.getJvmMemAllocInitial());
      remConf.setJvmMemAllocMaximum(this.defaults4RemoteContainerConfig.getJvmMemAllocMaximum());
    }
    return remConf;
  }
  /**
   * 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);
  }