com::declarativa::interprolog::PrologEngine Class Reference

Inheritance diagram for com::declarativa::interprolog::PrologEngine:

com::declarativa::interprolog::SubprocessEngine com::xsb::interprolog::NativeEngine

Public Member Functions

 PrologEngine (String startPrologCommand, boolean debug)
abstract void shutdown ()
File getJarDirectory ()
void consultFromPackage (String filename, Object requester)
void consultRelative (String filename, Object requester)
void load_dynRelative (String filename, Object requester)
void interrupt ()
boolean command (String s)
void progressMessage (String s)
boolean isDebug ()
void setDebug (boolean d)
boolean teachOneObject (Object example)
boolean teachMoreObjects (Object[] examples)
boolean teachMoreObjects (ObjectExamplePair[] examples)
Object[] deterministicGoal (String G, String OVar, Object[] objectsP, String RVars)
boolean deterministicGoal (String G)
Object[] deterministicGoal (String G, String RVars)
boolean deterministicGoal (String G, String OVar, Object[] objectsP)
synchronized boolean isIdle ()
synchronized void abortTasks ()
synchronized void interruptTasks ()
boolean isAvailable ()
void waitUntilAvailable ()
void waitUntilIdle ()
Object handleCallback (Object x)
final void firstJavaMessage ()
ResultFromJava doCallback (Object x)
int registerJavaObject (Object x)
Object makeInvisible (Object x)
Object getRealJavaObject (InvisibleObject o)
Object getRealJavaObject (int ID)
Object getRealJavaObject (Object o)

Static Public Member Functions

static File getJarDirectory (Class aClass)
static void printBindings (Object[] b)
static Method findMethod (Class targetClass, String name, Class[] formalArguments) throws NoSuchMethodException
static Constructor findConstructor (Class targetClass, Class[] formalArguments) throws NoSuchMethodException
static boolean assignableType (Class left, Class right)
static String shortClassName (Class c)

Data Fields

String startPrologCommand
boolean interrupting = false
final String firstJavaMessageName = "firstJavaMessage"

Static Public Attributes

static final String version = "2.0b1"
static final String nl = System.getProperty("line.separator")
static final int MAX_INT_VALUE = 134217727
static final int MIN_INT_VALUE = -134217728

Protected Member Functions

boolean isShutingDown ()
void operationRelative (String operation, String filename, Object requester)
abstract boolean realCommand (String s)
final void teachIPobjects (ObjectOutputStream obs) throws IOException
void teachBasicObjects (ObjectOutputStream obs) throws IOException
GoalFromJava makeDGoalObject (String G, String OVar, Object[] objectsP, String RVars, int timestamp)
int incGoalTimestamp ()
synchronized void scheduleGoal (GoalToExecute g)
synchronized GoalToExecute moreRecentToExecute ()
synchronized GoalToExecute forgetGoal (int timestamp)
synchronized void addMessage (MessageExecuting m)
synchronized void forgetMessage (MessageExecuting m)
synchronized MessageExecuting lastMessageRequest ()
Object doSomething ()

Protected Attributes

long startTime
File tempDirectory
ObjectRegistry knownObjects
boolean shutingDown = false
boolean debug = false
boolean topGoalHasStarted = false
int goalTimestamp

Static Protected Attributes

static int numberOfInstances = 0

Package Functions

void makeTempDirectory ()
File copyToTemp (String filename, Object requester)

Package Attributes

Vector goalsToExecute
Vector messagesExecuting
final Method getRealJavaObjectMethod

Detailed Description

The heart of InterProlog; a PrologEngine represents a Prolog abstract machine instance. This is an abstract class; you should use it just to declare variables, but must instantiate only a subclass.

Definition at line 19 of file PrologEngine.java.


Constructor & Destructor Documentation

com::declarativa::interprolog::PrologEngine::PrologEngine String  startPrologCommand,
boolean  debug
[inline]
 

Create a Prolog executor, possibly spawning it in a different process or loading it into memory, depending on the implementation by our subclass.

Parameters:
startPrologCommand File path to Prolog machine, see subclass docs for precise semantics
debug if true, print progress messages to aid debugging

Definition at line 63 of file PrologEngine.java.

References findMethod(), getRealJavaObjectMethod, goalsToExecute, knownObjects, makeTempDirectory(), messagesExecuting, numberOfInstances, setDebug(), shutdown(), and startTime.


Member Function Documentation

synchronized void com::declarativa::interprolog::PrologEngine::abortTasks  )  [inline]
 

Do not invoke this

Definition at line 503 of file PrologEngine.java.

Referenced by com::xsb::interprolog::NativeEngine::startTopGoal().

synchronized void com::declarativa::interprolog::PrologEngine::addMessage MessageExecuting  m  )  [inline, protected]
 

Just adds to messagesExecuting

Definition at line 482 of file PrologEngine.java.

static boolean com::declarativa::interprolog::PrologEngine::assignableType Class  left,
Class  right
[inline, static]
 

It is OK to assign an expression typed right to a variable typed left. Delegates on isAssignableFrom

Definition at line 759 of file PrologEngine.java.

boolean com::declarativa::interprolog::PrologEngine::command String  s  )  [inline]
 

Execute a Prolog "command"

Definition at line 224 of file PrologEngine.java.

Referenced by com::declarativa::interprolog::gui::ListenerWindow::ListenerWindow(), com::declarativa::interprolog::examples::HelloWorld::main(), and com::xsb::interprolog::NativeEngine::NativeEngine().

void com::declarativa::interprolog::PrologEngine::consultFromPackage String  filename,
Object  requester
[inline]
 

Extracts a Prolog file from the jar file or directory where the requester's class came from, and asks the background Prolog process to consult it. You should use this method only after your program is stable. The Prolog file is extracted to a temporary file, and automatically deleted on exiting the application.

Parameters:
filename The Prolog file name, including suffix; if absent ".P" is appended
requester Defines where the Prolog file resides
See also:
consultRelative(String, Object)

load_dynRelative(String, Object)

Definition at line 173 of file PrologEngine.java.

Referenced by com::declarativa::interprolog::gui::ListenerWindow::ListenerWindow(), and com::xsb::interprolog::NativeEngine::NativeEngine().

void com::declarativa::interprolog::PrologEngine::consultRelative String  filename,
Object  requester
[inline]
 

Consults a Prolog file from the directory where the requester's class would come from if it did not come from a jar file. Adds that directory to the library_directory relation, so modules can be found there

Parameters:
filename The Prolog file name, including suffix; if absent ".P" is appended
requester Defines where the Prolog file resides

Definition at line 187 of file PrologEngine.java.

boolean com::declarativa::interprolog::PrologEngine::deterministicGoal String  G,
String  OVar,
Object[]  objectsP
[inline]
 

Useful when you want to pass objects to Prolog but don't need objects returned. Same as deterministicGoal(G, OVar,objectsP,"[]")

Definition at line 444 of file PrologEngine.java.

Object [] com::declarativa::interprolog::PrologEngine::deterministicGoal String  G,
String  RVars
[inline]
 

Useful when you're constructing objects from Prolog, but don't need to pass any from Java. Same as deterministicGoal(G,null,null,RVars)

Definition at line 439 of file PrologEngine.java.

boolean com::declarativa::interprolog::PrologEngine::deterministicGoal String  G  )  [inline]
 

A parameterless goal with no result other than success/failure. Same as deterministicGoal(G, null,null,"[]")

Definition at line 434 of file PrologEngine.java.

Object [] com::declarativa::interprolog::PrologEngine::deterministicGoal String  G,
String  OVar,
Object[]  objectsP,
String  RVars
[inline]
 

Synchronously calls a Prolog goal. Only the first solution is considered. G should contain a syntactically correct Prolog term, without the trailing dot (.). Throws an IPAbortedException if a Prolog abort happens, and an IPInterruptedException if the interrupt() method was invoked.

See also:
deterministicGoal(String)

deterministicGoal(String,String)

deterministicGoal(String,String,Object[])

Returns:
a new array containing an object for each term in the rVars list, or null if goal fails
Parameters:
G Prolog goal term
OVar Prolog variable that will be bound to objectsP array
objectsP Array of Java objects to pass to Prolog goal
RVars Prolog list with object specifications, typically containing variables occurring in g. If null a single binding will be returned, containing a TermModel object representing the goal term solution

Reimplemented in com::declarativa::interprolog::SubprocessEngine, and com::xsb::interprolog::NativeEngine.

Definition at line 405 of file PrologEngine.java.

References com::declarativa::interprolog::util::ResultFromProlog::error, com::declarativa::interprolog::util::ResultFromProlog::rVars, com::declarativa::interprolog::util::ResultFromProlog::succeeded, and com::declarativa::interprolog::util::ResultFromProlog::timestamp.

