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.Thread
Communicate 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>
cmdArr
Array containing the command to call and its arguments.protected static int
dY
Default height of window.protected java.lang.String
errMes
Error message ifproSta=true
or null pointer otherwise.static int
locY
Y location of window that displays the console output.protected java.io.File
logFil
Log file to which simulation output will be written.protected boolean
logToSysOut
Flag, iftrue
, then the output will be written to System.out.protected java.lang.String
modNam
Name of the model.protected lbnl.util.ClientProcess.PrintStderr
priStdErr
The thread that captures the standard error stream.protected lbnl.util.ClientProcess.PrintOutput
priStdOut
The thread that captures the standard output stream.protected boolean
proSta
Flag that is set totrue
if the process started without throwing an exception.protected boolean
redErrStr
Flag, if true, redirects the standard error stream to the standard output stream.protected boolean
showConsoleWindow
Flag, if true, then the console output will be displayed in a JFrame.protected java.lang.Process
simPro
Process for the simulation.protected javax.swing.JTextArea
stdAre
Text area that contains the console output of the simulation.protected java.lang.StringBuilder
stdErr
String that contains the standard error stream.protected javax.swing.JFrame
stdFra
Frame that contains the console output of the simulation.protected java.lang.StringBuilder
stdOut
String that contains the standard output stream.protected javax.swing.JScrollPane
stdScrPan
Scroll pane that contains the text area for the console output.protected java.io.File
worDir
Working 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 void
disposeWindow()
Disposes the window that displays the console output.int
exitValue()
Get the exit value of the process.java.lang.String
getErrorMessage()
Return the error message ifproSta=true
or a null pointer otherwise.java.lang.String
getStandardError()
Get the standard error of the process.java.lang.String
getStandardOutput()
Get the standard output of the process.static void
main(java.lang.String[] args)
Main method for testing.boolean
processStarted()
Return true if the process started without throwing an exception.void
redirectErrorStream(boolean flag)
Redirects the standard error stream to the standard output stream.static void
resetWindowLocation()
Reset the position of the window that shows the console output.void
run()
Runs the process.void
setProcessArguments(java.util.List<java.lang.String> cmdarray, java.lang.String dir)
Set the process arguments.void
setSimulationLogFile(java.io.File simLogFil)
Sets the simulation log file.void
showConsoleWindow(boolean showWindow)
Set a flag that determines whether the console window will be displayed.int
waitFor()
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 totrue
if the process started without throwing an exception.
-
errMes
protected java.lang.String errMes
Error message ifproSta=true
or 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:
run
in interfacejava.lang.Runnable
- Overrides:
run
in 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=true
or a null pointer otherwise.- Returns:
- the error message if
proSta=true
or a null pointer otherwise.
-
waitFor
public int waitFor() throws java.lang.InterruptedException
Causes 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 IllegalActionException
Set 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 IllegalActionException
Main 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.
-
-