Package lbnl.util
Class ClientProcess
- java.lang.Object
 - 
- java.lang.Thread
 - 
- lbnl.util.ClientProcess
 
 
 
- 
- All Implemented Interfaces:
 java.lang.Runnable
public class ClientProcess extends java.lang.ThreadCommunicate with a client process.- Since:
 - Ptolemy II 8.0
 - Version:
 - $Id$
 - Author:
 - Michael Wetter
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected java.util.List<java.lang.String>cmdArrArray containing the command to call and its arguments.protected static intdYDefault height of window.protected java.lang.StringerrMesError message ifproSta=trueor null pointer otherwise.static intlocYY location of window that displays the console output.protected java.io.FilelogFilLog file to which simulation output will be written.protected booleanlogToSysOutFlag, iftrue, then the output will be written to System.out.protected java.lang.StringmodNamName of the model.protected lbnl.util.ClientProcess.PrintStderrpriStdErrThe thread that captures the standard error stream.protected lbnl.util.ClientProcess.PrintOutputpriStdOutThe thread that captures the standard output stream.protected booleanproStaFlag that is set totrueif the process started without throwing an exception.protected booleanredErrStrFlag, if true, redirects the standard error stream to the standard output stream.protected booleanshowConsoleWindowFlag, if true, then the console output will be displayed in a JFrame.protected java.lang.ProcesssimProProcess for the simulation.protected javax.swing.JTextAreastdAreText area that contains the console output of the simulation.protected java.lang.StringBuilderstdErrString that contains the standard error stream.protected javax.swing.JFramestdFraFrame that contains the console output of the simulation.protected java.lang.StringBuilderstdOutString that contains the standard output stream.protected javax.swing.JScrollPanestdScrPanScroll pane that contains the text area for the console output.protected java.io.FileworDirWorking directory of the subprocess, or null if the subprocess should inherit the working directory of the current process. 
- 
Constructor Summary
Constructors Constructor Description ClientProcess(java.lang.String modelName)Create a ClientProcess. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisposeWindow()Disposes the window that displays the console output.intexitValue()Get the exit value of the process.java.lang.StringgetErrorMessage()Return the error message ifproSta=trueor a null pointer otherwise.java.lang.StringgetStandardError()Get the standard error of the process.java.lang.StringgetStandardOutput()Get the standard output of the process.static voidmain(java.lang.String[] args)Main method for testing.booleanprocessStarted()Return true if the process started without throwing an exception.voidredirectErrorStream(boolean flag)Redirects the standard error stream to the standard output stream.static voidresetWindowLocation()Reset the position of the window that shows the console output.voidrun()Runs the process.voidsetProcessArguments(java.util.List<java.lang.String> cmdarray, java.lang.String dir)Set the process arguments.voidsetSimulationLogFile(java.io.File simLogFil)Sets the simulation log file.voidshowConsoleWindow(boolean showWindow)Set a flag that determines whether the console window will be displayed.intwaitFor()Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.- 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield 
 - 
 
 - 
 
- 
- 
Field Detail
- 
stdFra
protected javax.swing.JFrame stdFra
Frame that contains the console output of the simulation. 
- 
stdAre
protected javax.swing.JTextArea stdAre
Text area that contains the console output of the simulation. 
- 
stdScrPan
protected javax.swing.JScrollPane stdScrPan
Scroll pane that contains the text area for the console output. 
- 
locY
public static int locY
Y location of window that displays the console output. This data member is static so that windows can be placed above each other if multiple simulations are used 
- 
dY
protected static final int dY
Default height of window.- See Also:
 - Constant Field Values
 
 
- 
cmdArr
protected java.util.List<java.lang.String> cmdArr
Array containing the command to call and its arguments. 
- 
worDir
protected java.io.File worDir
Working directory of the subprocess, or null if the subprocess should inherit the working directory of the current process. 
- 
logFil
protected java.io.File logFil
Log file to which simulation output will be written. 
- 
logToSysOut
protected boolean logToSysOut
Flag, iftrue, then the output will be written to System.out. 
- 
simPro
protected java.lang.Process simPro
Process for the simulation. 
- 
modNam
protected java.lang.String modNam
Name of the model. 
- 
showConsoleWindow
protected boolean showConsoleWindow
Flag, if true, then the console output will be displayed in a JFrame. 
- 
proSta
protected boolean proSta
Flag that is set totrueif the process started without throwing an exception. 
- 
errMes
protected java.lang.String errMes
Error message ifproSta=trueor null pointer otherwise. 
- 
stdOut
protected java.lang.StringBuilder stdOut
String that contains the standard output stream. 
- 
stdErr
protected java.lang.StringBuilder stdErr
String that contains the standard error stream. 
- 
priStdOut
protected lbnl.util.ClientProcess.PrintOutput priStdOut
The thread that captures the standard output stream. 
- 
priStdErr
protected lbnl.util.ClientProcess.PrintStderr priStdErr
The thread that captures the standard error stream. 
- 
redErrStr
protected boolean redErrStr
Flag, if true, redirects the standard error stream to the standard output stream. 
 - 
 
- 
Method Detail
- 
showConsoleWindow
public void showConsoleWindow(boolean showWindow)
Set a flag that determines whether the console window will be displayed.- Parameters:
 showWindow- Set to false to avoid the console window to be shown
 
- 
disposeWindow
public void disposeWindow()
Disposes the window that displays the console output. 
- 
redirectErrorStream
public void redirectErrorStream(boolean flag)
Redirects the standard error stream to the standard output stream.- Parameters:
 flag- if true, redirects the standard error stream to the standard output stream
 
- 
setSimulationLogFile
public void setSimulationLogFile(java.io.File simLogFil)
Sets the simulation log file.- Parameters:
 simLogFil- The log file.
 
- 
run
public void run()
Runs the process.- Specified by:
 runin interfacejava.lang.Runnable- Overrides:
 runin classjava.lang.Thread
 
- 
processStarted
public boolean processStarted()
Return true if the process started without throwing an exception.- Returns:
 - true if the process started without throwing an exception.
 
 
- 
getErrorMessage
public java.lang.String getErrorMessage()
Return the error message ifproSta=trueor a null pointer otherwise.- Returns:
 - the error message if 
proSta=trueor a null pointer otherwise. 
 
- 
waitFor
public int waitFor() throws java.lang.InterruptedExceptionCauses the current thread to wait, if necessary, until the process represented by this Process object has terminated. This method returns immediately if the subprocess has already terminated. If the subprocess has not yet terminated, the calling thread will be blocked until the subprocess exits.- Returns:
 - the exit value of the process. By convention, 0 indicates normal termination.
 - Throws:
 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.
 
- 
getStandardOutput
public java.lang.String getStandardOutput()
Get the standard output of the process.- Returns:
 - the standard output of the process
 
 
- 
getStandardError
public java.lang.String getStandardError()
Get the standard error of the process.- Returns:
 - the standard error of the process
 
 
- 
exitValue
public int exitValue()
Get the exit value of the process.- Returns:
 - the exit value of the process
 
 
- 
resetWindowLocation
public static void resetWindowLocation()
Reset the position of the window that shows the console output. This function is typically called by actors in the wrapUp() method so that for the next simulation, the window will be placed at the same position again as in the previous simulation 
- 
setProcessArguments
public void setProcessArguments(java.util.List<java.lang.String> cmdarray, java.lang.String dir) throws IllegalActionExceptionSet the process arguments.- Parameters:
 cmdarray- array containing the command to call and its arguments.dir- the working directory of the subprocess.- Throws:
 IllegalActionException- if the canonical path name of the program file cannot be obtained.
 
- 
main
public static void main(java.lang.String[] args) throws IllegalActionExceptionMain method for testing.- Parameters:
 args- Commands to pass to the client process.- Throws:
 IllegalActionException- if the canonical path name of the program file cannot be obtained.
 
 - 
 
 -