2015-04-27 20:10:36 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2015 Laurent CLOUET
|
|
|
|
|
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; version 2
|
|
|
|
|
* of the License.
|
|
|
|
|
*
|
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.sheepit.client;
|
|
|
|
|
|
2019-08-07 22:17:59 +02:00
|
|
|
import lombok.Data;
|
|
|
|
|
|
2015-04-27 20:10:36 +01:00
|
|
|
import java.util.Date;
|
|
|
|
|
|
2019-08-07 22:17:59 +02:00
|
|
|
@Data
|
2015-04-27 20:10:36 +01:00
|
|
|
public class RenderProcess {
|
2019-08-07 22:17:59 +02:00
|
|
|
private long startTime;
|
|
|
|
|
private long endTime;
|
|
|
|
|
private int remainingDuration; // in seconds
|
2015-04-27 20:10:36 +01:00
|
|
|
private long memoryUsed; // in kB
|
2015-05-26 20:20:54 +01:00
|
|
|
private int coresUsed;
|
2015-04-27 20:10:36 +01:00
|
|
|
private Process process;
|
|
|
|
|
|
|
|
|
|
public RenderProcess() {
|
|
|
|
|
process = null;
|
2019-08-07 22:17:59 +02:00
|
|
|
startTime = -1;
|
|
|
|
|
endTime = -1;
|
2015-04-27 20:10:36 +01:00
|
|
|
memoryUsed = 0;
|
2015-05-26 20:20:54 +01:00
|
|
|
coresUsed = 0;
|
2015-04-27 20:35:44 +01:00
|
|
|
remainingDuration = 0;
|
2015-04-27 20:10:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @return duration in seconds
|
|
|
|
|
*/
|
|
|
|
|
public int getDuration() {
|
2019-08-07 22:17:59 +02:00
|
|
|
if (startTime != -1 && endTime != -1) {
|
|
|
|
|
return (int) ((endTime - startTime) / 1000);
|
2015-04-27 20:10:36 +01:00
|
|
|
}
|
2019-08-07 22:17:59 +02:00
|
|
|
else if (startTime != -1) {
|
|
|
|
|
return (int) ((new Date().getTime() - startTime) / 1000);
|
2015-04-27 20:10:36 +01:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void finish() {
|
2019-08-07 22:17:59 +02:00
|
|
|
endTime = new Date().getTime();
|
2015-04-27 20:10:36 +01:00
|
|
|
process = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void start() {
|
2019-08-07 22:17:59 +02:00
|
|
|
startTime = new Date().getTime();
|
2015-04-27 20:10:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int exitValue() {
|
|
|
|
|
int value = 0;
|
|
|
|
|
if (process == null) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
value = process.exitValue();
|
|
|
|
|
}
|
|
|
|
|
catch (IllegalThreadStateException e) {
|
|
|
|
|
// the process is not finished yet
|
|
|
|
|
value = 0;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
// actually is for java.io.IOException: GetExitCodeProcess error=6, The handle is invalid
|
|
|
|
|
// it was not declared throwable
|
|
|
|
|
|
|
|
|
|
// the process is not finished yet
|
|
|
|
|
value = 0;
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|