ItEr52S04ValidacionEProbasFuncionaisItEr51S04: Implemented timeout thread to terminate unfinished CutyCapt processes
This commit is contained in:
parent
fb3bd8bacf
commit
15eab39131
2 changed files with 64 additions and 13 deletions
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.web.print;
|
||||
|
||||
import static org.zkoss.ganttz.i18n.I18nHelper._;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
||||
public class CutyCaptTimeout extends Thread {
|
||||
|
||||
long timeout;
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(CutyPrint.class);
|
||||
|
||||
CutyCaptTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
sleep(timeout);
|
||||
Runtime.getRuntime().exec("killall CutyCapt");
|
||||
} catch (Exception e) {
|
||||
LOG.error(_("CutycaptTimeout thread exception"), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -53,6 +53,8 @@ public class CutyPrint {
|
|||
private static final Log LOG = LogFactory.getLog(CutyPrint.class);
|
||||
|
||||
private static final String CUTYCAPT_COMMAND = "/usr/bin/CutyCapt ";
|
||||
// Estimated maximum execution time (ms)
|
||||
private static final int CUTYCAPT_TIMEOUT = 20000;
|
||||
|
||||
// Taskdetails left padding
|
||||
private static int TASKDETAILS_WIDTH = 310;
|
||||
|
|
@ -183,34 +185,36 @@ public class CutyPrint {
|
|||
// Destination complete absolute path
|
||||
captureString += " --out=" + absolutePath + filename;
|
||||
|
||||
|
||||
try {
|
||||
// CutyCapt command execution
|
||||
LOG.warn(captureString);
|
||||
|
||||
Process print;
|
||||
Process server = null;
|
||||
|
||||
// Ensure cleanup of unfinished CutyCapt processes and CSS
|
||||
Runtime.getRuntime().exec("killall CutyCapt");
|
||||
Process printProcess;
|
||||
Process serverProcess = null;
|
||||
|
||||
// If there is a not real X server environment then use Xvfb
|
||||
if ((System.getenv("DISPLAY") == null)
|
||||
|| (System.getenv("DISPLAY").equals(""))) {
|
||||
String[] serverEnvironment = { "PATH=$PATH" };
|
||||
server = Runtime.getRuntime().exec("env - Xvfb :99",
|
||||
serverProcess = Runtime.getRuntime().exec("env - Xvfb :99",
|
||||
serverEnvironment);
|
||||
String[] environment = { "DISPLAY=:99.0" };
|
||||
print = Runtime.getRuntime().exec(captureString, environment);
|
||||
printProcess = Runtime.getRuntime().exec(captureString,
|
||||
environment);
|
||||
} else {
|
||||
print = Runtime.getRuntime().exec(captureString);
|
||||
printProcess = Runtime.getRuntime().exec(captureString);
|
||||
}
|
||||
try {
|
||||
print.waitFor();
|
||||
print.destroy();
|
||||
// Ensure CutyCapt process finalization
|
||||
CutyCaptTimeout timeoutThread = new CutyCaptTimeout( CUTYCAPT_TIMEOUT );
|
||||
new Thread(timeoutThread).start();
|
||||
|
||||
printProcess.waitFor();
|
||||
printProcess.destroy();
|
||||
|
||||
if ((System.getenv("DISPLAY") == null)
|
||||
|| (System.getenv("DISPLAY").equals(""))) {
|
||||
server.destroy();
|
||||
serverProcess.destroy();
|
||||
}
|
||||
Executions.getCurrent().sendRedirect(filename, "_blank");
|
||||
} catch (Exception e) {
|
||||
|
|
@ -278,4 +282,4 @@ public class CutyPrint {
|
|||
} else
|
||||
return srFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue