You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2018/04/25 03:31:53 UTC
[openmeetings] branch master updated: [OPENMEETINGS-1878]
StreamWatcher is added back
This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git
The following commit(s) were added to refs/heads/master by this push:
new bc5c079 [OPENMEETINGS-1878] StreamWatcher is added back
bc5c079 is described below
commit bc5c0798f712b6290f8cb467c3adf7f55e8c04a2
Author: Maxim Solodovnik <so...@gmail.com>
AuthorDate: Wed Apr 25 10:28:05 2018 +0700
[OPENMEETINGS-1878] StreamWatcher is added back
---
.../openmeetings/util/process/ProcessHelper.java | 54 ++++++++++++++++++++--
1 file changed, 49 insertions(+), 5 deletions(-)
diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/process/ProcessHelper.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/process/ProcessHelper.java
index b9f3835..864bdc6 100644
--- a/openmeetings-util/src/main/java/org/apache/openmeetings/util/process/ProcessHelper.java
+++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/process/ProcessHelper.java
@@ -21,17 +21,54 @@ package org.apache.openmeetings.util.process;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.openmeetings.util.OpenmeetingsVariables.getExtProcessTtl;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
-import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProcessHelper {
public static final Logger log = LoggerFactory.getLogger(ProcessHelper.class);
+ // This is necessary to prevent 'buffer overflow'
+ // https://stackoverflow.com/questions/9885643/ffmpeg-executed-from-javas-processbuilder-does-not-return-under-windows-7
+ private static class StreamWatcher extends Thread {
+ public final StringBuilder output = new StringBuilder();
+ private final InputStream is;
+ private boolean run = true;
+
+ private StreamWatcher(final InputStream is) {
+ this.is = is;
+ }
+
+ @Override
+ public void run() {
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(is, UTF_8));) {
+ String line = br.readLine();
+ while (run && line != null) {
+ output.append(line).append('\n');
+ line = br.readLine();
+ }
+ } catch (IOException ioexception) {
+ return;
+ }
+ }
+
+ public void finish() {
+ run = false;
+ }
+
+ @Override
+ public String toString() {
+ return output.toString();
+ }
+ }
+
private ProcessHelper() {}
private static String getCommand(String[] argv) {
@@ -71,9 +108,10 @@ public class ProcessHelper {
debugCommandStart(process, argv);
Process proc = null;
+ StreamWatcher errorWatcher = null;
+ StreamWatcher inputWatcher = null;
try {
- res.setCommand(getCommand(argv))
- .setOut("");
+ res.setCommand(getCommand(argv)).setOut("");
// By using the process Builder we have access to modify the
// environment variables
@@ -82,6 +120,10 @@ public class ProcessHelper {
pb.environment().putAll(env);
proc = pb.start();
+ errorWatcher = new StreamWatcher(proc.getErrorStream());
+ inputWatcher = new StreamWatcher(proc.getInputStream());
+ errorWatcher.start();
+ inputWatcher.start();
// 20-minute timeout for command execution
// FFMPEG conversion of Recordings may take a real long time until
@@ -89,8 +131,8 @@ public class ProcessHelper {
proc.waitFor(getExtProcessTtl(), TimeUnit.MINUTES);
res.setExitCode(proc.exitValue())
- .setOut(IOUtils.toString(proc.getInputStream(), UTF_8))
- .setError(IOUtils.toString(proc.getErrorStream(), UTF_8));
+ .setOut(inputWatcher.toString())
+ .setError(errorWatcher.toString());
} catch (Throwable t) {
log.error("executeScript", t);
res.setExitCode(-1)
@@ -98,6 +140,8 @@ public class ProcessHelper {
.setException(t.toString());
} finally {
if (proc != null) {
+ errorWatcher.finish();
+ inputWatcher.finish();
proc.destroy();
}
}
--
To stop receiving notification emails like this one, please contact
solomax@apache.org.