org.aitools.programd
Class Core

java.lang.Object
  extended by org.aitools.programd.Core

public class Core
extends java.lang.Object

The "core" of Program D, independent of any interfaces.

Author:
Noel Bush

Nested Class Summary
static class Core.Status
          Possible values for status.
(package private)  class Core.UncaughtExceptionHandler
           
 
Field Summary
private static java.lang.String AIML_SCHEMA_LOCATION
          The location of the AIML schema.
private  AIMLProcessorRegistry aimlProcessorRegistry
          The AIML processor registry.
private  AIMLWatcher aimlWatcher
          An AIMLWatcher.
static java.lang.String ASTERISK
          The * wildcard.
private  java.net.URL baseURL
          The base URL.
static java.lang.String BOT_CONFIG_SCHEMA_URI
          The namespace URI of the bot configuration.
private  BotConfigurationElementProcessorRegistry botConfigurationElementProcessorRegistry
          The bot configuration element processor registry.
private  Bots bots
          The bots.
static java.lang.String BUILD
          Build identifier.
static java.lang.String[] COPYLEFT
          Copyright notice.
private static java.lang.String EMPTY_STRING
           
private  Graphmaster graphmaster
          The Graphmaster.
private  Heart heart
          A heart.
private  java.lang.String hostname
          Name of the local host.
private  Interpreter interpreter
          An interpreter.
private  boolean loadtime
          Load time marker.
private  org.apache.log4j.Logger logger
          The logger for the Core.
private  Multiplexor multiplexor
          The Multiplexor.
private  javax.xml.parsers.SAXParser parser
          The SAXParser used in loading AIML.
static java.lang.String PLUGIN_CONFIG_SCHEMA_URI
          The namespace URI of the plugin configuration.
private  org.w3c.dom.Document pluginConfig
          The plugin config.
private static java.lang.String PLUGINS_SCHEMA_LOCATION
          The location of the plugins schema.
private  PredicateMaster predicateMaster
          The PredicateMaster.
private  ManagedProcesses processes
          The processes.
protected  CoreSettings settings
          The Settings.
protected  Core.Status status
          The status of the Core.
static java.lang.String VERSION
          Version of this package.
 
Constructor Summary
Core(java.net.URL base)
          Initializes a new Core object with default property values and the given base URL.
Core(java.net.URL base, CoreSettings settingsToUse)
          Initializes a new Core object with the given CoreSettings object and the given base URL.
Core(java.net.URL base, java.net.URL propertiesPath)
          Initializes a new Core object with the properties from the given file and the given base URL.
 
Method Summary
 void alert(java.lang.String description, java.lang.Thread t, java.lang.Throwable e)
          Notes the given Throwable and advises that the Core may no longer be stable.
 void alert(java.lang.String description, java.lang.Throwable e)
          Notes the given Throwable and advises that the Core may no longer be stable.
 void alert(java.lang.Thread t, java.lang.Throwable e)
          Notes the given Throwable and advises that the Core may no longer be stable.
 void alert(java.lang.Throwable e)
          Notes the given Throwable and advises that the Core may no longer be stable.
private  void doLoad(java.net.URL path, java.lang.String botid)
          An internal method used by load(URL, String).
 AIMLProcessorRegistry getAIMLProcessorRegistry()
           
 AIMLWatcher getAIMLWatcher()
           
 java.net.URL getBaseURL()
           
 Bot getBot(java.lang.String id)
           
 BotConfigurationElementProcessorRegistry getBotConfigurationElementProcessorRegistry()
           
 Bots getBots()
           
 Graphmaster getGraphmaster()
           
 java.lang.String getHostname()
           
 Interpreter getInterpreter()
           
 org.apache.log4j.Logger getLogger()
           
 ManagedProcesses getManagedProcesses()
           
 Multiplexor getMultiplexor()
           
 org.w3c.dom.Document getPluginConfig()
           
 PredicateMaster getPredicateMaster()
           
 java.lang.String getResponse(java.lang.String input, java.lang.String userid, java.lang.String botid)
          Returns the response to an input, using a default TextResponder.
 CoreSettings getSettings()
           
 Core.Status getStatus()
           
 void load(java.net.URL path, java.lang.String botid)
          Loads the Graphmaster with the contents of a given path.
 java.lang.String loadBot(java.net.URL path)
          Loads a bot from the given path.
 void loadBots(java.net.URL path)
          Loads bots from the indicated config file path.
 void processResponse(java.lang.String input)
          Processes the given input using default values for userid (the hostname), botid (the first available bot), and no responder.
 void reload(java.net.URL path)
          Reloads a file—it is not necessary to specify a particular botid here, because a reload of a file for one botid suffices for all bots associated with that file.
 void setLoadtime()
          Sets "loadtime" mode (so accidentally duplicated paths in a load config won't be loaded multiple times).
private  void setupInterpreter()
           
private  boolean shouldLoad(java.net.URL path, Bot bot)
          Tracks/checks whether a given path should be loaded, depending on whether or not it's currently "loadtime"; if the file has already been loaded and is allowed to be reloaded, unloads the file first.
 void shutdown()
          Performs all necessary shutdown tasks.
protected  void start()
          Initializes and starts up the Core.
private  void startHeart()
           
private  void startWatcher()
           
 void unloadBot(java.lang.String id)
          Unloads a bot with the given id.
 void unsetLoadtime()
          Unsets "loadtime" mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYLEFT

public static final java.lang.String[] COPYLEFT
Copyright notice.


VERSION

public static final java.lang.String VERSION
Version of this package.

See Also:
Constant Field Values

BUILD

public static final java.lang.String BUILD
Build identifier.

See Also:
Constant Field Values

AIML_SCHEMA_LOCATION

private static final java.lang.String AIML_SCHEMA_LOCATION
The location of the AIML schema.

See Also:
Constant Field Values

BOT_CONFIG_SCHEMA_URI

public static final java.lang.String BOT_CONFIG_SCHEMA_URI
The namespace URI of the bot configuration.

See Also:
Constant Field Values

PLUGIN_CONFIG_SCHEMA_URI

public static final java.lang.String PLUGIN_CONFIG_SCHEMA_URI
The namespace URI of the plugin configuration.

See Also:
Constant Field Values

PLUGINS_SCHEMA_LOCATION

private static final java.lang.String PLUGINS_SCHEMA_LOCATION
The location of the plugins schema.

See Also:
Constant Field Values

baseURL

private java.net.URL baseURL
The base URL.


settings

protected CoreSettings settings
The Settings.


graphmaster

private Graphmaster graphmaster
The Graphmaster.


multiplexor

private Multiplexor multiplexor
The Multiplexor.


predicateMaster

private PredicateMaster predicateMaster
The PredicateMaster.


bots

private Bots bots
The bots.


processes

private ManagedProcesses processes
The processes.


botConfigurationElementProcessorRegistry

private BotConfigurationElementProcessorRegistry botConfigurationElementProcessorRegistry
The bot configuration element processor registry.


parser

private javax.xml.parsers.SAXParser parser
The SAXParser used in loading AIML.


aimlProcessorRegistry

private AIMLProcessorRegistry aimlProcessorRegistry
The AIML processor registry.


aimlWatcher

private AIMLWatcher aimlWatcher
An AIMLWatcher.


interpreter

private Interpreter interpreter
An interpreter.


logger

private org.apache.log4j.Logger logger
The logger for the Core.


loadtime

private boolean loadtime
Load time marker.


hostname

private java.lang.String hostname
Name of the local host.


heart

private Heart heart
A heart.


pluginConfig

private org.w3c.dom.Document pluginConfig
The plugin config.


status

protected Core.Status status
The status of the Core.


EMPTY_STRING

private static final java.lang.String EMPTY_STRING
See Also:
Constant Field Values

ASTERISK

public static final java.lang.String ASTERISK
The * wildcard.

See Also:
Constant Field Values
Constructor Detail

Core

public Core(java.net.URL base)
Initializes a new Core object with default property values and the given base URL.

Parameters:
base - the base URL to use

Core

public Core(java.net.URL base,
            java.net.URL propertiesPath)
Initializes a new Core object with the properties from the given file and the given base URL.

Parameters:
base - the base URL to use
propertiesPath -

Core

public Core(java.net.URL base,
            CoreSettings settingsToUse)
Initializes a new Core object with the given CoreSettings object and the given base URL.

Parameters:
base - the base URL to use
settingsToUse - the settings to use
Method Detail

start

protected void start()
Initializes and starts up the Core.


startWatcher

private void startWatcher()

startHeart

private void startHeart()

setupInterpreter

private void setupInterpreter()
                       throws UserError,
                              DeveloperError
Throws:
UserError
DeveloperError

load

public void load(java.net.URL path,
                 java.lang.String botid)
Loads the Graphmaster with the contents of a given path.

Parameters:
path - path to the file(s) to load
botid -

reload

public void reload(java.net.URL path)
Reloads a file—it is not necessary to specify a particular botid here, because a reload of a file for one botid suffices for all bots associated with that file.

Parameters:
path -
Throws:
java.lang.IllegalArgumentException - if the given path is not actually loaded for any bot

doLoad

private void doLoad(java.net.URL path,
                    java.lang.String botid)
An internal method used by load(URL, String).

Parameters:
path -
botid -

shouldLoad

private boolean shouldLoad(java.net.URL path,
                           Bot bot)
Tracks/checks whether a given path should be loaded, depending on whether or not it's currently "loadtime"; if the file has already been loaded and is allowed to be reloaded, unloads the file first.

Parameters:
path - the path to check
bot - the bot for whom to check
Returns:
whether or not the given path should be loaded

setLoadtime

public void setLoadtime()
Sets "loadtime" mode (so accidentally duplicated paths in a load config won't be loaded multiple times).


unsetLoadtime

public void unsetLoadtime()
Unsets "loadtime" mode.


processResponse

public void processResponse(java.lang.String input)
Processes the given input using default values for userid (the hostname), botid (the first available bot), and no responder. The result is not returned. This method is mostly useful for a simple test of the Core.

Parameters:
input - the input to send

getResponse

public java.lang.String getResponse(java.lang.String input,
                                    java.lang.String userid,
                                    java.lang.String botid)
Returns the response to an input, using a default TextResponder.

Parameters:
input - the "non-internal" (possibly multi-sentence, non-substituted) input
userid - the userid for whom the response will be generated
botid - the botid from which to get the response
Returns:
the response

shutdown

public void shutdown()
Performs all necessary shutdown tasks. Shuts down the Graphmaster and all ManagedProcesses.


alert

public void alert(java.lang.Throwable e)
Notes the given Throwable and advises that the Core may no longer be stable.

Parameters:
e - the Throwable to log

alert

public void alert(java.lang.Thread t,
                  java.lang.Throwable e)
Notes the given Throwable and advises that the Core may no longer be stable.

Parameters:
t - the thread in which the Throwable was thrown
e - the Throwable to log

alert

public void alert(java.lang.String description,
                  java.lang.Throwable e)
Notes the given Throwable and advises that the Core may no longer be stable.

Parameters:
description - the description of the Throwable
e - the Throwable to log

alert

public void alert(java.lang.String description,
                  java.lang.Thread t,
                  java.lang.Throwable e)
Notes the given Throwable and advises that the Core may no longer be stable.

Parameters:
description - the description of the Throwable
t - the thread in which the Throwable was thrown
e - the Throwable to log

loadBots

public void loadBots(java.net.URL path)
Loads bots from the indicated config file path.

Parameters:
path - the config file path

loadBot

public java.lang.String loadBot(java.net.URL path)
Loads a bot from the given path. Will only work right if the file at the path actually has a >bot< element as its root.

Parameters:
path - the bot config file
Returns:
the id of the bot loaded

unloadBot

public void unloadBot(java.lang.String id)
Unloads a bot with the given id.

Parameters:
id - the bot to unload

getBots

public Bots getBots()
Returns:
the object that manages information about all bots

getBot

public Bot getBot(java.lang.String id)
Parameters:
id - the id of the bot desired
Returns:
the requested bot

getGraphmaster

public Graphmaster getGraphmaster()
Returns:
the Graphmaster

getMultiplexor

public Multiplexor getMultiplexor()
Returns:
the Multiplexor

getPredicateMaster

public PredicateMaster getPredicateMaster()
Returns:
the PredicateMaster

getBotConfigurationElementProcessorRegistry

public BotConfigurationElementProcessorRegistry getBotConfigurationElementProcessorRegistry()
Returns:
the BotConfigurationElementProcessorRegistry

getAIMLProcessorRegistry

public AIMLProcessorRegistry getAIMLProcessorRegistry()
Returns:
the AIML processor registry.

getAIMLWatcher

public AIMLWatcher getAIMLWatcher()
Returns:
the AIMLWatcher

getSettings

public CoreSettings getSettings()
Returns:
the settings for this core

getInterpreter

public Interpreter getInterpreter()
Returns:
the active JavaScript interpreter

getHostname

public java.lang.String getHostname()
Returns:
the local hostname

getManagedProcesses

public ManagedProcesses getManagedProcesses()
Returns:
the managed processes

getStatus

public Core.Status getStatus()
Returns:
the status of the Core

getPluginConfig

public org.w3c.dom.Document getPluginConfig()
Returns:
the plugin config

getBaseURL

public java.net.URL getBaseURL()
Returns:
the base URL

getLogger

public org.apache.log4j.Logger getLogger()
Returns:
the logger