|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objecthyspirit.engines.HyEngine
public abstract class HyEngine
This class implements all required methods and communications for the HySpirit engines. There are two possible modes:
Created on 02-Dec-2005 10:34:51
| Field Summary | |
|---|---|
protected java.lang.String |
argumentString
|
protected org.apache.log4j.Logger |
LOG
|
boolean |
stdin
|
protected static java.lang.String |
TIME_PREFIX
The prefix that identifies a line returned by the time command |
| Constructor Summary | |
|---|---|
HyEngine(java.lang.String engineName)
This constructor must be used if you are going to start your own engine process (client/server mode). |
|
HyEngine(java.lang.String engineName,
HySpiritProperties hyspirit)
This constructor must be used if you are going to start your own engine process (client/server mode). |
|
HyEngine(java.lang.String engineName,
java.lang.String hostname,
int port)
This constructor must be used if you want to attach to a running engine process (client mode) through a socket |
|
| Method Summary | |
|---|---|
protected java.lang.String[] |
buildCommand()
Builds the command from the parameters. |
void |
closeSTDIN()
Closes the STDIN. |
void |
destroy()
Kills a running process. |
java.lang.String |
echoSpecial(java.lang.String message)
Returns a string which lets the engine echo the given message |
int |
exitValue()
Returns the exit value of the process or -1 if in client mode |
java.lang.String |
getCommand()
Returns the absolute path of the current command if in client/server mode and null if in client mode |
java.lang.String |
getEngineName()
Returns the engine name |
java.io.BufferedReader |
getInputReader()
Gets the input reader, which is STDOUT in client/server mode, and the socket output reader otherwise |
java.io.BufferedWriter |
getOutputWriter()
Gets the output writer, which is STDIN in client/server mode, and the socket input writer otherwise |
java.lang.String |
getPercentageCPU()
If we used the Unix time command, this method gets the elapsed
sys mode CPU seconds |
java.lang.String |
getRealTime()
If we used the Unix time command, this method gets the elapsed
real time in [hours:]minutes:seconds. |
java.io.BufferedReader |
getSTDERR()
Deprecated. STDERR now redirected to System.err. Returns null. |
java.io.BufferedWriter |
getSTDIN()
Gets STDIN if not in clientmode. |
java.io.BufferedReader |
getSTDOUT()
Gets STDOUT if not in clientmode. |
protected java.lang.String |
getStreamEndMessage()
|
java.lang.String |
getSysTime()
If we used the Unix time command, this method gets the elapsed
sys mode CPU seconds |
java.lang.String |
getUserTime()
If we used the Unix time command, this method gets the elapsed
user mode CPU seconds |
boolean |
hasNext()
Returns if there is a next element to read or not. |
boolean |
isInClientMode()
Returns true if this object is in client mode, and false if it is in client/server mode. |
boolean |
isRunning()
Returns true if the underlying process is running, false otherwise. |
HyKB |
kb()
Get the knowledge base of this engine. |
void |
kb(HyKB kb)
Set the knowledge base of this engine. |
void |
kb(java.lang.String kbName)
Set the knowledge base of this engine. |
java.lang.String |
next()
Returns the next line of output from the underlying engine or null if there's nothing more to read. |
void |
readFromSTDIN()
Ensures that the process reads input from STDIN. |
void |
reset()
Resets all parameters of the engine after destroying a possibly running process. |
void |
restart()
Restarts the engine. |
void |
run()
Run command. |
protected void |
send(java.io.BufferedReader input)
|
void |
send(java.lang.String input)
Send input string to engine. |
java.lang.String |
sendAndReceive(java.lang.String input)
This is a convenience method: it sends the input given in the string to the STDIN of the engine and returns the output of the engine. |
void |
sendFile(java.lang.String filename)
Send content of file to engine. |
void |
setArgumentString(java.lang.String argumentString)
Additional arguments which are not supported (yet) by an engine can be set here. |
void |
setLogger(org.apache.log4j.Logger log)
Sets a logger for the engine. |
void |
start()
Starting this object as a thread. |
void |
suppressSTDERR(boolean suppress)
By default, the engine process' output to STDERR is redirected to the System.err and to the engine's logger. |
protected boolean |
takesTime()
Returns true if we use the Unix time command |
void |
takeTime(boolean taketime)
Whether to take runtime statistics of the engine process or not. |
int |
waitFor()
Causes the current thread to wait, if necessary, until the process has terminated. |
void |
waitTillRunning()
This does nothing but wait until an underlying bridge process is actually running, and it return then. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public boolean stdin
protected java.lang.String argumentString
protected org.apache.log4j.Logger LOG
protected static final java.lang.String TIME_PREFIX
time command
| Constructor Detail |
|---|
public HyEngine(java.lang.String engineName)
throws HySpiritException
engineName - the name of the engine (e.g., 'hy_pra')
HySpiritException - if we can't determine the environment
public HyEngine(java.lang.String engineName,
HySpiritProperties hyspirit)
throws HySpiritException
engineName - the name of the engine (e.g., 'hy_pra')hyspirit - the HySpirit properties containing the environment
HySpiritException - if we can't determine the environment
public HyEngine(java.lang.String engineName,
java.lang.String hostname,
int port)
throws HySpiritException
hostname - the hostname of the engine serverport - the port of the engine server
HySpiritException - if the connection failed| Method Detail |
|---|
public void setLogger(org.apache.log4j.Logger log)
log - the logger.public void setArgumentString(java.lang.String argumentString)
argumentString - the argument stringpublic void start()
public java.lang.String getCommand()
public java.lang.String getEngineName()
public java.lang.String getRealTime()
time command, this method gets the elapsed
real time in [hours:]minutes:seconds.
takeTime(boolean)public java.lang.String getUserTime()
time command, this method gets the elapsed
user mode CPU seconds
takeTime(boolean)public java.lang.String getSysTime()
time command, this method gets the elapsed
sys mode CPU seconds
takeTime(boolean)public java.lang.String getPercentageCPU()
time command, this method gets the elapsed
sys mode CPU seconds
takeTime(boolean)public void readFromSTDIN()
public java.io.BufferedWriter getSTDIN()
public java.io.BufferedReader getSTDOUT()
public java.io.BufferedReader getSTDERR()
System.err. Returns null.
public void closeSTDIN()
throws java.io.IOException
hyp_pra) need either
enough input or an EOF in STDIN before they release their buffered output.
So try this if you don't receive any output from the underlying engine.
java.io.IOException
public java.io.BufferedWriter getOutputWriter()
throws java.io.IOException
java.io.IOException
public java.io.BufferedReader getInputReader()
throws java.io.IOException
java.io.IOExceptionpublic void reset()
run().
public void run()
run in interface java.lang.Runnable
public void destroy()
throws java.lang.IllegalThreadStateException
java.lang.IllegalThreadStateException - if the process hasn't started yet.
public void restart()
throws java.lang.IllegalThreadStateException
java.lang.IllegalThreadStateException
public int waitFor()
throws java.lang.IllegalThreadStateException,
java.lang.InterruptedException
java.lang.InterruptedException - - if the current thread is interrupted by
another thread while it is waiting, then the wait is ended and
an InterruptedException is thrown.
java.lang.IllegalThreadStateException - if the process hasn't started yet.public boolean isRunning()
public boolean isInClientMode()
public void waitTillRunning()
public int exitValue()
throws java.lang.IllegalThreadStateException
java.lang.IllegalThreadStateException - - if the process has not yet
terminated or started.
public void send(java.lang.String input)
throws java.io.IOException
input - the string to be sent to the engine.
java.io.IOException
public void sendFile(java.lang.String filename)
throws java.io.IOException
filename - the content of this file will be sent to the engine
java.io.IOExceptionprotected java.lang.String getStreamEndMessage()
public java.lang.String echoSpecial(java.lang.String message)
message - the message to be echoed
public java.lang.String sendAndReceive(java.lang.String input)
input -
protected void send(java.io.BufferedReader input)
throws java.io.IOException
java.io.IOExceptionpublic boolean hasNext()
public java.lang.String next()
public void suppressSTDERR(boolean suppress)
suppress - true if the process output should not be sent to
System.err, false else.public void takeTime(boolean taketime)
true, the engine is started using the Unix time
command with the format defined in TIME_FORMAT. The output
is appended to STDOUT.
takeTime - whether to take file or not. Default: don't take time
false.protected boolean takesTime()
time command
time command, false elseprotected java.lang.String[] buildCommand()
buildCommand and
reset methods. Be sure that you place the support for new,
additional parameters somewhere. This means the block
if (this.argumentString != null) {
StringTokenizer strTok= new StringTokenizer(this.argumentString);
while (strTok.hasMoreTokens()) commandVec.add(strTok.nextToken());
}
should appear somewhere in your buildCommand
implementation.
The output of this method is used in the run() method.
public void kb(HyKB kb)
public void kb(java.lang.String kbName)
throws java.io.IOException
kbName - the name of the knowledge base
java.io.IOExceptionpublic HyKB kb()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||