Cleaner version of removing project's directory

This commit is contained in:
Laurent Clouet
2019-08-07 18:40:02 +02:00
parent de4dfcd047
commit 3e9d701d7c
3 changed files with 38 additions and 14 deletions

View File

@@ -27,6 +27,8 @@ import java.io.StringWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Observable;
import java.util.Observer;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@@ -565,7 +567,7 @@ public class Client {
} }
} }
public Error.Type work(Job ajob) { public Error.Type work(final Job ajob) {
int ret; int ret;
gui.setRenderingProjectName(ajob.getName()); gui.setRenderingProjectName(ajob.getName());
@@ -614,7 +616,14 @@ public class Client {
return Error.Type.MISSING_RENDERER; return Error.Type.MISSING_RENDERER;
} }
Error.Type err = ajob.render(); Observer removeSceneDirectoryOnceRenderHasStartedObserver = new Observer() {
@Override public void update(Observable observable, Object o) {
System.out.println("Client::work got an event");
removeSceneDirectory(ajob);
}
};
Error.Type err = ajob.render(removeSceneDirectoryOnceRenderHasStartedObserver);
gui.setRenderingProjectName(""); gui.setRenderingProjectName("");
gui.setRemainingTime(""); gui.setRemainingTime("");
gui.setRenderingTime(""); gui.setRenderingTime("");

View File

@@ -35,6 +35,8 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
@@ -70,14 +72,10 @@ public class Job {
private boolean serverBlockJob; private boolean serverBlockJob;
private Gui gui; private Gui gui;
private Configuration config; private Configuration config;
private Client client;
private Log log; private Log log;
private boolean directoryRemoved; public Job(Configuration config_, Gui gui_, Log log_, String id_, String frame_, String path_, boolean use_gpu, String command_, String script_, String sceneMd5_, String rendererMd5_, String name_, String password_, String extras_, boolean synchronous_upload_, String update_method_) {
public Job(Configuration config_, Client client_, Gui gui_, Log log_, String id_, String frame_, String path_, boolean use_gpu, String command_, String script_, String sceneMd5_, String rendererMd5_, String name_, String password_, String extras_, boolean synchronous_upload_, String update_method_) {
config = config_; config = config_;
client = client_;
id = id_; id = id_;
numFrame = frame_; numFrame = frame_;
path = path_; path = path_;
@@ -98,7 +96,6 @@ public class Job {
serverBlockJob = false; serverBlockJob = false;
log = log_; log = log_;
render = new RenderProcess(); render = new RenderProcess();
directoryRemoved = false;
} }
public void block() { public void block() {
@@ -230,7 +227,7 @@ public class Job {
return synchronousUpload; return synchronousUpload;
} }
public Error.Type render() { public Error.Type render(Observer renderStarted) {
gui.status("Rendering"); gui.status("Rendering");
RenderProcess process = getProcessRender(); RenderProcess process = getProcessRender();
Timer timerOfMaxRenderTime = null; Timer timerOfMaxRenderTime = null;
@@ -326,6 +323,7 @@ public class Job {
} }
try { try {
renderStartedObservable event = new renderStartedObservable(renderStarted);
String line; String line;
log.debug(command.toString()); log.debug(command.toString());
OS os = OS.getOS(); OS os = OS.getOS();
@@ -377,9 +375,8 @@ public class Job {
return error; return error;
} }
if (directoryRemoved == false && (process.getMemoryUsed() > 0 || process.getRemainingDuration() > 0)) { if (event.isStarted() == false && (process.getMemoryUsed() > 0 || process.getRemainingDuration() > 0)) {
client.removeSceneDirectory(this); event.doNotifyIsStarted();
directoryRemoved = true;
} }
} }
input.close(); input.close();
@@ -859,4 +856,23 @@ public class Job {
return config.getTileSize(); return config.getTileSize();
} }
} }
public static class renderStartedObservable extends Observable {
private boolean isStarted;
public renderStartedObservable(Observer observer) {
super();
addObserver(observer);
}
public void doNotifyIsStarted() {
setChanged();
notifyObservers();
isStarted = true;
}
public boolean isStarted() {
return isStarted;
}
}
} }

View File

@@ -464,7 +464,6 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
Job a_job = new Job( Job a_job = new Job(
this.user_config, this.user_config,
this.client,
this.client.getGui(), this.client.getGui(),
this.client.getLog(), this.client.getLog(),
job_node.getAttribute("id"), job_node.getAttribute("id"),