Referenced by com::declarativa::interprolog::gui::PrologEventBroker::actionPerformed(), com::declarativa::interprolog::gui::RelationTreeNode::getChild(), com::declarativa::interprolog::gui::RelationTreeNode::getChildCount(), com::declarativa::interprolog::gui::RelationTreeNode::getIndexOfChild(), com::declarativa::interprolog::examples::HelloWindow::HelloWindow(), com::declarativa::interprolog::examples::HelloWorld::main(), com::declarativa::interprolog::examples::BackEnd::main(), com::declarativa::interprolog::gui::TermModelWindow::TermModelWindow(), and com::declarativa::interprolog::gui::RelationTreeNode::toString().

ResultFromJava com::declarativa::interprolog::PrologEngine::doCallback Object  x  )  [inline]
 

Execute a Prolog->Java call

Definition at line 604 of file PrologEngine.java.

References com::declarativa::interprolog::util::MessageFromProlog::arguments, and com::declarativa::interprolog::util::MessageFromProlog::target.

Referenced by com::declarativa::interprolog::util::MessageExecuting::run().

Object com::declarativa::interprolog::PrologEngine::doSomething  )  [inline, protected]
 

return result to last javaMessage or pick more recent GoalToExecute

Reimplemented in com::declarativa::interprolog::SubprocessEngine.

Definition at line 571 of file PrologEngine.java.

References com::declarativa::interprolog::util::MessageExecuting::getResult(), and com::declarativa::interprolog::util::MessageExecuting::hasEnded().

static Constructor com::declarativa::interprolog::PrologEngine::findConstructor Class  targetClass,
Class[]  formalArguments
throws NoSuchMethodException [inline, static]
 

Similar to findMethod(), but for constructors rather than regular methods

Definition at line 729 of file PrologEngine.java.

static Method com::declarativa::interprolog::PrologEngine::findMethod Class  targetClass,
String  name,
Class[]  formalArguments
throws NoSuchMethodException [inline, static]
 

An utility building on the functionality of getMethod(), to provide the javaMessage predicate with method argument polimorphism. If the type signatures do not match exactly, searches all method signatures to see if their arguments are type-compatible.

Definition at line 692 of file PrologEngine.java.

Referenced by PrologEngine().

final void com::declarativa::interprolog::PrologEngine::firstJavaMessage  )  [inline]
 

Dummy method, whose name is used to start the callback thread

Definition at line 599 of file PrologEngine.java.

synchronized GoalToExecute com::declarativa::interprolog::PrologEngine::forgetGoal int  timestamp  )  [inline, protected]
 

Currently does a dumb linear search, enough for our scenarios. 2 possibilities: use Hashtable; make ResultFromProlog bring back a reference to GoalFromJava

Definition at line 470 of file PrologEngine.java.

static File com::declarativa::interprolog::PrologEngine::getJarDirectory Class  aClass  )  [inline, static]
 

Returns the directory containing the jar with the given class

Definition at line 109 of file PrologEngine.java.

File com::declarativa::interprolog::PrologEngine::getJarDirectory  )  [inline]
 

Returns the directory containing the jar with the engine class

Definition at line 104 of file PrologEngine.java.

Object com::declarativa::interprolog::PrologEngine::getRealJavaObject Object  o  )  [inline]
 

Just returns the object, untouched (but "dereferenced" if called from Prolog). This serves the need to get objects in javaMessage because of the way CallbackHandler.doCallback works. For example: ipPrologEngine(_E), stringArraytoList(_O,[miguel,calejo]), javaMessage(_E,_R,getRealJavaObject(_O)),stringArraytoList(_R,List). ... will bind List to [miguel,calejo] and not to an InvisibleObject specification as ordinarly would happen

Definition at line 810 of file PrologEngine.java.

Object com::declarativa::interprolog::PrologEngine::getRealJavaObject int  ID  )  [inline]
 

Same as getRealJavaObject(InvisibleObject), but accepts an integer ID as argument instead

Definition at line 800 of file PrologEngine.java.

Object com::declarativa::interprolog::PrologEngine::getRealJavaObject InvisibleObject  o  )  [inline]
 

Get the object referred by the integer in a InvisibleObject wrapper.

Parameters:
o An InvisibleObject
Returns:
The real object denoted by o in the context of this engine
See also:
InvisibleObject

Definition at line 796 of file PrologEngine.java.

Object com::declarativa::interprolog::PrologEngine::handleCallback Object  x  )  [inline]
 

Handling of javaMessages and deterministicGoals. This is where most things happen.

Parameters:
x Argument of the callback predicate

Definition at line 546 of file PrologEngine.java.

References com::declarativa::interprolog::util::GoalToExecute::setResult(), and com::declarativa::interprolog::util::ResultFromProlog::timestamp.

