⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appinfo.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * The contents of this file are subject to the OAA  Community Research
 * License Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License
 * at http://www.ai.sri.com/~oaa/.  Software distributed under the License
 * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * rights and limitations under the License.  Portions of the software are
 * Copyright (c) SRI International, 1999-2003.  All rights reserved.
 * "OAA" is a registered trademark, and "Open Agent Architecture" is a
 * trademark, of SRI International, a California nonprofit public benefit
 * corporation.
*/

package com.sri.oaa2.agt.startit;

import java.io.*;
import java.util.*;
import java.util.regex.*;
import com.sri.oaa2.icl.*;
import com.sri.oaa2.com.*;


public class AppInfo {

  // private????
  public String appid;
  public String appname;
  public String oaaname;
  public String appdir;
  public String host;
  public String user;
  public int    shell = LoginInfo.LOCAL;
    public Vector/*String*/ environment = new Vector();
  public String appline;
  public Vector/*String*/ projects = null; // default: means in all projects
  public String onready;
  public String ondisconnect;
  public String helptext;
  public boolean restart;
  public boolean hidden;
  public boolean facilitator;
  public int port = -1;
  protected Vector/*String*/ waitfor = new Vector(); // temporary, during init (just holds names)
  protected Vector/*AppInfo*/ agentsToWaitFor = new Vector(); // actual list of apps to wait for
  protected Vector/*AppInfo*/ appsWaitingForMe = new Vector(); // used to kill in reverse order of start
  protected Vector/*OutputFlag*/ waitforoutput = new Vector();
  protected String logfile;

  public final static String VAR_HOST = "Host";
  public final static String VAR_OAACONNECT = "OaaConnect";

  // fields used ONLY if this is a facilitator (not really making use of
  // subclasses here, but it's a bit complicated to implement that way...)
  public OptionInfo portOption; // points to the option for choosing its port

  public final Vector/*OptionInfo*/ options = new Vector/*OptionInfo*/();;

  // StartitInfo needs to know this so it can call me:
  public  final static String APPNAME  = "appname";
  // nobody needs to know about these other strings I care about:
  private final static String APPID    = "appid";
  private final static String OAANAME  = "oaaname";
  private final static String APPDIR   = "appdir";
  private final static String HOST     = "host";
  private final static String USER     = "user";
  private final static String LOGIN    = "login";
  private final static String SHELL    = "shell";
  private final static String ENVIRONMENT  = "environment";
  private final static String PRELINE  = "preline";
  private final static String APPLINE  = "appline";
  private final static String RESTART  = "restart";
  private final static String HIDDEN   = "hidden";
  private final static String PROJECTS = "projects";
  private final static String ONREADY  = "onready";
  private final static String ONDISCONNECT = "ondisconnect";
  private final static String HELPTEXT = "helptext";
  private final static String FAC      = "facilitator";
  private final static String FACPORT  = "port";
  private final static String WAITFOR  = "waitfor";
  private final static String WAITFOROUTPUT  = "waitforoutput";
  private final static String LOGFILE  = "logfile";
  private final static String END      = "end";

  private final static int DEFAULT_PORT = 3378;

  protected StartitInfo sinfo;
  private final StartitProcess sprocess;

  public final static int MAX_NESTING = 65;

