mess
Class MessAgent

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--metaglue.AgentAgent
                          |
                          +--agentland.util.GoodAgent
                                |
                                +--agentland.resource.ManagedAgent
                                      |
                                      +--mess.MessAgent

public class MessAgent
extends ManagedAgent
implements Mess, Userfunction, RemoteTagsListener

An agent to handle the Metaglue Expert System Shell. This agent defines various primitives for Mess scripts, and controls the parsing and execution of the Jess code.

Revision history:
=================
10/3/99 by KZG: I made it provide a new function to JESS: reliesOn. 
Now you can call something like from inside your JESS script:  
(bind ?a (reliesOn "society" "agent_name" "designation"))     

If you pass an empty string instead of the agent_name, you will
get the current instance of the MessAgent back.
and then you can use ?a to communicate with the agent you have 
just relied on: 
(call ?a some_method "argument1" "argument2" "etc")

10/6/99 by KZG: added "mg-log" primitive to jess; calls log method 
in this agent (log is already used in JESS for, guess, logarithms)

10/15/99 by KZG: I have merged NotifiedMess and Mess into a single
agent. Hence Mess now has add-spy and notify primitives built
in. When a message arrives, a fact of type secret gets asserted
and run is called.

10/17/99 by KZG: I have added a 'say' primitive

10/23/99 by MHC; I rewrote all the speech in and out processing!
No docs yet!

10/23/99 + MHC.  Lots of news things and tighter Metaglue integration.

03/07/2000 by KZG: Added the posibility of starting MessAgent in
prompt mode. Use the 'doPrompt' attribute (set to false by default).

05/20/2000 by KZG: Made all load... functions return true on
success or false otherwise

06/28/00 by AC.  Added 'ask' and 'askFree' primitives.  'ask' takes
a String question and returns either 0 for no, 1 for yes, 2 for maybe,
3 for unknown, and -1 for error.  'askFree' returns a String.

10/29/00 by KZG: changed run() method to return a serializable
object; the value of this object is set inside the mess program
with setReturnValue user function

11/17/00 by KZG: modified run() again -- now the return object is
a hashtable with multiple return values set during the run of the
rete engine. If the old setReturnValue was called in rete, the
value is stored under "DEFAULT" key in the hashtable.

See Also:
Serialized Form

Inner Class Summary
protected  class MessAgent.RunPrompt
           
 
Inner classes inherited from class metaglue.AgentAgent
AgentAgent.Attribute
 
Field Summary
protected  Rete rete
          The JESS Engine.
 
Fields inherited from class agentland.resource.ManagedAgent
rm, society
 
Fields inherited from class agentland.util.GoodAgent
alert, notifier
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface metaglue.Agent
ALIVE, DIED, NO_METAGLUE, NOT_RUNNING, STARTING
 
Fields inherited from interface metaglue.Agent
ALIVE, DIED, NO_METAGLUE, NOT_RUNNING, STARTING
 
Fields inherited from interface metaglue.Agent
ALIVE, DIED, NO_METAGLUE, NOT_RUNNING, STARTING
 
Constructor Summary
MessAgent()
           
 
Method Summary
 void acceptedTagsResult(Hashtable tags)
          For incoming speech--chop into bits and send on to mess scripts.
 void addMessSpy(String noteType)
          Helper method used by extentions/MessAddSpy.java
 void addUserfunction(Serializable uf)
           
protected  void addUserFunctions()
           
 void assert(Fact f)
           
 void assert(String s)
           
 void assertAttribute(String attrName)
          This method asserts a fact of type attribute.
 void assertSpeechTag(String tagName, String tagValue)
          Asserts speech tag as an instance of a heard fact in JESS.
 Fact assertStringFact(String fact)
          Asserts a fact as a string and returns the Fact object
 Value call(ValueVector vv, Context c)
           
 void callInitScripts()
           
 void clear()
           
 void execCommand(String cmd)
          Passes a JESS command to the engine.
 Vector facts()
           
 String fetch(String name)
           
 int fetchInt(String name)
           
 String getName()
          The two methods below provide a relies-on function for JESS
 Object getReturnValue(Object key)
           
 void loadFacts()
           
 boolean loadFile(String fname)
          Loads a set of definitions into the interpreter from a filename.
 AppGrammar loadGrammar(String grammar)
           
protected  void loadPackages()
          Load a series of JESS packages.
 boolean loadReader(Reader i)
          Returns true on success or false otherwise
 boolean loadScript(String packageList)
           
 boolean loadString(String s)
          Loads a set of definitions into the interpreter from a string.
 boolean loadURL(String urlString)
          Loads a set of definitions into the interpreter from a URL.
 int messAsk(String question)
           
 String messAskFree(String question)
           
 void messSay(String s)
           
 void messSaySafe(String s)
           
 void messSaySync(String s)
           
 void messThink(String s)
           
 Fact newFact(Fact f)
           
 Fact newFact(String s)
           
 void reset()
           
 void retract(Fact f)
           
 void retract(String s)
           
 Hashtable run()
          run method starts the rete engine and returns the return value set during the execution of the mess program.
protected  void runRete()
           
 void saveFacts()
           
 void setReturnValue(Object key, Object val)
          This is for the Mess engine to set the return value to be returned by the run() method.
protected  void startRete()
           
 void store(String name, Object value)
           
 void store(String name, Value value)
           
 void tell(Secret s)
          This method receives notifications on behalf of JESS.
 
Methods inherited from class agentland.resource.ManagedAgent
connect, getAlert, getNeed, reliesOn, reliesOn, replace, request, request, request, requestAgent, requestAgent, resources, resourcesByAgentID, setNeed, yank, yank, yank
 
Methods inherited from class agentland.util.GoodAgent
addSpy, addSpy, alert, alertString, beep, error, getHistory, getHistoryElement, getPersistentMap, log, notify, removeSpy, removeSpy, resetHistory, safeRely, safeRely, safeRely, setNiceLogName
 
Methods inherited from class metaglue.AgentAgent
addMonitor, alive, defrost, defrostAll, defrostBoolean, defrostInt, defrostString, fixAttribute, fixAttribute, freeze, freeze, freeze, freezeAll, freezeVar, getAgentID, getAttribute, getCatalog, getCatalogID, getDesignation, getFrozenVariables, getLogLevel, getMetaglueAgent, getMetaglueAgentID, getOccupation, getProperties, getSociety, log, log, obtainMetaglueAgent, obtainMetaglueAgent, obtainMetaglueAgentByName, reliesOn, reliesOnSynch, removeFrozen, replaceExceptionHandler, setFreezeName, setLogLevel, setLogName, shutdown, startAgent, startAgentOn, startAgentOn, startup, status, tiedTo, tiedTo, tiedTo, tiedTo, tieToDesignation, whereAreYou
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

rete

protected Rete rete
The JESS Engine.
Constructor Detail

MessAgent

public MessAgent()
          throws RemoteException
Method Detail

saveFacts

public void saveFacts()
               throws RemoteException
Specified by:
saveFacts in interface Mess

loadFacts

public void loadFacts()
               throws RemoteException
Specified by:
loadFacts in interface Mess

callInitScripts

public void callInitScripts()
                     throws RemoteException

startRete

protected void startRete()

addUserFunctions

protected void addUserFunctions()

loadPackages

protected void loadPackages()
Load a series of JESS packages. This can be used by subclasses of JessAgent to load new packages into the system.

reset

public void reset()
           throws RemoteException
Specified by:
reset in interface Mess

clear

public void clear()
           throws RemoteException
Specified by:
clear in interface Mess

run

public Hashtable run()
              throws RemoteException
run method starts the rete engine and returns the return value set during the execution of the mess program.
Specified by:
run in interface Mess

setReturnValue

public void setReturnValue(Object key,
                           Object val)
This is for the Mess engine to set the return value to be returned by the run() method.

getReturnValue

public Object getReturnValue(Object key)

runRete

protected void runRete()

newFact

public Fact newFact(String s)
             throws RemoteException
Specified by:
newFact in interface Mess

newFact

public Fact newFact(Fact f)
             throws RemoteException
Specified by:
newFact in interface Mess

assert

public void assert(String s)
            throws RemoteException
Specified by:
assert in interface Mess

assert

public void assert(Fact f)
Specified by:
assert in interface Mess

assertStringFact

public Fact assertStringFact(String fact)
Asserts a fact as a string and returns the Fact object
Parameters:
fact - a String encoding of the fact to be asserted
Returns:
the Fact object for the newly asserted fact or null if not successful

retract

public void retract(String s)
             throws RemoteException
Specified by:
retract in interface Mess

retract

public void retract(Fact f)
             throws RemoteException
Specified by:
retract in interface Mess

store

public void store(String name,
                  Object value)
           throws RemoteException
Specified by:
store in interface Mess

store

public void store(String name,
                  Value value)
           throws RemoteException

fetch

public String fetch(String name)
             throws RemoteException
Specified by:
fetch in interface Mess

fetchInt

public int fetchInt(String name)
             throws RemoteException
Specified by:
fetchInt in interface Mess

facts

public Vector facts()
             throws RemoteException
Specified by:
facts in interface Mess

loadString

public boolean loadString(String s)
                   throws RemoteException
Description copied from interface: Mess
Loads a set of definitions into the interpreter from a string.
Specified by:
loadString in interface Mess

loadReader

public boolean loadReader(Reader i)
Returns true on success or false otherwise

loadURL

public boolean loadURL(String urlString)
Description copied from interface: Mess
Loads a set of definitions into the interpreter from a URL. If the URL is not fully specified, an intelligent base URL will be used to resolve ambiguity. If the loaded code includes the `(run)' directive, this will also run the expert system to completion.
Specified by:
loadURL in interface Mess

loadScript

public boolean loadScript(String packageList)
                   throws RemoteException
Specified by:
loadScript in interface Mess

loadFile

public boolean loadFile(String fname)
Description copied from interface: Mess
Loads a set of definitions into the interpreter from a filename.
Specified by:
loadFile in interface Mess

execCommand

public void execCommand(String cmd)
Description copied from interface: Mess
Passes a JESS command to the engine.
Specified by:
execCommand in interface Mess

addUserfunction

public void addUserfunction(Serializable uf)
                     throws RemoteException
Specified by:
addUserfunction in interface Mess

loadGrammar

public AppGrammar loadGrammar(String grammar)
                       throws RemoteException

acceptedTagsResult

public void acceptedTagsResult(Hashtable tags)
                        throws RemoteException
For incoming speech--chop into bits and send on to mess scripts.
Specified by:
acceptedTagsResult in interface RemoteTagsListener

messThink

public void messThink(String s)

messAsk

public int messAsk(String question)

messAskFree

public String messAskFree(String question)

messSay

public void messSay(String s)

messSaySync

public void messSaySync(String s)

messSaySafe

public void messSaySafe(String s)

assertSpeechTag

public void assertSpeechTag(String tagName,
                            String tagValue)
                     throws RemoteException
Asserts speech tag as an instance of a heard fact in JESS.
Specified by:
assertSpeechTag in interface Mess

assertAttribute

public void assertAttribute(String attrName)
                     throws RemoteException
This method asserts a fact of type attribute. This fact contains slots: string, int and boolean. The string slot is always filled. The other two are filled only if it makes sense. Of course the value put in the slots is the value of the attribute whose name is passed as the argument to this method.
Specified by:
assertAttribute in interface Mess

addMessSpy

public void addMessSpy(String noteType)
Helper method used by extentions/MessAddSpy.java

tell

public void tell(Secret s)
          throws RemoteException
This method receives notifications on behalf of JESS. When a notification for this agent arrives, a fact of type "message" is asserted inside JESS
Overrides:
tell in class GoodAgent

getName

public String getName()
The two methods below provide a relies-on function for JESS
Specified by:
getName in interface Userfunction

call

public Value call(ValueVector vv,
                  Context c)
           throws JessException
Specified by:
call in interface Userfunction