Referenced by com::xsb::interprolog::NativeEngine::callback().

void com::declarativa::interprolog::PrologEngine::interrupt  )  [inline]
 

Interrupt Prolog and make it return to its top level. This is the equivalent to performing a ctrl+c or similar command when using Prolog under a standard console shell.

Definition at line 214 of file PrologEngine.java.

synchronized void com::declarativa::interprolog::PrologEngine::interruptTasks  )  [inline]
 

Do not invoke this

Definition at line 513 of file PrologEngine.java.

Referenced by com::xsb::interprolog::NativeEngine::startTopGoal().

boolean com::declarativa::interprolog::PrologEngine::isAvailable  )  [inline]
 

Present implementation is always available, so this always returns true

Reimplemented in com::declarativa::interprolog::SubprocessEngine.

Definition at line 523 of file PrologEngine.java.

boolean com::declarativa::interprolog::PrologEngine::isDebug  )  [inline]
 

Debug messages are being written

Definition at line 240 of file PrologEngine.java.

Referenced by com::declarativa::interprolog::gui::ListenerWindow::ListenerWindow().

synchronized boolean com::declarativa::interprolog::PrologEngine::isIdle  )  [inline]
 

The engine is doing nothing

Reimplemented in com::xsb::interprolog::NativeEngine.

Definition at line 498 of file PrologEngine.java.

boolean com::declarativa::interprolog::PrologEngine::isShutingDown  )  [inline, protected]
 

This implementation returns false

Reimplemented in com::declarativa::interprolog::SubprocessEngine.

Definition at line 83 of file PrologEngine.java.

Object com::declarativa::interprolog::PrologEngine::makeInvisible Object  x  )  [inline]
 

Register an object with this Engine, so it later can be referred from Prolog without serializing it, and returns an InvisibleObject encapsulating the reference.

Parameters:
x Object to be registered
Returns:
InvisibleObject denoting the object. In Prolog one can then refer to it by using the InvisibleObject class.
See also:
InvisibleObject

Definition at line 787 of file PrologEngine.java.

Referenced by com::declarativa::interprolog::examples::HelloWindow::HelloWindow().

static void com::declarativa::interprolog::PrologEngine::printBindings Object[]  b  )  [inline, static]
 

Convenience for debugging

Definition at line 245 of file PrologEngine.java.

void com::declarativa::interprolog::PrologEngine::progressMessage String  s  )  [inline]
 

Debugging aid

Definition at line 234 of file PrologEngine.java.

Referenced by com::xsb::interprolog::NativeEngine::callback(), com::xsb::interprolog::NativeEngine::NativeEngine(), and com::xsb::interprolog::NativeEngine::startTopGoal().

abstract boolean com::declarativa::interprolog::PrologEngine::realCommand String  s  )  [protected, pure virtual]
 

Implementation of a simple parameterless Prolog goal; does not support recursive nor multithreaded operation, use command instead

See also:
command(String)

Implemented in com::declarativa::interprolog::SubprocessEngine, and com::xsb::interprolog::NativeEngine.

int com::declarativa::interprolog::PrologEngine::registerJavaObject Object  x  )  [inline]
 

Register an object with this Engine, so it later can be referred from Prolog without serializing it.

Parameters:
x Object to be registered
Returns:
Integer denoting the object. In Prolog one can then refer to it by using the InvisibleObject class.
See also:
InvisibleObject

Definition at line 777 of file PrologEngine.java.

Referenced by com::declarativa::interprolog::gui::PrologEventBroker::actionPerformed(), com::declarativa::interprolog::examples::HelloWindow2::HelloWindow2(), and com::xsb::interprolog::NativeEngine::NativeEngine().

synchronized void com::declarativa::interprolog::PrologEngine::scheduleGoal GoalToExecute  g  )  [inline, protected]
 

Adds goal to pool awaiting execution by Prolog

Definition at line 456 of file PrologEngine.java.

abstract void com::declarativa::interprolog::PrologEngine::shutdown  )  [pure virtual]
 

Release Prolog engine resources, making it unusable

Implemented in com::declarativa::interprolog::SubprocessEngine, and com::xsb::interprolog::NativeEngine.

Referenced by PrologEngine().

void com::declarativa::interprolog::PrologEngine::teachBasicObjects ObjectOutputStream  obs  )  throws IOException [inline, protected]
 

Provide Prolog with material to construct special objects that actually represent basic type values, so that Prolog can call (through javaMessage) methods with basic type (non-object) arguments. Also provides material for some other convenience objects

Definition at line 302 of file PrologEngine.java.

Referenced by com::xsb::interprolog::NativeEngine::NativeEngine().

boolean com::declarativa::interprolog::PrologEngine::teachMoreObjects ObjectExamplePair[]  examples  )  [inline]
 

Send an array of object example pairs to Prolog and generate ipObjectSpec facts. Returns true if this succeeds, false otherwise.

Parameters:
examples The examples
See also:
ObjectExamplePair

Definition at line 370 of file PrologEngine.java.

boolean com::declarativa::interprolog::PrologEngine::teachMoreObjects Object[]  examples  )  [inline]
 

Same as teachMoreObjects(ObjectExamplePair[]), but example pairs are constructed with (2) repeated examples for each object

See also:
teachMoreObjects(ObjectExamplePair[])

Definition at line 357 of file PrologEngine.java.

Referenced by com::declarativa::interprolog::gui::ListenerWindow::ListenerWindow().

boolean com::declarativa::interprolog::PrologEngine::teachOneObject Object  example  )  [inline]
 

Same as teachMoreObjects(ObjectExamplePair[]), but the single example pair is constructed repeating the object

See also:
teachMoreObjects(ObjectExamplePair[])

Definition at line 351 of file PrologEngine.java.

Referenced by com::declarativa::interprolog::examples::BackEnd::main().

void com::declarativa::interprolog::PrologEngine::waitUntilIdle  )  [inline]
 

Sleeps the current Java thread until this engine is available. If this never happens, we're in trouble.

Definition at line 536 of file PrologEngine.java.


Field Documentation

final String com::declarativa::interprolog::PrologEngine::firstJavaMessageName = "firstJavaMessage"
 

Name of first message sent to Java

Definition at line 49 of file PrologEngine.java.

Referenced by com::xsb::interprolog::NativeEngine::startTopGoal().

final Method com::declarativa::interprolog::PrologEngine::getRealJavaObjectMethod [package]
 

"Constant" used for some special javaMessage handling

Definition at line 47 of file PrologEngine.java.

Referenced by PrologEngine().

Vector com::declarativa::interprolog::PrologEngine::goalsToExecute [package]
 

Prolog Goals whose execution has not yet finished or whose results have not yet been returned to their Java clients

Definition at line 42 of file PrologEngine.java.

Referenced by PrologEngine().

int com::declarativa::interprolog::PrologEngine::goalTimestamp [protected]
 

goal counter

Definition at line 39 of file PrologEngine.java.

boolean com::declarativa::interprolog::PrologEngine::interrupting = false
 

Prolog is handling an interrupt

Definition at line 35 of file PrologEngine.java.

Referenced by com::xsb::interprolog::NativeEngine::startTopGoal().

ObjectRegistry com::declarativa::interprolog::PrologEngine::knownObjects [protected]
 

Table of object references that can be referred from Prolog without being serialized

Definition at line 32 of file PrologEngine.java.

Referenced by PrologEngine().

final int com::declarativa::interprolog::PrologEngine::MAX_INT_VALUE = 134217727 [static]
 

Maximum integer value. 28 bits is all we got on XSB Prolog

Definition at line 55 of file PrologEngine.java.

Vector com::declarativa::interprolog::PrologEngine::messagesExecuting [package]
 

javaMessage requests that have started execution and whose results have not yet been returned to Prolog.

Definition at line 44 of file PrologEngine.java.

Referenced by PrologEngine().

final int com::declarativa::interprolog::PrologEngine::MIN_INT_VALUE = -134217728 [static]
 

Minimum integer value.

Definition at line 57 of file PrologEngine.java.

final String com::declarativa::interprolog::PrologEngine::nl = System.getProperty("line.separator") [static]
 

Convenience for newline

Definition at line 27 of file PrologEngine.java.

String com::declarativa::interprolog::PrologEngine::startPrologCommand
 

File path to Prolog machine

Definition at line 24 of file PrologEngine.java.

File com::declarativa::interprolog::PrologEngine::tempDirectory [protected]
 

Temporary directory where Prolog files are unjared to. It is automatically declared as a Prolog library_directory

Definition at line 29 of file PrologEngine.java.

Referenced by com::xsb::interprolog::NativeEngine::NativeEngine().

final String com::declarativa::interprolog::PrologEngine::version = "2.0b1" [static]
 

InterProlog version

Definition at line 22 of file PrologEngine.java.


The documentation for this class was generated from the following file:
Generated on Wed Jul 26 13:30:52 2006 for XSB by  doxygen 1.4.5