  public AppInfo(StartitInfo s, ConfigReader reader, String args[]) {
    sinfo = s;
    sprocess = new StartitProcess(this);
    boolean reachedEnd = false;
    String rest;

    String token;

    if (!reader.getFirstToken().equals(APPNAME)) {
      System.err.println("OOPS: " + reader.getFirstToken());
      return;
    }
    appname = reader.getRest();

    while (!reachedEnd) {
      reader.readLine();
      token = reader.getFirstToken();
      if (token.equals(OAANAME)) {
	oaaname = reader.getRest();
      }
      else if (token.equals(APPID)) {
	appid = reader.getRest();
      }
      else if (token.equals(APPDIR)) {
	appdir = reader.getRest();
      }
      else if (token.equals(HOST)) {
	host = reader.getRest();
      }
      else if (token.equals(USER)) {
	user = reader.getRest();
      }
      else if (token.equals(LOGIN)) {
	String login = reader.getRest();
	host = LoginInfo.getHost(login);
	user = LoginInfo.getUser(login);
      }
      else if (token.equals(SHELL)) {
	rest = reader.getRest();
	int sh = LoginInfo.shellFromString(rest);
	if (sh != LoginInfo.UNDEFINED) {
	  shell = sh;
	}
	else {
	  reader.printWarning("Undefined " + SHELL + ": " + rest);
	}
      }
      else if (token.equals(ENVIRONMENT)) {
	environment.addAll(reader.getRemainingTokens());
      }
      else if (token.equals(PRELINE)) {
	reader.printWarning("The \"preline\" directive is no longer supported.  " +
			    "(You may use \"environment\" to pass environment variables.)");
      }
      else if (token.equals(APPLINE)) {
	appline = reader.getRest();
      }
      else if (token.equals(RESTART)) {
	restart = true;
      }
      else if (token.equals(HIDDEN)) {
	hidden = true;
      }
      else if (token.equals(PROJECTS)) {
	projects = reader.getRemainingTokens();
	for (Iterator i = projects.iterator(); i.hasNext(); ) {
	  String p = (String) i.next();
	  if (sinfo.projectlist==null || !sinfo.projectlist.contains(p)) {
	    reader.printError("project \"" + p + "\" not in projectlist");
	  }
	}
      }
      else if (token.equals(ONREADY)) {
	onready = reader.getRest();
      }
      else if (token.equals(ONDISCONNECT)) {
	ondisconnect = reader.getRest();
      }
      else if (token.equals(HELPTEXT)) {
	helptext = reader.getRest();
      }
      else if (token.equals(FAC)) {
	facilitator = true;
      }
      else if (token.equals(WAITFOR)) {
	waitfor.addAll(reader.getRemainingTokens());
      }
      else if (token.equals(WAITFOROUTPUT)) {
	waitforoutput.add(new OutputFlag(reader.getNextToken(), reader.getRest()));
      }
      else if (token.equals(LOGFILE)) {
	logfile = reader.getRest();
      }
      else if (token.equals(END)) {
	reachedEnd = true;;
      }
      else if (token.equals(FACPORT)) {
	try {
          port = Integer.parseInt(reader.getRest());
	}
	catch (NumberFormatException e) {
          reader.printError("port must be an integer");
	}
      }
      else { // assume it's an OptionInfo keyword (if not, OptionInfo will complain)
	OptionInfo option = new OptionInfo(reader);
	if (option.type == option.INVALID) { // not an option after all
	  reader.printError("unknown app keyword: " + reader.getFirstToken());
	}
	else {
	  options.add(option);
	}
      }
    }

    // make sure there's an appid
    if (appid == null) {
      appid = isAgent() ? oaaname : appname;
    }

    if (isFacilitator()) {
      if (port < 0) {
	// If port not given in config file, look for value in setup.pl 
        IclTerm deffac = LibComUtils.oaaResolveVariable("default_facilitator", args);
	if (deffac != null && deffac.size() >= 2) {
	  IclTerm iclport = deffac.getTerm(1);
	  if (iclport.isInt()) {
	    port = ((IclInt)iclport).toInt();
	  }
	}
        // All else fails, use default value. 
	if (port < 0) {
	  port = DEFAULT_PORT;
	}
      }
      String portString = String.valueOf(port);
      portOption = new OptionInfo(OptionInfo.TOGGLE_TEXT_MENU, "Port");
      portOption.label = "Port: ";
      portOption.falseLabel = portString;
      portOption.falseValue = portString;
      portOption.size = 4;
      options.add(0, portOption);

      // facilitators get their own OaaConnection
      sprocess.setOaaConnection(new OaaConnection(sinfo));
    }
  }

  /** This is called by StartitInfo once all apps have been read in.  It initializes
   * various fields, for example, that pointed to other apps by name, and needed all
   * apps around so it could resolve their names.
   */
  public void initialize() {
    // fill in agentsToWaitFor, given waitfor Strings;
    initializeWaitFor();
    
    // resolve waitforoutput

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -