public class SimulationStarter
extends java.lang.Object
implements java.lang.Cloneable
This project was carried out at:
and supported byGenOpt Copyright (c) 1998-2021, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
| Modifier and Type | Field and Description | 
|---|---|
protected java.lang.String | 
CommandLine  | 
protected java.util.concurrent.locks.ReentrantLock | 
lock  | 
private static java.lang.String | 
LS
System dependent line separator 
 | 
protected int | 
maxThrPoo
The maximum number of threads in the pool 
 | 
protected OptimizationIni | 
OptIni  | 
protected java.lang.Process[] | 
pro  | 
protected java.util.concurrent.atomic.AtomicBoolean[] | 
proFre
Array with boolean flag, flag is true if this process number can be used 
 | 
protected boolean | 
PrombtFileExtension  | 
protected java.lang.String | 
worDir  | 
| Constructor and Description | 
|---|
SimulationStarter(java.lang.String command,
                 boolean promptInputFileExtension,
                 java.lang.String workingDirectory,
                 OptimizationIni optIni)
constructor 
 | 
| Modifier and Type | Method and Description | 
|---|---|
private int | 
_getThreadNumber()
Returns the thread number to be used by this process 
 | 
(package private) void | 
_processProcessOutput(int iPro,
                     ThreadedInputStream errorStream,
                     java.io.File proWorDir,
                     java.lang.String comLin)
Processes the output of the simulation 
 | 
private java.lang.String | 
_updateAndGetCommandLine(java.lang.String worDirPre)
Updates the command line by replacing the output paths with the output path of the
  working directory, which can change from one simulation to another. 
 | 
private void | 
_updateCommandLine()
Updates the command line. 
 | 
void | 
destroyProcess()
Destroys all processes that exists 
 | 
void | 
destroyProcess(int iPro)
destroys the process if it exists 
 | 
java.lang.String | 
getCommandDiagnostics(java.lang.String worDirPre)
Gets a string representation of the command line and the working directory. 
 | 
static java.lang.String | 
replaceString(java.lang.String Original,
             java.lang.String Find,
             java.lang.String Set)
Replace all occurences of the String 'Find' with the String 'Set'
  in the String 'Original' even if 'Find' appears several times. 
 | 
void | 
run(java.lang.String worDirPre)
Runs the simulation program 
 | 
void | 
setMaximumNumberOfThreads(int maximumThreads)
Sets the maximum number of threads in the pool. 
 | 
void | 
setWorkingDirectory(java.lang.String workingDirectory)
Sets the working directory. 
 | 
private static final java.lang.String LS
protected java.lang.String CommandLine
protected boolean PrombtFileExtension
protected java.lang.String worDir
protected OptimizationIni OptIni
protected java.lang.Process[] pro
protected java.util.concurrent.atomic.AtomicBoolean[] proFre
protected int maxThrPoo
protected java.util.concurrent.locks.ReentrantLock lock
public SimulationStarter(java.lang.String command,
                         boolean promptInputFileExtension,
                         java.lang.String workingDirectory,
                         OptimizationIni optIni)
                  throws java.io.IOException
command - the command line (with placeholder for the variables)promptInputFileExtension - flag for specifying whether the extension
        of the inputfile must be written in the command or not.true if the extension has to be written,
        false otherwise.)workingDirectory - the working directory for the process.optIni - Instance of the OptimizationIni classjava.io.IOException - If an I/O error occurs, which is possible because the construction of the
                        canonical pathname may require filesystem queriespublic void setMaximumNumberOfThreads(int maximumThreads)
                               throws OptimizerException
maximumThreads - The maximum number of threads in the poolOptimizerException - If the maximum number of processes has already been allocatedprivate void _updateCommandLine()
private java.lang.String _updateAndGetCommandLine(java.lang.String worDirPre)
                                           throws java.io.IOException
worDirPre - Prefix for working directory. This will be added to all output and log paths.java.io.IOException - If an I/O error occurs, which is possible because the construction of the
                        canonical pathname may require filesystem queriespublic static java.lang.String replaceString(java.lang.String Original,
                                             java.lang.String Find,
                                             java.lang.String Set)
Original - String that has be scanned for 'Find'Find - String that has to be found and replacedSet - String that has to be set at the position of 'Find'private int _getThreadNumber()
                      throws OptimizerException
OptimizerException - If no thread is available. This condition should never occur.public java.lang.String getCommandDiagnostics(java.lang.String worDirPre)
                                       throws java.io.IOException
worDirPre - working directory prefix, to be added to current working directory to enable
                  parallel simulationsjava.io.IOExceptionpublic void run(java.lang.String worDirPre)
         throws java.io.IOException,
                OptimizerException,
                java.lang.Exception
worDirPre - working directory prefix, to be added to current working directory to enable
                  parallel simulationsjava.io.IOExceptionOptimizerExceptionjava.lang.Exceptionvoid _processProcessOutput(int iPro,
                           ThreadedInputStream errorStream,
                           java.io.File proWorDir,
                           java.lang.String comLin)
                    throws java.lang.NullPointerException,
                           OptimizerException,
                           java.io.IOException
iPro - the process numberproWorDir - the process working directory (used for error reporting)comLin - the command line (used for error reporting)java.lang.NullPointerException - If the user requested GenOpt to stopOptimizerExceptionjava.io.IOException - if the output or error stream cannot be readpublic void destroyProcess()
public void destroyProcess(int iPro)
iPro - number of the processpublic void setWorkingDirectory(java.lang.String workingDirectory)
workingDirectory - the working directory.