com.haley.haleyrules
Interface WorkingMemory


public interface WorkingMemory

The WorkingMemory interface represents an Eclipse Working Memory. A WorkingMemory should only be accessed by a single Java thread at a time.


Method Summary
 void assertOrUpdate(java.lang.Object object)
          Assert or update an Object into this WorkingMemory.
 Stream findStream(java.lang.String logicalName)
          Returns the logical stream if it exists otherwise null
 ObjectIterator getAssertedObjects()
          Returns an iterator for the asserted objects in this working memory.
 KnowledgeBase getKnowledgeBase()
          Returns the knowledge base for this working memory.
 java.lang.Object getObject()
          Returns the object that was associated with the working memory, which may be null
 java.util.Date getWorkingMemoryTime()
          Returns the time that a working memory uses to determine whether or not a rule is effective or has expired.
 boolean isAsserted(java.lang.Object object)
          Determines if the given object is currently asserted in the working memory.
 boolean isHalted()
          Returns true iff the inference engine was explicitly halted.
 boolean isRunning()
          Indicates whether a call to run() is still executing for a working memory.
 void loadFactFile(java.lang.String filename)
          This function loads a file containing facts.
 void loadXMLfromFile(java.lang.String filename)
          This function loads XML from a file
 void loadXMLfromReader(java.lang.String systemId, java.io.Reader reader)
          This function loads XML from a reader
 void loadXMLfromString(java.lang.String systemId, java.lang.String xmlData)
          This function loads XML from a string
 void loadXMLfromURL(java.net.URL url)
          This function loads XML from an URL
 StringOutputStream newOutputStream(java.lang.String logicalName, int initialCapacity)
          Creates a new logical in-memory output stream for this working memory.
 OutputStream newOutputStream(java.lang.String logicalName, java.lang.String filename, boolean append)
          Creates a new logical file-based output stream for this working memory.
 void reset()
          Retracts all facts from the WorkingMemory and asserts the initial-fact as well as all facts found within deffacts constructs
 void retract(java.lang.Object object)
          Retract an object from the WorkingMemory.
 long run()
          Execute an arbitrary number of activations on this WorkingMemory, using all Rulesets and Agendas.
 long run(long limit)
          Execute activations on this WorkingMemory up to a given limit, using all Rulesets and Agendas.
 void setObject(java.lang.Object object)
          Sets the object that was associated with the working memory
 void setWorkingMemoryTime(java.util.Date date)
          Sets the time that a working memory uses to determine whether or not a rule is effective or has expired.
 

Method Detail

getObject

public java.lang.Object getObject()
                           throws EclipseException
Returns the object that was associated with the working memory, which may be null

Returns:
the object to be associated with the working memory
Throws:
EclipseException - if the working memory has been deleted

setObject

public void setObject(java.lang.Object object)
               throws EclipseException
Sets the object that was associated with the working memory

Parameters:
object - the object to be associated with the working memory
Throws:
EclipseException

getKnowledgeBase

public KnowledgeBase getKnowledgeBase()
                               throws EclipseException
Returns the knowledge base for this working memory.

Returns:
the knowledge base
Throws:
EclipseException - if the working memory has been deleted

reset

public void reset()
           throws EclipseException
Retracts all facts from the WorkingMemory and asserts the initial-fact as well as all facts found within deffacts constructs

Throws:
EclipseException - if the working memory has been deleted
EclipseException - if an error occurred

run

public long run(long limit)
         throws EclipseException
Execute activations on this WorkingMemory up to a given limit, using all Rulesets and Agendas. For an arbitrary number of activations pass -1 for the limit

Parameters:
limit - the maximum number of activations to execute, where a negative number for no limit.
Returns:
the number of rules executed
Throws:
EclipseException - if the working memory has been deleted
EclipseException - if Java code (invoked via JNI native code) throws an exception or the run failed
EclipseException - if an error occurred
See Also:
run(), Ruleset.run(WorkingMemory), Ruleset.run(WorkingMemory,long), Agenda.run(WorkingMemory), Agenda.run(WorkingMemory,long)

run

public long run()
         throws EclipseException
Execute an arbitrary number of activations on this WorkingMemory, using all Rulesets and Agendas.

Returns:
the number of activations executed
Throws:
EclipseException - if the working memory has been deleted
EclipseException - if Java code (invoked via JNI native code) throws an exception
EclipseException - if an error occurred
See Also:
run(long), Ruleset.run(WorkingMemory), Ruleset.run(WorkingMemory,long), Agenda.run(WorkingMemory), Agenda.run(WorkingMemory,long)

isHalted

public boolean isHalted()
                 throws EclipseException
Returns true iff the inference engine was explicitly halted. The inference engine may be explicly halted by calling (halt) within the right hand side of a rule. This is typically used to determine whether or not execution reached an explicit halt rather than exhaustion of all executions, reaching the limit specified in a call to run, or a breakpoint.

Returns:
true if and only if a rule explicitly halted execution for a working memory.
Throws:
EclipseException - if the working memory has been deleted
EclipseException - if Java code (invoked via JNI native code) throws an exception
EclipseException - if an error occurred
See Also:
run(), run(long), Ruleset.run(WorkingMemory), Ruleset.run(WorkingMemory,long), Agenda.run(WorkingMemory), Agenda.run(WorkingMemory,long)

isRunning

public boolean isRunning()
                  throws EclipseException
Indicates whether a call to run() is still executing for a working memory.

Returns:
true if and only if Eclipse is running for the working memory.
Throws:
EclipseException - if the working memory has been deleted
EclipseException - if an error occurred
See Also:
run(), run(long), Ruleset.run(WorkingMemory), Ruleset.run(WorkingMemory,long), Agenda.run(WorkingMemory), Agenda.run(WorkingMemory,long)

getWorkingMemoryTime

public java.util.Date getWorkingMemoryTime()
                                    throws EclipseException
Returns the time that a working memory uses to determine whether or not a rule is effective or has expired.

Returns:
the time that a working memory uses to determine whether or not a rule is effective or has expired
Throws:
EclipseException - if the working memory has been deleted
EclipseException - if an error occurred
See Also:
setWorkingMemoryTime(Date), Rule.getEffectiveDate(), Rule.getExpirationDate()

setWorkingMemoryTime

public void setWorkingMemoryTime(java.util.Date date)
                          throws EclipseException
Sets the time that a working memory uses to determine whether or not a rule is effective or has expired.

Parameters:
date - the time that a working memory uses to determine whether or not a rule is effective or has expired
Throws:
EclipseException - if the working memory has been deleted
EclipseException - if an error occurred
See Also:
getWorkingMemoryTime(), Rule.getEffectiveDate(), Rule.getExpirationDate()

loadFactFile

public void loadFactFile(java.lang.String filename)
                  throws EclipseException
This function loads a file containing facts.

Parameters:
filename - the filename to load
Throws:
EclipseException - if this method is not supported
EclipseException - if unable to open the file

assertOrUpdate

public void assertOrUpdate(java.lang.Object object)
                    throws EclipseException
Assert or update an Object into this WorkingMemory.

Parameters:
object - an Object
Throws:
EclipseException - if the working memory has been deleted
EclipseException - if an error occurred

retract

public void retract(java.lang.Object object)
             throws EclipseException
Retract an object from the WorkingMemory.

Parameters:
object - an Object
Throws:
EclipseException

isAsserted

public boolean isAsserted(java.lang.Object object)
                   throws EclipseException
Determines if the given object is currently asserted in the working memory.

Parameters:
object - an Object
Returns:
true if the given object has been asserted via assertOrUpdate(Object) and not subsequently retracted via retract(Object)
Throws:
EclipseException

loadXMLfromReader

public void loadXMLfromReader(java.lang.String systemId,
                              java.io.Reader reader)
                       throws EclipseException
This function loads XML from a reader

Parameters:
systemId - the identifier for the XML
reader - the source for the XML
Throws:
EclipseException - if the working memory has been deleted
EclipseException - if an error occurred

loadXMLfromString

public void loadXMLfromString(java.lang.String systemId,
                              java.lang.String xmlData)
                       throws EclipseException
This function loads XML from a string

Parameters:
systemId - the identifier for the XML
xmlData - the source for the XML
Throws:
EclipseException - if the working memory has been deleted
EclipseException - if an error occurred

loadXMLfromFile

public void loadXMLfromFile(java.lang.String filename)
                     throws EclipseException
This function loads XML from a file

Parameters:
filename - the filename containing the XML
Throws:
EclipseException - if the working memory has been deleted
EclipseException - if an error occurred

loadXMLfromURL

public void loadXMLfromURL(java.net.URL url)
                    throws EclipseException
This function loads XML from an URL

Parameters:
url - the URL containing the XML
Throws:
EclipseException - if the working memory has been deleted
EclipseException - if an error occurred

getAssertedObjects

public ObjectIterator getAssertedObjects()
                                  throws EclipseException
Returns an iterator for the asserted objects in this working memory.

Returns:
an ObjectIterator that iterates over all objects placeed into this working memory by assertOrUpdate(Object).
Throws:
EclipseException - if an error occurred

newOutputStream

public StringOutputStream newOutputStream(java.lang.String logicalName,
                                          int initialCapacity)
                                   throws EclipseException
Creates a new logical in-memory output stream for this working memory. An in-memory stream is StringOutputStream.reset() when the working memory is reset and Stream.close() is called when the working memory is deleted

Parameters:
logicalName - the logical name for the stream that may be used in stream functions accessible to rules
initialCapacity - the initial capacity of the stream
Returns:
a new in-memory output stream for this working memory
Throws:
EclipseException - if a logical stream with the given name already exists

newOutputStream

public OutputStream newOutputStream(java.lang.String logicalName,
                                    java.lang.String filename,
                                    boolean append)
                             throws EclipseException,
                                    java.io.FileNotFoundException
Creates a new logical file-based output stream for this working memory. When the working memory is reset or removed, then Stream.close() is called for the stream.

Parameters:
logicalName - the logical name for the stream that may be used in stream functions accessible to rules
filename - the filename for the output stream
append - if true, then bytes will be written to the end of the file rather than the beginning
Returns:
a new in-memory output stream for this working memory
Throws:
EclipseException - if a logical stream with the given name already exists
java.io.FileNotFoundException

findStream

public Stream findStream(java.lang.String logicalName)
                  throws EclipseException
Returns the logical stream if it exists otherwise null

Parameters:
logicalName - the logical name for the stream that may be used in stream functions accessible to rules
Returns:
the stream with the specified logical name
Throws:
EclipseException - if an error occurred


Copyright © 1998-2006 Haley Systems, Inc. All Rights Reserved.