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

📄 liboaa.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
         initLog4J = logger.getAllAppenders() == null || !logger.getAllAppenders().hasMoreElements();
     }
   }
   if (initLog4J) {
       String logconfigName;
       InputStream logConfig;
       logconfigName = OAA_LOG_CONFIG_FILE_DEFAULT;
       try {
         logconfigName = System.getProperty(OAA_LOG_CONFIG_FILE,
                                            OAA_LOG_CONFIG_FILE_DEFAULT);
       }
       catch(Exception e) {
         System.out.println("Unable to read logger config file name because of "+e.getMessage()+", using default of "+logconfigName);
       }
       logConfig = LibOaa.class.getResourceAsStream(logconfigName);
       if(logConfig == null) {
         try {
           System.out.println("Unable to read "+logconfigName+" as a system resource, attempting local file system instead...");
           logConfig = new java.io.FileInputStream(logconfigName);
         }
         catch(Exception e)
         {
           System.out.println("Unable to read "+logconfigName+" from local filesystem, delaying config until the constructor is called");
         }
       }
       if(logConfig != null) {
         configureLoggerFromXMLStreamIfNecessary(logConfig);
       }
   } else {
       System.out.println("<< OAA skipping log4j configuration >>");
   }
   LibOaa.libInit();
 }

  static private boolean isLoggingConfigured = false;

  /**
   * Allows the OAA logger to be configured from the specified stream.
   * <p>
   * This method is similar to the
   * <code>configureLoggerFromXMLStream</code>
   * method, with the difference that existing configuration will be
   * modified to the new configuration only if the logger was never
   * configured before. This is the default case, and is used when we
   * want to try several different configuration methods in order of
   * priority.
   * </p>
   * This method is always invoked from the following two places in
   * the LibOaa class.
   * <ul>
   * <li> The static initializer which attempts to read the file from:
   *    <ul>
   *    <li> the location specified by the system property
   *    oaa.log.config.file.</li>
   *    <li> the default system resource of com/sri/oaa2/oaa_log_config.xml.
   *    </li>
   *    </ul>
   * <li> The default constructor which, if the static initializer did
   * not work, reads the file from the resource (note that the static
   * initializer had to use the <i>system</i> resource) of
   * com/sri/oaa2/oaa_log_config.xml</li>
   * </ul>
   * <p>
   * The addition of the call from the default constructor allows this
   * class to be used in contexts other than a privileged java
   * application with access to system resources. For example, LibOaa
   * can now be used in an applet or as part of RMI as well.
   * </p>
   */
  public static void configureLoggerFromXMLStreamIfNecessary(InputStream inStream)
  {
      configureLoggerFromXMLStream(inStream, false);
  }

  /**
   * Allows the OAA logger to be configured from the specified stream.
   * <p>
   * This is used by LibOaa to try to configure the logger from
   * several standard places. The users of LibOaa can configure the
   * logger from other locations (such as a website) as well.
   * </p>
   * @param inStream The stream to read the XML file from. As usual,
   * most OS streams (FileInputStream...) should be wrapped by a
   * BufferedInputStream before being passed in here.
   * @param override Controls whether the configuration should be
   * always overridden or not.
   * <p>
   * The truth table for whether the configuration will be overridden
   * or not is
   * <table>
   * <tr><td>Override</td><td>isLoggingConfigured</td><td>Operation </tr>
   * <tr><td>true</td><td>Don't care</td><td>Configure</td></tr>
   * <tr><td>false</td><td>true</td><td>Ignore</td></tr>
   * <tr><td>false</td><td>false</td><td>Configure</td></tr>
   * </table>
   * </p>
   * <p>
   * Note that this method is thread-safe since it's synchronized.
   * </p>
   */
  public static synchronized void configureLoggerFromXMLStream(InputStream inStream, boolean override)
  {
    if(override || !isLoggingConfigured) {
      try {
        new DOMConfigurator().doConfigure(inStream,
                                          LogManager.getLoggerRepository());
        isLoggingConfigured = true;
        System.out.println("Configuration of log4j DONE");
      }
      catch(Exception e) {
        RuntimeException re = new RuntimeException(e.toString());
        re.fillInStackTrace();
        throw re;
      }
    }
  }

  static Logger logger = Logger.getLogger(LibOaa.class.getName());

  /**
   * @deprecated Use LibOaa.getLibraryLanguage()
   */
  static public final String oaa_library_language = "java";

  /**
   * Get the language in which this library was written
   */
  static public String getLibraryLanguage()
  {
    return oaa_library_language;
  }

  /**
   * Current version of the OAA agent library
   *
   * @deprecated Use getLibraryVersion()
   */
  static public final IclTerm oaa_library_version = getLibraryVersion();
  /**
   * @deprecated Use LibOaa.oaa_library_version
   */
  static public final IclTerm oaa_library_release = oaa_library_version;

  /**
   *
   * Return a copy of the library version IclTerm.
   */
  static public IclTerm getLibraryVersion()
  {
    return new IclList(new IclInt(2), new IclInt(3), new IclInt(1));
  }

  private boolean disconnect = false;
  private final boolean THROWEXCEPTIONONBADPARSE = false;

  /**
   * Timeout for getting a new message
   */
  private final long NEWMSGWAITTIMEOUT = Long.parseLong(System.getProperty("oaa.lib.new_message_wait_timeout", "5000"));

  /**
   * Linked list of EventsBuckets
   */
  LinkedList prioritizedSavedEvents = new LinkedList();

  /**
   * Manages timeouts for goals
   */
  TimeLimitManager timeLimitManager = new TimeLimitManager();

  /**
   * Request timeout in milliseconds
   */
  int oaa_timeout = 10000; // In milliseconds

  /**
   * Used in pollUntilEvent to store the waited event and the current
   * priority for each level of recursion.
   */
  CAwaitedEventsVector mAwaitedEvents;

  /*
   * Used in pollUntilEvent to store the priority of the current doEvent call.
   */
  //Stack DoEventPriorityStack;//= new Stack();

  /*
   * Used in pollUntilEvent to store the received events which are actually
   * awaited in some other recursion level.
   */
  ArrayList pendingPolledEventVector;

  /*
   * True when the agentlib thread is polling for an event.
   */
  boolean poll_until_event = false;

  /*
   * Table containing callback listeners for agent
   */
  Hashtable callbackTable;

  /*
   * Table storing delayed events
   */
  Hashtable oaa_delay_table;
  String delayedId = null;
  ReentrantLock delayedIdMutex = new ReentrantLock();

  /**
   * To store the current agent's pieces of data.
   * In the prolog version, agent's data are directly stored as facts.
   */
  public IclDb prologDatabase;//=new IclDb();

  // Debugging flag
  boolean oaa_trace = false;
  boolean oaa_com_trace = false;
  boolean oaa_debug = false;     // has no meaning in Java version...
  /*
   * Counter for generating unique goal ids
   */
  long globalCounter = 0;

  // List of contexts
  IclList oaa_current_contexts;//=new IclList();

  // Stack of current priorities at each nested DoEvent level
  Stack oaa_doevent_priority;//=new Stack();

  // List that locally stores the current solvables (in standard form) of
  // the agent
  IclList oaa_solvables;//=new IclList();

  String oaaThreadName = null;

  private CountDownLatch runLatch = new CountDownLatch(1);

  // Database which contains information about the solvables
  // The facts stroed are :
  //   clause(Goal, Body, Ref)
  //   clause(Head, Body)
  private LibCom mLibCom;

  private final int FAC_ID = 0;

    private boolean exitOnEvHalt = true;

    // Static icl terms
    private static final IclTerm resolveFalseTerm = new IclStruct(
            "resolve_vars", new IclStr("false"));
    private final static IclTerm _Address = new IclStruct("tcp",
            new IclVar("Host"),new IclVar("Port"));

  boolean debugOn = false;
  private void debugP(String s)
  {
    /*
    if(debugOn) {
      System.out.println(s);
    }
    */
  }

  // DEBUG
  // private CChronometer mChrono = new CChronometer();
  /**
   * Class initialization method. Called from the constructor.
   * <p>
   * @see  #LibOaa
   */
  private void initAll() {
    InputStream inStream = getClass().getClassLoader().getResourceAsStream(OAA_LOG_CONFIG_FILE_DEFAULT);
    // this should have succeeded since the oaa2 jar file contains the
    // XML file, but just in case it didn't, let's check
    if(inStream != null)
    {
      configureLoggerFromXMLStreamIfNecessary(inStream);
    }
    else
    {
      System.out.println("Unable to read logging config information as an application resource as well, using log4j defaults");
    }
    logger.info("OAA2 Java library Release : " + oaa_library_release);
    //oaa_saved_events = new OaaEventList(this);
    //DoEventPriorityStack= new Stack();
    pendingPolledEventVector= new ArrayList();
    callbackTable = new Hashtable();
    oaa_delay_table = new Hashtable();
    delayedId = null;

    prologDatabase=new IclDb();

    // List of contexts
    oaa_current_contexts=new IclList();

    // Stack of current priorities at each nested DoEvent level
    oaa_doevent_priority=new Stack();

    // List that locally stores the current solvables (in standard form) of
    // the agent
    oaa_solvables=new IclList();

    // Database which contains information about the solvables
    // The facts stroed are :
    //   clause(Goal, Body, Ref)
    //   clause(Head, Body)

    // DEBUG : Should be private
  }

  /**
   * Initialize the OAA library. This is currently a no-op; it is a
   * placeholder for future functionality.
   */
   public static void libInit()
   {
   }

  /**
   * LibOaa contains all functions necessary to create an agent for
   * the Open Agent Architecture.  A LibOaa class is created with a
   * communications object that will provide the networking to allow the
   * agent to connect and communicate with a Facilitator agent.  The LibCom
   * object is most often initiallized using LibComTcpProtocol to act as
   * the transport layer for communication.
   * <p>
   * @param inLibCom    Communications library to use for this agent
   * @see        com.sri.oaa2.com.LibCom
   * @see        com.sri.oaa2.com.LibComTcpProtocol
   */
  public LibOaa(LibCom inLibCom) {

    initAll();
    this.oaaThreadName = "OAA-Thread-" + this.getName() + "-" + Integer.toString(this.hashCode());

⌨️ 快捷键说明

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