This repository has been archived by the owner on Mar 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from njam/issue-5
Kill thumbnailer on mediaStream close
- Loading branch information
Showing
6 changed files
with
143 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package ch.cargomedia.wms.process; | ||
|
||
import com.wowza.wms.logging.WMSLoggerFactory; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class InterruptibleProcess extends Thread { | ||
|
||
private String[] _command; | ||
private BufferedReader _processReader = null; | ||
private Boolean _interrupted = false; | ||
|
||
private String _output = null; | ||
private Integer _exitCode = null; | ||
private Exception _exception = null; | ||
|
||
public InterruptibleProcess(String[] command) { | ||
_command = command; | ||
} | ||
|
||
public void run() { | ||
try { | ||
ProcessBuilder builder = new ProcessBuilder(_command); | ||
builder.redirectErrorStream(true); | ||
Process _process = builder.start(); | ||
|
||
_processReader = new BufferedReader(new InputStreamReader(_process.getInputStream())); | ||
String line; | ||
_output = ""; | ||
while ((line = _processReader.readLine()) != null) { | ||
_output += line + "\n"; | ||
} | ||
|
||
if (_interrupted) { | ||
throw new InterruptedException(); | ||
} | ||
|
||
_exitCode = _process.waitFor(); | ||
if (0 != _exitCode) { | ||
throw new Exception(String.format("Command exited with code `%s`. \nCommand: %s \nOutput: \n%s", | ||
_process.exitValue(), StringUtils.join(_command, " "), _output)); | ||
} | ||
} catch (Exception e) { | ||
_exception = e; | ||
} | ||
} | ||
|
||
@Override | ||
public void interrupt() { | ||
_interrupted = true; | ||
this._closeProcessReader(); | ||
super.interrupt(); | ||
} | ||
|
||
public String getOutput() { | ||
return _output; | ||
} | ||
|
||
public Integer getExitCode() { | ||
return _exitCode; | ||
} | ||
|
||
public Exception getException() { | ||
return _exception; | ||
} | ||
|
||
public void throwExceptionIfAny() throws Exception { | ||
if (null != _exception) { | ||
throw _exception; | ||
} | ||
} | ||
|
||
private void _closeProcessReader() { | ||
if (null != _processReader) { | ||
try { | ||
_processReader.close(); | ||
_processReader = null; | ||
} catch (IOException e) { | ||
WMSLoggerFactory.getLogger(null).error("Cannot close process reader: " + e.getMessage()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ch.cargomedia.wms.process; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class ProcessSequence { | ||
|
||
private ArrayList<String[]> _commandList = new ArrayList<String[]>(); | ||
private InterruptibleProcess _processWorker = null; | ||
private Boolean _interrupted = false; | ||
|
||
public void addCommand(String[] command) { | ||
_commandList.add(command); | ||
} | ||
|
||
public void runAll() throws Exception { | ||
for (String[] command : _commandList) { | ||
if (_interrupted) { | ||
throw new InterruptedException(); | ||
} | ||
_processWorker = new InterruptibleProcess(command); | ||
_processWorker.run(); | ||
_processWorker.join(0); | ||
_processWorker.throwExceptionIfAny(); | ||
_processWorker = null; | ||
} | ||
_commandList.clear(); | ||
} | ||
|
||
public void interrupt() { | ||
_interrupted = true; | ||
if (null != _processWorker) { | ||
_processWorker.interrupt(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters