com::declarativa::interprolog::SubprocessEngine Class Reference

Inheritance diagram for com::declarativa::interprolog::SubprocessEngine:

com::declarativa::interprolog::PrologEngine

Public Member Functions

synchronized void addPrologOutputListener (PrologOutputListener client)
synchronized void removePrologOutputListener (PrologOutputListener client)
void addPrologStdoutListener (OutputListener l)
void addPrologStderrListener (OutputListener l)
void removePrologStdoutListener (OutputListener l)
void removePrologStderrListener (OutputListener l)
 SubprocessEngine (String startPrologCommand, boolean debug)
 SubprocessEngine (String startPrologCommand)
boolean isAvailable ()
synchronized void shutdown ()
synchronized void sendAndFlush (String s)
void sendAndFlushLn (String s)
Object[] deterministicGoal (String G, String OVar, Object[] objectsP, String RVars)

Protected Member Functions

void setupCallbackServer ()
Object receiveObject () throws IOException
void sendObject (Object y) throws IOException
boolean isShutingDown ()
void finalize () throws Throwable
void setDetectPromptAndBreak (boolean yes)
boolean isDetectingPromptAndBreak ()
void prepareInterrupt (String myHost) throws IOException
synchronized void doInterrupt ()
boolean realCommand (String s)
Object[] firstGoal (String G, String OVar, Object[] objectsP, String RVars)
Object doSomething ()
synchronized boolean onlyFirstGoalSchedulled ()
void setupErrorHandling ()
void removeErrorHandling ()

Static Protected Member Functions

static boolean needsSocketInterrupt ()

Protected Attributes

Socket socket

Package Attributes

Process prolog
PrintWriter prologStdin
OutputHandler stdoutHandler
OutputHandler stderrHandler
ServerSocket serverSocket
ServerSocket intServerSocket = null
Socket intSocket = null
String interruptCommand = null
Vector listeners = new Vector ()
boolean available
Recognizer promptTrigger = new Recognizer("| ?-")
Recognizer breakTrigger = new Recognizer(": ?-")
Recognizer errorTrigger = new Recognizer("++Error",true)

Detailed Description

A PrologEngine implemented over TCP/IP sockets. A SubprocessEngine object represents and gives access to a running Prolog process in background. Multiple instances correspond to multiple Prolog processes, outside the Java Virtual Machine.

Definition at line 19 of file SubprocessEngine.java.


Constructor & Destructor Documentation

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

Construct a SubprocessEngine, launching a Prolog process in background.

Parameters:
startPrologCommand The command to launch Prolog, as if given from a console shell. Must not be null.
debug If true this engine will send debugging messages to System.out
See also:
SubprocessEngine::shutdown

SubprocessEngine::teachMoreObjects(ObjectExamplePair[])

SubprocessEngine::setDebug(boolean)

Definition at line 96 of file SubprocessEngine.java.

References com::declarativa::interprolog::util::PrologOutputObjectStream::flush(), and com::declarativa::interprolog::util::PrologOutputObjectStream::getObjectStream().


Member Function Documentation

synchronized void com::declarativa::interprolog::SubprocessEngine::addPrologOutputListener PrologOutputListener  client  )  [inline]
 

Add a PrologOutputListener to this engine. All stdout and stderr output will be routed to the client.

Parameters:
client An object interested in receiving messages depicting Prolog's progress
See also:
com.declarativa.interprolog.PrologOutputListener

Definition at line 45 of file SubprocessEngine.java.

References addPrologStderrListener(), addPrologStdoutListener(), and listeners.

void com::declarativa::interprolog::SubprocessEngine::addPrologStdoutListener OutputListener  l  )  [inline]
 

Add a OutputListener to get output from Prolog's standard output. This is a lower level interface than addPrologOutputListener(PrologOutputListener).

Parameters:
client An object interested in Prolog's standard output
See also:
com.declarativa.interprolog.util.OutputListener

Definition at line 69 of file SubprocessEngine.java.

Referenced by addPrologOutputListener().

Object [] com::declarativa::interprolog::SubprocessEngine::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 from com::declarativa::interprolog::PrologEngine.

Definition at line 347 of file SubprocessEngine.java.

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

return result to last javaMessage or pick more recent GoalToExecute

Reimplemented from com::declarativa::interprolog::PrologEngine.

Definition at line 400 of file SubprocessEngine.java.

void com::declarativa::interprolog::SubprocessEngine::finalize  )  throws Throwable [inline, protected]
 

Kill the Prolog background process. If you wish to make sure this message is sent on exiting, use System.runFinalizersOnExit(true) on initialization

Definition at line 264 of file SubprocessEngine.java.

Object [] com::declarativa::interprolog::SubprocessEngine::firstGoal String  G,
String  OVar,
Object[]  objectsP,
String  RVars
[inline, protected]
 

Very alike deterministicGoal except that it sends the initial GoalFromJava object over the socket

Definition at line 364 of file SubprocessEngine.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.

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

Prolog is thought to be idle

Reimplemented from com::declarativa::interprolog::PrologEngine.

Definition at line 177 of file SubprocessEngine.java.

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

This implementation returns false

Reimplemented from com::declarativa::interprolog::PrologEngine.

Definition at line 257 of file SubprocessEngine.java.

boolean com::declarativa::interprolog::SubprocessEngine::realCommand String  s  )  [inline, protected, virtual]
 

This implementation may get stuck if the command includes variables, because the Prolog top level interpreter may offer to compute more solutions; use variables prefixed with '_'

Implements com::declarativa::interprolog::PrologEngine.

Definition at line 341 of file SubprocessEngine.java.

synchronized void com::declarativa::interprolog::SubprocessEngine::sendAndFlush String  s  )  [inline]
 

Sends a String to Prolog's input. Its meaning will naturally depend on the current state of Prolog: it can be a top goal, or input to an ongoing computation

Definition at line 289 of file SubprocessEngine.java.

synchronized void com::declarativa::interprolog::SubprocessEngine::shutdown  )  [inline, virtual]
 

Shuts down the background Prolog process as well as the dependent Java threads.

Implements com::declarativa::interprolog::PrologEngine.

Definition at line 229 of file SubprocessEngine.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