Skip to content

Commit

Permalink
chore(pipeline): improve pipeline exception encapsulation
Browse files Browse the repository at this point in the history
  • Loading branch information
NPavie committed Apr 22, 2024
1 parent ea6afe2 commit 9b6329a
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions Common/DaisyConverterLib/Pipeline/Pipeline2/Pipeline2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,33 +135,41 @@ private Pipeline2()
options.Add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005");
}
#endif
try {
// Load a new JVM
jni = new JavaNativeInterface(options, jvmDllPath, false);

// Initialize runner in the JVM
SimpleAPIClass = jni.GetJavaClass("SimpleAPI");
CommandLineJobClass = jni.GetJavaClass("SimpleAPI$CommandLineJob");
JobStatusClass = jni.GetJavaClass("org/daisy/pipeline/job/Job$Status");
} catch ( Exception ex ) {
throw new Exception("An error occured while launching DAISY Pipeline 2", ex);
}

// Load a new JVM
jni = new JavaNativeInterface(options, jvmDllPath, false);
try {
string systemOut = Path.Combine(LogsFolder, "sysOut.log");
string systemErr = Path.Combine(LogsFolder, "sysErr.log");

// Initialize runner in the JVM
SimpleAPIClass = jni.GetJavaClass("SimpleAPI");
CommandLineJobClass = jni.GetJavaClass("SimpleAPI$CommandLineJob");
JobStatusClass = jni.GetJavaClass("org/daisy/pipeline/job/Job$Status");
IntPtr JavaSystem = jni.GetJavaClass("java/lang/System");
jni.CallVoidMethod(
JavaSystem,
IntPtr.Zero,
"setOut",
"(Ljava/io/PrintStream;)V",
makePrintStream(systemOut)
);
jni.CallVoidMethod(
JavaSystem,
IntPtr.Zero,
"setErr",
"(Ljava/io/PrintStream;)V",
makePrintStream(systemErr)
);
} catch (Exception ex ) {
throw new Exception("An error occured while creating log dp2 log files", ex);
}

string systemOut = Path.Combine(LogsFolder, "sysOut.log");
string systemErr = Path.Combine(LogsFolder, "sysErr.log");

IntPtr JavaSystem = jni.GetJavaClass("java/lang/System");
jni.CallVoidMethod(
JavaSystem,
IntPtr.Zero,
"setOut",
"(Ljava/io/PrintStream;)V",
makePrintStream(systemOut)
);
jni.CallVoidMethod(
JavaSystem,
IntPtr.Zero,
"setErr",
"(Ljava/io/PrintStream;)V",
makePrintStream(systemErr)
);
}

private IntPtr makePrintStream(string filepath)
Expand Down

0 comments on commit 9b6329a

Please sign in to comment.