Skip to content

Commit

Permalink
Fixed threading locations
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeByDrescher committed Jan 30, 2025
1 parent 69d66f2 commit 60079af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class TimeLimitedCommand implements Callable<Integer> {
* Perform the desired command
* @return return code of the command
*/
protected abstract Integer executeCommand();
protected abstract Integer executeCommand() throws Exception;

protected long getTimeout() {return this.timeout;}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,10 @@ public class ExecuteOmexCommand extends ExecutionBasedCommand {
@Override
public Integer call() throws Exception {
if (!this.executionShouldContinue()) return 0;
CLIRecordable cliTracer = new CliTracer();
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Integer> futureResult = executor.submit(this::executeCommand);
long startTime_ms = System.currentTimeMillis();

try {
File tmpDirExec = Files.createTempDirectory("VCell_CLI_" + Long.toHexString(new Date().getTime())).toFile();
File tmpDirConv = Files.createTempDirectory("VCell_CLI_" + Long.toHexString(new Date().getTime())).toFile();
Tracer.clearTraceEvents();

startTime_ms = System.currentTimeMillis();
boolean needsNoConversion = !this.inputFilePath.getName().endsWith(".vcml");
File inFile = needsNoConversion ? this.inputFilePath : ExecuteOmexCommand.performInputFileConversion(this.inputFilePath, tmpDirConv);

if (inFile != null)
ExecuteImpl.singleMode(inFile, tmpDirExec, cliTracer,
this.bKeepTempFiles, this.bExactMatchOnly, this.bEncapsulateOutput, this.bSmallMeshOverride);


FileUtils.copyDirectoryContents(tmpDirExec, this.outputFilePath, true, null);
Integer ignored;
try { // This try is explicitly for timeouts
if (this.getTimeout() == 0) {
futureResult.get();
Expand All @@ -94,6 +77,7 @@ public Integer call() throws Exception {
} catch (TimeoutException e) {
// In the event of timeout, we want to log like we're talking from the command in question
// We'll leave an in-log reference to the actual class and method
futureResult.cancel(true);
String debugSnipIt = logger.getLevel().isInRange(Level.TRACE, Level.DEBUG) ? "(TimeLimitedCommand::call) " : "";
String msg = String.format("%sTask too too long, exceeding %s %s.", debugSnipIt, this.getTimeout(), this.getTimeUnit().toString().toLowerCase());
LogManager.getLogger(this.getClass()).error(msg);
Expand Down Expand Up @@ -171,8 +155,23 @@ protected boolean executionShouldContinue() {
* @return return code of the command
*/
@Override
protected Integer executeCommand() {
return 0;
protected Integer executeCommand() throws Exception {
File tmpDirExec = Files.createTempDirectory("VCell_CLI_" + Long.toHexString(new Date().getTime())).toFile();
File tmpDirConv = Files.createTempDirectory("VCell_CLI_" + Long.toHexString(new Date().getTime())).toFile();
Tracer.clearTraceEvents();

boolean needsNoConversion = !this.inputFilePath.getName().endsWith(".vcml");
File inFile = needsNoConversion ? this.inputFilePath : ExecuteOmexCommand.performInputFileConversion(this.inputFilePath, tmpDirConv);

CLIRecordable cliTracer = new CliTracer();
if (inFile != null)
ExecuteImpl.singleMode(inFile, tmpDirExec, cliTracer,
this.bKeepTempFiles, this.bExactMatchOnly, this.bEncapsulateOutput, this.bSmallMeshOverride);


FileUtils.copyDirectoryContents(tmpDirExec, this.outputFilePath, true, null);
return 0;

}

private static File performInputFileConversion(File inputFile, File outputDir) {
Expand Down
11 changes: 6 additions & 5 deletions vcell-cli/src/main/java/org/vcell/cli/run/ExecuteImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cbit.vcell.solver.ode.ODESolverResultSet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jlibsedml.XMLException;
import org.vcell.cli.messaging.CLIRecordable;
import org.vcell.cli.exceptions.ExecutionException;
import org.vcell.cli.run.hdf5.BiosimulationsHdfWriterException;
Expand Down Expand Up @@ -118,14 +119,14 @@ private static void runSingleExecOmex(File inputFile, File outputDir, CLIRecorda

public static void singleMode(File inputFile, File rootOutputDir, CLIRecordable cliLogger,
boolean bKeepTempFiles, boolean bExactMatchOnly, boolean bEncapsulateOutput,
boolean bSmallMeshOverride) throws Exception{
boolean bSmallMeshOverride) throws IOException, BiosimulationsHdfWriterException, ExecutionException, XMLException {
ExecuteImpl.singleMode(inputFile, rootOutputDir, cliLogger, bKeepTempFiles, bExactMatchOnly,
bEncapsulateOutput, bSmallMeshOverride, false);
}

public static void singleMode(File inputFile, File rootOutputDir, CLIRecordable cliLogger,
boolean bKeepTempFiles, boolean bExactMatchOnly, boolean bEncapsulateOutput,
boolean bSmallMeshOverride, boolean bBioSimMode) throws Exception {
boolean bSmallMeshOverride, boolean bBioSimMode) throws IOException, BiosimulationsHdfWriterException, ExecutionException, XMLException {
// Build statuses
String bioModelBaseName = FileUtils.getBaseName(inputFile.getName()); // bioModelBaseName = input file without the path
String outputBaseDir = rootOutputDir.getAbsolutePath();
Expand Down Expand Up @@ -209,13 +210,13 @@ public static void singleExecVcml(File vcmlFile, File outputDir, CLIRecordable c
somethingFailed = somethingDidFail();
} catch (ExpressionException e) {
Tracer.failure(e, "ExpressionException while processing VCML " + vcmlFile.getName());
logger.error("InterruptedException while creating results CSV from VCML " + vcmlFile.getName(), e);
logger.error("ExpressionException while creating results CSV from VCML " + vcmlFile.getName(), e);
somethingFailed = somethingDidFail();
} catch (InterruptedException e) {
} /*catch (InterruptedException e) {
Tracer.failure(e, "InterruptedException while processing VCML " + vcmlFile.getName());
logger.error("InterruptedException while transposing CSV from VCML " + vcmlFile.getName(), e);
somethingFailed = somethingDidFail();
} catch (Exception e) {
}*/ catch (Exception e) {
Tracer.failure(e, "Unexpected exception while processing VCML " + vcmlFile.getName());
String errorMessage = String.format("Unexpected exception while transposing CSV from VCML <%s>\n%s", vcmlFile.getName(), e.toString());
logger.error(errorMessage, e);
Expand Down

0 comments on commit 60079af

Please sign in to comment.