Example #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;
  }
Example #2
0
  /**
   * This method configures and send a ACLMessage to start a new remote-Container.
   *
   * @param remConf the RemoteContainerConfig
   * @param preventUsageOfAlreadyUsedComputers the boolean prevent usage of already used computers
   * @return the name of the container
   */
  private String sendMsgRemoteContainerRequest(RemoteContainerConfig inConf) {

    // --- Get the local Address of JADE ------------------------
    String myPlatformAddress = myContainer.getPlatformID();

    // --- If the remote-configuration is null configure it now -
    RemoteContainerConfig remConf = this.getRemoteContainerConfigAuto();
    if (inConf != null) {
      if (inConf.getJadeContainerName() != null) {
        String name = inConf.getJadeContainerName();
        int suf = getSuffixNo(inConf.getJadeContainerName());
        name = name + suf;
        remConf.setJadeContainerName(name);
      }
      if (inConf.getJadeHost() != null) {
        remConf.setJadeHost(inConf.getJadeHost());
      }
      if (inConf.getJadePort() != null) {
        remConf.setJadePort(inConf.getJadePort());
      }
      if (inConf.getJadeServices() != null) {
        remConf.setJadeServices(inConf.getJadeServices());
      }
    }

    // --- Define the AgentAction -------------------------------
    ClientRemoteContainerRequest req = new ClientRemoteContainerRequest();
    req.setRemoteConfig(remConf);

    Action act = new Action();
    act.setActor(myContainer.getAMS());
    act.setAction(req);

    // --- Define receiver of the Message -----------------------
    AID agentGUIAgent = new AID("server.client" + "@" + myPlatformAddress, AID.ISGUID);

    // --- Build Message ----------------------------------------
    ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
    msg.setSender(myContainer.getAMS());
    msg.addReceiver(agentGUIAgent);
    msg.setLanguage(new SLCodec().getName());
    msg.setOntology(DistributionOntology.getInstance().getName());
    try {
      msg.setContentObject(act);
    } catch (IOException errCont) {
      logger.error(errCont);
    }

    // --- Send message -----------------------------------------
    myContainer.postMessageToLocalAgent(msg, agentGUIAgent);

    // --- Remind, that we're waiting for this container --------
    loadInfo.setNewContainer2Wait4(remConf.getJadeContainerName());

    // --- Return -----------------------------------------------
    return remConf.getJadeContainerName();
  }