Use lombok annotation instead of get/set

This commit is contained in:
Laurent Clouet
2019-08-07 22:17:59 +02:00
parent 9b36dcf9b5
commit 9f1f509bb6
12 changed files with 123 additions and 420 deletions

View File

@@ -29,6 +29,7 @@
<pathelement location="extern/platform.jar"/> <pathelement location="extern/platform.jar"/>
<pathelement location="extern/jna.jar"/> <pathelement location="extern/jna.jar"/>
<pathelement location="extern/args4j.jar"/> <pathelement location="extern/args4j.jar"/>
<pathelement location="extern/lombok.jar"/>
<pathelement location="extern/zip4j.jar"/> <pathelement location="extern/zip4j.jar"/>
<pathelement location="extern/jaxb-api.jar"/> <pathelement location="extern/jaxb-api.jar"/>
<pathelement location="extern/jaxb-core.jar"/> <pathelement location="extern/jaxb-core.jar"/>
@@ -39,6 +40,7 @@
<unjar src="extern/platform.jar" dest="build"> <unjar src="extern/platform.jar" dest="build">
<filelist dir="." files="extern/jna.jar" /> <filelist dir="." files="extern/jna.jar" />
<filelist dir="." files="extern/args4j.jar" /> <filelist dir="." files="extern/args4j.jar" />
<filelist dir="." files="extern/lombok.jar" />
<filelist dir="." files="extern/zip4j.jar" /> <filelist dir="." files="extern/zip4j.jar" />
<filelist dir="." files="extern/jaxb-api.jar" /> <filelist dir="." files="extern/jaxb-api.jar" />
<filelist dir="." files="extern/jaxb-core.jar" /> <filelist dir="." files="extern/jaxb-core.jar" />

BIN
extern/lombok.jar vendored Normal file

Binary file not shown.

View File

@@ -47,16 +47,19 @@ import com.sheepit.client.exception.FermeExceptionSessionDisabled;
import com.sheepit.client.exception.FermeServerDown; import com.sheepit.client.exception.FermeServerDown;
import com.sheepit.client.os.OS; import com.sheepit.client.os.OS;
import lombok.Data;
@Data
public class Client { public class Client {
private Gui gui; private Gui gui;
private Server server; private Server server;
private Configuration config; private Configuration configuration;
private Log log; private Log log;
private Job renderingJob; private Job renderingJob;
private Job previousJob; private Job previousJob;
private BlockingQueue<Job> jobsToValidate; private BlockingQueue<Job> jobsToValidate;
private boolean isValidatingJob; private boolean isValidatingJob;
private long start_time; private long startTime;
private boolean disableErrorSending; private boolean disableErrorSending;
private boolean running; private boolean running;
@@ -64,10 +67,10 @@ public class Client {
private int maxDownloadFileAttempts = 5; private int maxDownloadFileAttempts = 5;
public Client(Gui gui_, Configuration config, String url_) { public Client(Gui gui_, Configuration configuration, String url_) {
this.config = config; this.configuration = configuration;
this.server = new Server(url_, this.config, this); this.server = new Server(url_, this.configuration, this);
this.log = Log.getInstance(this.config); this.log = Log.getInstance(this.configuration);
this.gui = gui_; this.gui = gui_;
this.renderingJob = null; this.renderingJob = null;
this.previousJob = null; this.previousJob = null;
@@ -80,40 +83,16 @@ public class Client {
} }
public String toString() { public String toString() {
return String.format("Client (config %s, server %s)", this.config, this.server); return String.format("Client (configuration %s, server %s)", this.configuration, this.server);
}
public Job getRenderingJob() {
return this.renderingJob;
}
public Gui getGui() {
return this.gui;
}
public Configuration getConfiguration() {
return this.config;
}
public Server getServer() {
return this.server;
}
public Log getLog() {
return this.log;
}
public long getStartTime() {
return this.start_time;
} }
public int run() { public int run() {
if (this.config.checkOSisSupported() == false) { if (this.configuration.checkOSisSupported() == false) {
this.gui.error(Error.humanString(Error.Type.OS_NOT_SUPPORTED)); this.gui.error(Error.humanString(Error.Type.OS_NOT_SUPPORTED));
return -3; return -3;
} }
if (this.config.checkCPUisSupported() == false) { if (this.configuration.checkCPUisSupported() == false) {
this.gui.error(Error.humanString(Error.Type.CPU_NOT_SUPPORTED)); this.gui.error(Error.humanString(Error.Type.CPU_NOT_SUPPORTED));
return -4; return -4;
} }
@@ -125,7 +104,7 @@ public class Client {
step = this.log.newCheckPoint(); step = this.log.newCheckPoint();
this.gui.status("Starting"); this.gui.status("Starting");
this.config.cleanWorkingDirectory(); this.configuration.cleanWorkingDirectory();
Error.Type ret; Error.Type ret;
ret = this.server.getConfiguration(); ret = this.server.getConfiguration();
@@ -138,7 +117,7 @@ public class Client {
return -1; return -1;
} }
this.start_time = new Date().getTime(); this.startTime = new Date().getTime();
this.server.start(); // for staying alive this.server.start(); // for staying alive
// create a thread which will send the frame // create a thread which will send the frame
@@ -215,7 +194,7 @@ public class Client {
this.renderingJob = null; this.renderingJob = null;
} }
else { else {
this.start_time = new Date().getTime(); // reset start session time because the server did it this.startTime = new Date().getTime(); // reset start session time because the server did it
try { try {
Calendar next_request = this.nextJobRequest(); Calendar next_request = this.nextJobRequest();
if (next_request != null) { if (next_request != null) {
@@ -345,7 +324,7 @@ public class Client {
continue; continue;
} }
if (this.renderingJob.simultaneousUploadIsAllowed() == false) { // power or compute_method job, need to upload right away if (this.renderingJob.isSynchronousUpload() == false) { // power or compute_method job, need to upload right away
ret = confirmJob(this.renderingJob); ret = confirmJob(this.renderingJob);
if (ret != Error.Type.OK) { if (ret != Error.Type.OK) {
gui.error("Client::run problem with confirmJob (returned " + ret + ")"); gui.error("Client::run problem with confirmJob (returned " + ret + ")");
@@ -403,8 +382,8 @@ public class Client {
} }
} }
// this.config.workingDirectory.delete(); // this.configuration.workingDirectory.delete();
this.config.removeWorkingDirectory(); this.configuration.removeWorkingDirectory();
if (this.server == null) { if (this.server == null) {
return 0; return 0;
@@ -428,10 +407,6 @@ public class Client {
return 0; return 0;
} }
public boolean isSuspended() {
return this.suspended;
}
public void suspend() { public void suspend() {
suspended = true; suspended = true;
} }
@@ -451,10 +426,6 @@ public class Client {
this.running = true; this.running = true;
} }
public boolean isRunning() {
return this.running;
}
public int senderLoop() { public int senderLoop() {
int step = log.newCheckPoint(); int step = log.newCheckPoint();
Error.Type ret; Error.Type ret;
@@ -538,13 +509,13 @@ public class Client {
* @return the date of the next request, or null if there is not delay (null <=> now) * @return the date of the next request, or null if there is not delay (null <=> now)
*/ */
public Calendar nextJobRequest() { public Calendar nextJobRequest() {
if (this.config.requestTime == null) { if (this.configuration.getRequestTime() == null) {
return null; return null;
} }
else { else {
Calendar next = null; Calendar next = null;
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
for (Pair<Calendar, Calendar> interval : this.config.requestTime) { for (Pair<Calendar, Calendar> interval : this.configuration.getRequestTime()) {
Calendar start = (Calendar) now.clone(); Calendar start = (Calendar) now.clone();
Calendar end = (Calendar) now.clone(); Calendar end = (Calendar) now.clone();
start.set(Calendar.SECOND, 00); start.set(Calendar.SECOND, 00);
@@ -605,14 +576,14 @@ public class Client {
if (scene_file.exists() == false) { if (scene_file.exists() == false) {
gui.setRenderingProjectName(""); gui.setRenderingProjectName("");
this.log.error("Client::work job preparation failed (scene file '" + scene_file.getAbsolutePath() + "' does not exist), cleaning directory in hope to recover"); this.log.error("Client::work job preparation failed (scene file '" + scene_file.getAbsolutePath() + "' does not exist), cleaning directory in hope to recover");
this.config.cleanWorkingDirectory(); this.configuration.cleanWorkingDirectory();
return Error.Type.MISSING_SCENE; return Error.Type.MISSING_SCENE;
} }
if (renderer_file.exists() == false) { if (renderer_file.exists() == false) {
gui.setRenderingProjectName(""); gui.setRenderingProjectName("");
this.log.error("Client::work job preparation failed (renderer file '" + renderer_file.getAbsolutePath() + "' does not exist), cleaning directory in hope to recover"); this.log.error("Client::work job preparation failed (renderer file '" + renderer_file.getAbsolutePath() + "' does not exist), cleaning directory in hope to recover");
this.config.cleanWorkingDirectory(); this.configuration.cleanWorkingDirectory();
return Error.Type.MISSING_RENDERER; return Error.Type.MISSING_RENDERER;
} }
@@ -631,7 +602,7 @@ public class Client {
this.log.error("Client::work problem with runRenderer (ret " + err + ")"); this.log.error("Client::work problem with runRenderer (ret " + err + ")");
if (err == Error.Type.RENDERER_CRASHED_PYTHON_ERROR) { if (err == Error.Type.RENDERER_CRASHED_PYTHON_ERROR) {
this.log.error("Client::work failed with python error, cleaning directory in hope to recover"); this.log.error("Client::work failed with python error, cleaning directory in hope to recover");
this.config.cleanWorkingDirectory(); this.configuration.cleanWorkingDirectory();
} }
return err; return err;
} }
@@ -646,7 +617,7 @@ public class Client {
} }
protected int downloadExecutable(Job ajob) throws FermeExceptionNoSpaceLeftOnDevice { protected int downloadExecutable(Job ajob) throws FermeExceptionNoSpaceLeftOnDevice {
return this.downloadFile(ajob, ajob.getRendererArchivePath(), ajob.getRenderMd5(), String.format("%s?type=binary&job=%s", this.server.getPage("download-archive"), ajob.getId()), "renderer"); return this.downloadFile(ajob, ajob.getRendererArchivePath(), ajob.getRendererMD5(), String.format("%s?type=binary&job=%s", this.server.getPage("download-archive"), ajob.getId()), "renderer");
} }
private int downloadFile(Job ajob, String local_path, String md5_server, String url, String download_type) throws FermeExceptionNoSpaceLeftOnDevice { private int downloadFile(Job ajob, String local_path, String md5_server, String url, String download_type) throws FermeExceptionNoSpaceLeftOnDevice {
@@ -757,7 +728,7 @@ public class Client {
scene_path_file.mkdir(); scene_path_file.mkdir();
// unzip the archive // unzip the archive
ret = Utils.unzipFileIntoDirectory(scene_archive, scene_path, ajob.getSceneArchivePassword(), log); ret = Utils.unzipFileIntoDirectory(scene_archive, scene_path, ajob.getPassword(), log);
if (ret != 0) { if (ret != 0) {
this.log.error("Client::prepareWorkingDirectory, error(2) with Utils.unzipFileIntoDirectory(" + scene_archive + ", " + scene_path + ") returned " + ret); this.log.error("Client::prepareWorkingDirectory, error(2) with Utils.unzipFileIntoDirectory(" + scene_archive + ", " + scene_path + ") returned " + ret);
this.gui.error("Client::prepareWorkingDirectory, error with Utils.unzipFileIntoDirectory of the scene (returned " + ret + ")"); this.gui.error("Client::prepareWorkingDirectory, error with Utils.unzipFileIntoDirectory of the scene (returned " + ret + ")");
@@ -825,15 +796,11 @@ public class Client {
return Error.Type.OK; return Error.Type.OK;
} }
public Job getPreviousJob() {
return this.previousJob;
}
protected boolean shouldWaitBeforeRender() { protected boolean shouldWaitBeforeRender() {
int concurrent_job = this.jobsToValidate.size(); int concurrent_job = this.jobsToValidate.size();
if (this.isValidatingJob) { if (this.isValidatingJob) {
concurrent_job++; concurrent_job++;
} }
return (concurrent_job >= this.config.maxUploadingJob()); return (concurrent_job >= this.configuration.getMaxUploadingJob());
} }
} }

View File

@@ -34,17 +34,19 @@ import java.util.List;
import com.sheepit.client.hardware.cpu.CPU; import com.sheepit.client.hardware.cpu.CPU;
import com.sheepit.client.hardware.gpu.GPUDevice; import com.sheepit.client.hardware.gpu.GPUDevice;
import com.sheepit.client.os.OS; import com.sheepit.client.os.OS;
import lombok.Data;
@Data
public class Configuration { public class Configuration {
public enum ComputeType { public enum ComputeType {
CPU_GPU, CPU, GPU CPU_GPU, CPU, GPU
} // accept job for ... } // accept job for ...
private String configFilePath; private String configFilePath;
public File workingDirectory; private File workingDirectory;
public File storageDirectory; // for permanent storage (binary archive) private File storageDirectory; // for permanent storage (binary archive)
public boolean userHasSpecifiedACacheDir; private boolean userHasSpecifiedACacheDir;
public String static_exeDirName; private String static_exeDirName;
private String login; private String login;
private String password; private String password;
private String proxy; private String proxy;
@@ -57,7 +59,7 @@ public class Configuration {
private GPUDevice GPUDevice; private GPUDevice GPUDevice;
private boolean detectGPUs; private boolean detectGPUs;
private boolean printLog; private boolean printLog;
public List<Pair<Calendar, Calendar>> requestTime; private List<Pair<Calendar, Calendar>> requestTime;
private String extras; private String extras;
private boolean autoSignIn; private boolean autoSignIn;
private String UIType; private String UIType;
@@ -96,78 +98,6 @@ public class Configuration {
return String.format("Configuration (workingDirectory '%s')", this.workingDirectory.getAbsolutePath()); return String.format("Configuration (workingDirectory '%s')", this.workingDirectory.getAbsolutePath());
} }
public String getConfigFilePath() {
return this.configFilePath;
}
public void setConfigPath(String val) {
this.configFilePath = val;
}
public String login() {
return this.login;
}
public void setLogin(String login_) {
this.login = login_;
}
public String password() {
return this.password;
}
public void setPassword(String password_) {
this.password = password_;
}
public String getProxy() {
return this.proxy;
}
public void setProxy(String url) {
this.proxy = url;
}
public int maxUploadingJob() {
return this.maxUploadingJob;
}
public GPUDevice getGPUDevice() {
return this.GPUDevice;
}
public boolean getDetectGPUs() {
return this.detectGPUs;
}
public void setMaxUploadingJob(int max) {
this.maxUploadingJob = max;
}
public void setUseNbCores(int nbcores) {
this.nbCores = nbcores;
}
public int getNbCores() {
return this.nbCores;
}
public void setMaxMemory(long max) {
this.maxMemory = max;
}
public long getMaxMemory() {
return this.maxMemory;
}
public void setMaxRenderTime(int max) {
this.maxRenderTime = max;
}
public int getMaxRenderTime() {
return this.maxRenderTime;
}
public void setUsePriority(int priority) { public void setUsePriority(int priority) {
if (priority > 19) if (priority > 19)
priority = 19; priority = 19;
@@ -178,38 +108,10 @@ public class Configuration {
} }
public int getPriority() {
return this.priority;
}
public void setPrintLog(boolean val) {
this.printLog = val;
}
public boolean getPrintLog() {
return this.printLog;
}
public int computeMethodToInt() { public int computeMethodToInt() {
return this.computeMethod.ordinal(); return this.computeMethod.ordinal();
} }
public ComputeType getComputeMethod() {
return this.computeMethod;
}
public void setUseGPU(GPUDevice device) {
this.GPUDevice = device;
}
public void setDetectGPUs(boolean val) {
this.detectGPUs = val;
}
public void setComputeMethod(ComputeType meth) {
this.computeMethod = meth;
}
public void setCacheDir(File cache_dir_) { public void setCacheDir(File cache_dir_) {
removeWorkingDirectory(); removeWorkingDirectory();
if (cache_dir_ == null) { if (cache_dir_ == null) {
@@ -259,12 +161,8 @@ public class Configuration {
} }
} }
public boolean getUserHasSpecifiedACacheDir() {
return this.userHasSpecifiedACacheDir;
}
public File getCacheDirForSettings() { public File getCacheDirForSettings() {
if (this.getUserHasSpecifiedACacheDir() == false) { if (this.userHasSpecifiedACacheDir == false) {
return null; return null;
} }
else { else {
@@ -273,46 +171,6 @@ public class Configuration {
} }
} }
public void setExtras(String str) {
this.extras = str;
}
public String getExtras() {
return this.extras;
}
public void setAutoSignIn(boolean v) {
this.autoSignIn = v;
}
public boolean getAutoSignIn() {
return this.autoSignIn;
}
public void setUIType(String ui) {
this.UIType = ui;
}
public String getUIType() {
return this.UIType;
}
public void setTileSize(int size) {
this.tileSize = size;
}
public int getTileSize() {
return this.tileSize;
}
public void setHostname(String hostname_) {
this.hostname = hostname_;
}
public String getHostname() {
return this.hostname;
}
public String getDefaultHostname() { public String getDefaultHostname() {
try { try {
return InetAddress.getLocalHost().getHostName(); return InetAddress.getLocalHost().getHostName();

View File

@@ -46,17 +46,20 @@ import com.sheepit.client.Error.Type;
import com.sheepit.client.hardware.gpu.GPUDevice; import com.sheepit.client.hardware.gpu.GPUDevice;
import com.sheepit.client.hardware.gpu.opencl.OpenCL; import com.sheepit.client.hardware.gpu.opencl.OpenCL;
import com.sheepit.client.os.OS; import com.sheepit.client.os.OS;
import lombok.Data;
import lombok.Getter;
@Data
public class Job { public class Job {
public static final String UPDATE_METHOD_BY_REMAINING_TIME = "remainingtime"; public static final String UPDATE_METHOD_BY_REMAINING_TIME = "remainingtime";
public static final String UPDATE_METHOD_BLENDER_INTERNAL_BY_PART = "blenderinternal"; public static final String UPDATE_METHOD_BLENDER_INTERNAL_BY_PART = "blenderinternal";
public static final String UPDATE_METHOD_BY_TILE = "by_tile"; public static final String UPDATE_METHOD_BY_TILE = "by_tile";
private String numFrame; private String frameNumber;
private String sceneMD5; private String sceneMD5;
private String rendererMD5; private String rendererMD5;
private String id; private String id;
private String pictureFilename; private String outputImagePath;
private String path; // path inside of the archive private String path; // path inside of the archive
private String rendererCommand; private String rendererCommand;
private String script; private String script;
@@ -71,13 +74,13 @@ public class Job {
private boolean userBlockJob; private boolean userBlockJob;
private boolean serverBlockJob; private boolean serverBlockJob;
private Gui gui; private Gui gui;
private Configuration config; private Configuration configuration;
private Log log; private Log log;
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_, 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_; configuration = config_;
id = id_; id = id_;
numFrame = frame_; frameNumber = frame_;
path = path_; path = path_;
useGPU = use_gpu; useGPU = use_gpu;
rendererCommand = command_; rendererCommand = command_;
@@ -88,7 +91,7 @@ public class Job {
extras = extras_; extras = extras_;
synchronousUpload = synchronous_upload_; synchronousUpload = synchronous_upload_;
gui = gui_; gui = gui_;
pictureFilename = null; outputImagePath = null;
script = script_; script = script_;
updateRenderingStatusMethod = update_method_; updateRenderingStatusMethod = update_method_;
askForRendererKill = false; askForRendererKill = false;
@@ -112,83 +115,7 @@ public class Job {
} }
public String toString() { public String toString() {
return String.format("Job (numFrame '%s' sceneMD5 '%s' rendererMD5 '%s' ID '%s' pictureFilename '%s' jobPath '%s' gpu %s name '%s' extras '%s' updateRenderingStatusMethod '%s' render %s)", numFrame, sceneMD5, rendererMD5, id, pictureFilename, path, useGPU, name, extras, updateRenderingStatusMethod, render); return String.format("Job (numFrame '%s' sceneMD5 '%s' rendererMD5 '%s' ID '%s' pictureFilename '%s' jobPath '%s' gpu %s name '%s' extras '%s' updateRenderingStatusMethod '%s' render %s)", frameNumber, sceneMD5, rendererMD5, id, outputImagePath, path, useGPU, name, extras, updateRenderingStatusMethod, render);
}
public String getId() {
return id;
}
public String getFrameNumber() {
return numFrame;
}
public String getExtras() {
return extras;
}
public String getScript() {
return script;
}
public String getSceneMD5() {
return sceneMD5;
}
public String getRenderMd5() {
return rendererMD5;
}
public String getPath() {
return path;
}
public String getUpdateRenderingStatusMethod() {
return updateRenderingStatusMethod;
}
public void setAskForRendererKill(boolean val) {
askForRendererKill = val;
}
public boolean getAskForRendererKill() {
return askForRendererKill;
}
public void setUserBlockJob(boolean val) {
userBlockJob = val;
}
public boolean getUserBlockJob() {
return userBlockJob;
}
public void setServerBlockJob(boolean val) {
serverBlockJob = val;
}
public boolean getServerBlockJob() {
return serverBlockJob;
}
public String getRenderCommand() {
return rendererCommand;
}
public boolean getUseGPU() {
return useGPU;
}
public String getName() {
return name;
}
public void setOutputImagePath(String path) {
pictureFilename = path;
}
public String getOutputImagePath() {
return pictureFilename;
} }
public String getPrefixOutputImage() { public String getPrefixOutputImage() {
@@ -196,7 +123,7 @@ public class Job {
} }
public String getRendererDirectory() { public String getRendererDirectory() {
return config.workingDirectory.getAbsolutePath() + File.separator + rendererMD5; return configuration.getWorkingDirectory().getAbsolutePath() + File.separator + rendererMD5;
} }
public String getRendererPath() { public String getRendererPath() {
@@ -204,11 +131,11 @@ public class Job {
} }
public String getRendererArchivePath() { public String getRendererArchivePath() {
return config.getStorageDir().getAbsolutePath() + File.separator + rendererMD5 + ".zip"; return configuration.getStorageDir().getAbsolutePath() + File.separator + rendererMD5 + ".zip";
} }
public String getSceneDirectory() { public String getSceneDirectory() {
return config.workingDirectory.getAbsolutePath() + File.separator + sceneMD5; return configuration.getWorkingDirectory().getAbsolutePath() + File.separator + sceneMD5;
} }
public String getScenePath() { public String getScenePath() {
@@ -216,15 +143,7 @@ public class Job {
} }
public String getSceneArchivePath() { public String getSceneArchivePath() {
return config.workingDirectory.getAbsolutePath() + File.separator + sceneMD5 + ".zip"; return configuration.getWorkingDirectory().getAbsolutePath() + File.separator + sceneMD5 + ".zip";
}
public String getSceneArchivePassword() {
return password;
}
public boolean simultaneousUploadIsAllowed() {
return synchronousUpload;
} }
public Error.Type render(Observer renderStarted) { public Error.Type render(Observer renderStarted) {
@@ -239,8 +158,8 @@ public class Job {
+ "def hndl(signum, frame):\n" + "def hndl(signum, frame):\n"
+ " pass\n" + " pass\n"
+ "signal.signal(signal.SIGINT, hndl)\n"; + "signal.signal(signal.SIGINT, hndl)\n";
if (getUseGPU() && config.getGPUDevice() != null && config.getComputeMethod() != ComputeType.CPU) { if (isUseGPU() && configuration.getGPUDevice() != null && configuration.getComputeMethod() != ComputeType.CPU) {
core_script = "sheepit_set_compute_device(\"" + config.getGPUDevice().getType() + "\", \"GPU\", \"" + config.getGPUDevice().getId() + "\")\n"; core_script = "sheepit_set_compute_device(\"" + configuration.getGPUDevice().getType() + "\", \"GPU\", \"" + configuration.getGPUDevice().getId() + "\")\n";
gui.setComputeMethod("GPU"); gui.setComputeMethod("GPU");
} }
else { else {
@@ -251,10 +170,10 @@ public class Job {
core_script += ignore_signal_script; core_script += ignore_signal_script;
core_script += String.format("bpy.context.scene.render.tile_x = %1$d\nbpy.context.scene.render.tile_y = %1$d\n", getTileSize()); core_script += String.format("bpy.context.scene.render.tile_x = %1$d\nbpy.context.scene.render.tile_y = %1$d\n", getTileSize());
File script_file = null; File script_file = null;
String command1[] = getRenderCommand().split(" "); String command1[] = getRendererCommand().split(" ");
int size_command = command1.length + 2; // + 2 for script int size_command = command1.length + 2; // + 2 for script
if (config.getNbCores() > 0) { // user has specified something if (configuration.getNbCores() > 0) { // user has specified something
size_command += 2; size_command += 2;
} }
@@ -262,13 +181,13 @@ public class Job {
Map<String, String> new_env = new HashMap<String, String>(); Map<String, String> new_env = new HashMap<String, String>();
new_env.put("BLENDER_USER_CONFIG", config.workingDirectory.getAbsolutePath().replace("\\", "\\\\")); new_env.put("BLENDER_USER_CONFIG", configuration.getWorkingDirectory().getAbsolutePath().replace("\\", "\\\\"));
new_env.put("CORES", Integer.toString(config.getNbCores())); new_env.put("CORES", Integer.toString(configuration.getNbCores()));
new_env.put("PRIORITY", Integer.toString(config.getPriority())); new_env.put("PRIORITY", Integer.toString(configuration.getPriority()));
new_env.put("PYTHONPATH", ""); // make sure blender is using the embedded python, if not it could create "Fatal Python error: Py_Initialize" new_env.put("PYTHONPATH", ""); // make sure blender is using the embedded python, if not it could create "Fatal Python error: Py_Initialize"
new_env.put("PYTHONHOME", "");// make sure blender is using the embedded python, if not it could create "Fatal Python error: Py_Initialize" new_env.put("PYTHONHOME", "");// make sure blender is using the embedded python, if not it could create "Fatal Python error: Py_Initialize"
if (getUseGPU() && config.getGPUDevice() != null && config.getComputeMethod() != ComputeType.CPU && OpenCL.TYPE.equals(config.getGPUDevice().getType())) { if (isUseGPU() && configuration.getGPUDevice() != null && configuration.getComputeMethod() != ComputeType.CPU && OpenCL.TYPE.equals(configuration.getGPUDevice().getType())) {
new_env.put("CYCLES_OPENCL_SPLIT_KERNEL_TEST", "1"); new_env.put("CYCLES_OPENCL_SPLIT_KERNEL_TEST", "1");
this.updateRenderingStatusMethod = UPDATE_METHOD_BY_TILE; // don't display remaining time this.updateRenderingStatusMethod = UPDATE_METHOD_BY_TILE; // don't display remaining time
} }
@@ -280,7 +199,7 @@ public class Job {
command.add("-P"); command.add("-P");
try { try {
script_file = File.createTempFile("script_", "", config.workingDirectory); script_file = File.createTempFile("script_", "", configuration.getWorkingDirectory());
File file = new File(script_file.getAbsolutePath()); File file = new File(script_file.getAbsolutePath());
FileWriter txt; FileWriter txt;
txt = new FileWriter(file); txt = new FileWriter(file);
@@ -305,13 +224,13 @@ public class Job {
case ".e": case ".e":
command.add(getRendererPath()); command.add(getRendererPath());
// the number of cores has to be put after the binary and before the scene arg // the number of cores has to be put after the binary and before the scene arg
if (config.getNbCores() > 0) { if (configuration.getNbCores() > 0) {
command.add("-t"); command.add("-t");
command.add(Integer.toString(config.getNbCores())); command.add(Integer.toString(configuration.getNbCores()));
} }
break; break;
case ".o": case ".o":
command.add(config.workingDirectory.getAbsolutePath() + File.separator + getPrefixOutputImage()); command.add(configuration.getWorkingDirectory().getAbsolutePath() + File.separator + getPrefixOutputImage());
break; break;
case ".f": case ".f":
command.add(getFrameNumber()); command.add(getFrameNumber());
@@ -327,12 +246,12 @@ public class Job {
String line; String line;
log.debug(command.toString()); log.debug(command.toString());
OS os = OS.getOS(); OS os = OS.getOS();
process.setCoresUsed(config.getNbCores()); process.setCoresUsed(configuration.getNbCores());
process.start(); process.start();
getProcessRender().setProcess(os.exec(command, new_env)); getProcessRender().setProcess(os.exec(command, new_env));
BufferedReader input = new BufferedReader(new InputStreamReader(getProcessRender().getProcess().getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(getProcessRender().getProcess().getInputStream()));
if (config.getMaxRenderTime() > 0) { if (configuration.getMaxRenderTime() > 0) {
timerOfMaxRenderTime = new Timer(); timerOfMaxRenderTime = new Timer();
timerOfMaxRenderTime.schedule(new TimerTask() { timerOfMaxRenderTime.schedule(new TimerTask() {
@Override @Override
@@ -340,14 +259,14 @@ public class Job {
RenderProcess process = getProcessRender(); RenderProcess process = getProcessRender();
if (process != null) { if (process != null) {
long duration = (new Date().getTime() - process.getStartTime() ) / 1000; // in seconds long duration = (new Date().getTime() - process.getStartTime() ) / 1000; // in seconds
if (config.getMaxRenderTime() > 0 && duration > config.getMaxRenderTime()) { if (configuration.getMaxRenderTime() > 0 && duration > configuration.getMaxRenderTime()) {
log.debug("Killing render because process duration"); log.debug("Killing render because process duration");
OS.getOS().kill(process.getProcess()); OS.getOS().kill(process.getProcess());
setAskForRendererKill(true); setAskForRendererKill(true);
} }
} }
} }
}, config.getMaxRenderTime() * 1000 + 2000); // +2s to be sure the delay is over }, configuration.getMaxRenderTime() * 1000 + 2000); // +2s to be sure the delay is over
} }
log.debug("renderer output"); log.debug("renderer output");
@@ -356,8 +275,8 @@ public class Job {
log.debug(line); log.debug(line);
updateRenderingMemoryPeak(line); updateRenderingMemoryPeak(line);
if (config.getMaxMemory() != -1 && process.getMemoryUsed() > config.getMaxMemory()) { if (configuration.getMaxMemory() != -1 && process.getMemoryUsed() > configuration.getMaxMemory()) {
log.debug("Blocking render because process ram used (" + process.getMemoryUsed() + "k) is over user setting (" + config.getMaxMemory() + "k)"); log.debug("Blocking render because process ram used (" + process.getMemoryUsed() + "k) is over user setting (" + configuration.getMaxMemory() + "k)");
OS.getOS().kill(process.getProcess()); OS.getOS().kill(process.getProcess());
process.finish(); process.finish();
if (script_file != null) { if (script_file != null) {
@@ -416,24 +335,24 @@ public class Job {
} }
}; };
File[] files = config.workingDirectory.listFiles(textFilter); File[] files = configuration.getWorkingDirectory().listFiles(textFilter);
if (getAskForRendererKill()) { if (isAskForRendererKill()) {
log.debug("Job::render been asked to end render"); log.debug("Job::render been asked to end render");
long duration = (new Date().getTime() - process.getStartTime() ) / 1000; // in seconds long duration = (new Date().getTime() - process.getStartTime() ) / 1000; // in seconds
if (config.getMaxRenderTime() > 0 && duration > config.getMaxRenderTime()) { if (configuration.getMaxRenderTime() > 0 && duration > configuration.getMaxRenderTime()) {
log.debug("Render killed because process duration (" + duration + "s) is over user setting (" + config.getMaxRenderTime() + "s)"); log.debug("Render killed because process duration (" + duration + "s) is over user setting (" + configuration.getMaxRenderTime() + "s)");
return Error.Type.RENDERER_KILLED_BY_USER_OVER_TIME; return Error.Type.RENDERER_KILLED_BY_USER_OVER_TIME;
} }
if (files.length != 0) { if (files.length != 0) {
new File(files[0].getAbsolutePath()).delete(); new File(files[0].getAbsolutePath()).delete();
} }
if (getServerBlockJob()) { if (isServerBlockJob()) {
return Error.Type.RENDERER_KILLED_BY_SERVER; return Error.Type.RENDERER_KILLED_BY_SERVER;
} }
if (getUserBlockJob()) { if (isUserBlockJob()) {
return Error.Type.RENDERER_KILLED_BY_USER; return Error.Type.RENDERER_KILLED_BY_USER;
} }
return Error.Type.RENDERER_KILLED; return Error.Type.RENDERER_KILLED;
@@ -449,7 +368,7 @@ public class Job {
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
File crash_file = new File(config.workingDirectory + File.separator + basename + ".crash.txt"); File crash_file = new File(configuration.getWorkingDirectory() + File.separator + basename + ".crash.txt");
if (crash_file.exists()) { if (crash_file.exists()) {
log.error("Job::render crash file found => the renderer crashed"); log.error("Job::render crash file found => the renderer crashed");
crash_file.delete(); crash_file.delete();
@@ -844,20 +763,22 @@ public class Job {
} }
public int getTileSize() { public int getTileSize() {
if (config.getTileSize() == -1) { // not set if (configuration.getTileSize() == -1) { // not set
int size = 32; // CPU int size = 32; // CPU
GPUDevice gpu = this.config.getGPUDevice(); GPUDevice gpu = this.configuration.getGPUDevice();
if (getUseGPU() && gpu != null) { if (isUseGPU() && gpu != null) {
return gpu.getRecommandedTileSize(); return gpu.getRecommandedTileSize();
} }
return size; return size;
} }
else { else {
return config.getTileSize(); return configuration.getTileSize();
} }
} }
public static class renderStartedObservable extends Observable { public static class renderStartedObservable extends Observable {
@Getter
private boolean isStarted; private boolean isStarted;
public renderStartedObservable(Observer observer) { public renderStartedObservable(Observer observer) {
@@ -870,9 +791,5 @@ public class Job {
notifyObservers(); notifyObservers();
isStarted = true; isStarted = true;
} }
public boolean isStarted() {
return isStarted;
}
} }
} }

View File

@@ -89,7 +89,7 @@ public class Log {
if (instance == null) { if (instance == null) {
boolean print = false; boolean print = false;
if (config != null) { if (config != null) {
print = config.getPrintLog(); print = config.isPrintLog();
} }
instance = new Log(print); instance = new Log(print);
} }

View File

@@ -19,82 +19,49 @@
package com.sheepit.client; package com.sheepit.client;
import lombok.Data;
import java.util.Date; import java.util.Date;
@Data
public class RenderProcess { public class RenderProcess {
private long start; private long startTime;
private long end; private long endTime;
private int remainingDuration; private int remainingDuration; // in seconds
private long memoryUsed; // in kB private long memoryUsed; // in kB
private int coresUsed; private int coresUsed;
private Process process; private Process process;
public RenderProcess() { public RenderProcess() {
process = null; process = null;
start = -1; startTime = -1;
end = -1; endTime = -1;
memoryUsed = 0; memoryUsed = 0;
coresUsed = 0; coresUsed = 0;
remainingDuration = 0; remainingDuration = 0;
} }
public void setMemoryUsed(long val) {
memoryUsed = val;
}
public long getMemoryUsed() {
return memoryUsed;
}
public void setCoresUsed(int val) {
coresUsed = val;
}
public int getCoresUsed() {
return coresUsed;
}
public long getStartTime() {
return start;
}
public long getEndTime() {
return end;
}
/** /**
* *
* @return duration in seconds * @return duration in seconds
*/ */
public int getDuration() { public int getDuration() {
if (start != -1 && end != -1) { if (startTime != -1 && endTime != -1) {
return (int) ((end - start) / 1000); return (int) ((endTime - startTime) / 1000);
} }
else if (start != -1) { else if (startTime != -1) {
return (int) ((new Date().getTime() - start) / 1000); return (int) ((new Date().getTime() - startTime) / 1000);
} }
return 0; return 0;
} }
/**
*
* @return duration in seconds
*/
public int getRemainingDuration() {
return remainingDuration;
}
public void setRemainingDuration(int val) {
remainingDuration = val;
}
public void finish() { public void finish() {
end = new Date().getTime(); endTime = new Date().getTime();
process = null; process = null;
} }
public void start() { public void start() {
start = new Date().getTime(); startTime = new Date().getTime();
} }
public int exitValue() { public int exitValue() {
@@ -118,12 +85,4 @@ public class RenderProcess {
} }
return value; return value;
} }
public void setProcess(Process val) {
process = val;
}
public Process getProcess() {
return process;
}
} }

View File

@@ -188,8 +188,8 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
try { try {
String url_remote = this.base_url + "/server/config.php"; String url_remote = this.base_url + "/server/config.php";
String parameters = String.format("login=%s&password=%s&cpu_family=%s&cpu_model=%s&cpu_model_name=%s&cpu_cores=%s&os=%s&ram=%s&bits=%s&version=%s&hostname=%s&ui=%s&extras=%s", String parameters = String.format("login=%s&password=%s&cpu_family=%s&cpu_model=%s&cpu_model_name=%s&cpu_cores=%s&os=%s&ram=%s&bits=%s&version=%s&hostname=%s&ui=%s&extras=%s",
URLEncoder.encode(this.user_config.login(), "UTF-8"), URLEncoder.encode(this.user_config.getLogin(), "UTF-8"),
URLEncoder.encode(this.user_config.password(), "UTF-8"), URLEncoder.encode(this.user_config.getPassword(), "UTF-8"),
URLEncoder.encode(os.getCPU().family(), "UTF-8"), URLEncoder.encode(os.getCPU().family(), "UTF-8"),
URLEncoder.encode(os.getCPU().model(), "UTF-8"), URLEncoder.encode(os.getCPU().model(), "UTF-8"),
URLEncoder.encode(os.getCPU().name(), "UTF-8"), URLEncoder.encode(os.getCPU().name(), "UTF-8"),
@@ -407,13 +407,13 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
// blender 2.7x // blender 2.7x
script += "try:\n"; script += "try:\n";
script += "\tbpy.context.user_preferences.filepaths.temporary_directory = \"" + this.user_config.workingDirectory.getAbsolutePath().replace("\\", "\\\\") + "\"\n"; script += "\tbpy.context.user_preferences.filepaths.temporary_directory = \"" + this.user_config.getWorkingDirectory().getAbsolutePath().replace("\\", "\\\\") + "\"\n";
script += "except AttributeError:\n"; script += "except AttributeError:\n";
script += "\tpass\n"; script += "\tpass\n";
// blender 2.80 // blender 2.80
script += "try:\n"; script += "try:\n";
script += "\tbpy.context.preferences.filepaths.temporary_directory = \"" + this.user_config.workingDirectory.getAbsolutePath().replace("\\", "\\\\") + "\"\n"; script += "\tbpy.context.preferences.filepaths.temporary_directory = \"" + this.user_config.getWorkingDirectory().getAbsolutePath().replace("\\", "\\\\") + "\"\n";
script += "except AttributeError:\n"; script += "except AttributeError:\n";
script += "\tpass\n"; script += "\tpass\n";
@@ -917,7 +917,7 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
for (int i = 0; i < ns.getLength(); ++i) { for (int i = 0; i < ns.getLength(); ++i) {
Element file_node = (Element) ns.item(i); Element file_node = (Element) ns.item(i);
if (file_node.hasAttribute("md5") && file_node.hasAttribute("action") && file_node.getAttribute("action").equals("delete")) { if (file_node.hasAttribute("md5") && file_node.hasAttribute("action") && file_node.getAttribute("action").equals("delete")) {
String path = this.user_config.workingDirectory.getAbsolutePath() + File.separatorChar + file_node.getAttribute("md5"); String path = this.user_config.getWorkingDirectory().getAbsolutePath() + File.separatorChar + file_node.getAttribute("md5");
this.log.debug("Server::handleFileMD5DeleteDocument delete old file " + path); this.log.debug("Server::handleFileMD5DeleteDocument delete old file " + path);
File file_to_delete = new File(path + ".zip"); File file_to_delete = new File(path + ".zip");
file_to_delete.delete(); file_to_delete.delete();

View File

@@ -312,10 +312,10 @@ public class SettingsLoader {
loadFile(); loadFile();
if (config.login().isEmpty() && login != null) { if (config.getLogin().isEmpty() && login != null) {
config.setLogin(login); config.setLogin(login);
} }
if (config.password().isEmpty() && password != null) { if (config.getPassword().isEmpty() && password != null) {
config.setPassword(password); config.setPassword(password);
} }
@@ -342,11 +342,11 @@ public class SettingsLoader {
if (config.getGPUDevice() == null && gpu != null) { if (config.getGPUDevice() == null && gpu != null) {
GPUDevice device = GPU.getGPUDevice(gpu); GPUDevice device = GPU.getGPUDevice(gpu);
if (device != null) { if (device != null) {
config.setUseGPU(device); config.setGPUDevice(device);
} }
} }
if (config.getNbCores() == -1 && cores != null) { if (config.getNbCores() == -1 && cores != null) {
config.setUseNbCores(Integer.valueOf(cores)); config.setNbCores(Integer.valueOf(cores));
} }
if (config.getMaxMemory() == -1 && ram != null) { if (config.getMaxMemory() == -1 && ram != null) {
@@ -357,7 +357,7 @@ public class SettingsLoader {
config.setMaxRenderTime(Integer.valueOf(renderTime)); config.setMaxRenderTime(Integer.valueOf(renderTime));
} }
if (config.getUserHasSpecifiedACacheDir() == false && cacheDir != null) { if (config.isUserHasSpecifiedACacheDir() == false && cacheDir != null) {
config.setCacheDir(new File(cacheDir)); config.setCacheDir(new File(cacheDir));
} }

View File

@@ -63,7 +63,7 @@ public class GPU {
public static List<GPUDevice> listDevices(Configuration config) { public static List<GPUDevice> listDevices(Configuration config) {
if (devices == null) { if (devices == null) {
if (config.getDetectGPUs()) { if (config.isDetectGPUs()) {
generate(); generate();
} }
else { else {

View File

@@ -167,13 +167,13 @@ public class Worker {
System.err.println("GPU unknown, list of available gpus can be display with --show-gpu"); System.err.println("GPU unknown, list of available gpus can be display with --show-gpu");
System.exit(2); System.exit(2);
} }
config.setUseGPU(gpu); config.setGPUDevice(gpu);
} }
if (request_time != null) { if (request_time != null) {
String[] intervals = request_time.split(","); String[] intervals = request_time.split(",");
if (intervals != null) { if (intervals != null) {
config.requestTime = new LinkedList<Pair<Calendar, Calendar>>(); config.setRequestTime(new LinkedList<Pair<Calendar, Calendar>>());
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm"); SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
for (String interval : intervals) { for (String interval : intervals) {
@@ -192,7 +192,7 @@ public class Worker {
} }
if (start.before(end)) { if (start.before(end)) {
config.requestTime.add(new Pair<Calendar, Calendar>(start, end)); config.getRequestTime().add(new Pair<Calendar, Calendar>(start, end));
} }
else { else {
System.err.println("Error: wrong request time " + times[0] + " is after " + times[1]); System.err.println("Error: wrong request time " + times[0] + " is after " + times[1]);
@@ -208,7 +208,7 @@ public class Worker {
return; return;
} }
else { else {
config.setUseNbCores(nb_cores); config.setNbCores(nb_cores);
} }
if (max_ram != null) { if (max_ram != null) {
@@ -274,7 +274,7 @@ public class Worker {
System.exit(2); System.exit(2);
} }
else if (compute_method == ComputeType.CPU) { else if (compute_method == ComputeType.CPU) {
config.setUseGPU(null); // remove the GPU config.setGPUDevice(null); // remove the GPU
} }
config.setComputeMethod(compute_method); config.setComputeMethod(compute_method);
@@ -289,7 +289,7 @@ public class Worker {
System.err.println("Aborting"); System.err.println("Aborting");
System.exit(2); System.exit(2);
} }
config.setConfigPath(config_file); config.setConfigFilePath(config_file);
new SettingsLoader(config_file).merge(config); new SettingsLoader(config_file).merge(config);
} }
@@ -302,7 +302,7 @@ public class Worker {
} }
switch (type) { switch (type) {
case GuiTextOneLine.type: case GuiTextOneLine.type:
if (config.getPrintLog()) { if (config.isPrintLog()) {
System.out.println("OneLine UI can not be used if verbose mode is enabled"); System.out.println("OneLine UI can not be used if verbose mode is enabled");
System.exit(2); System.exit(2);
} }

View File

@@ -121,12 +121,12 @@ public class Settings implements Activity {
JLabel loginLabel = new JLabel("Username:"); JLabel loginLabel = new JLabel("Username:");
login = new JTextField(); login = new JTextField();
login.setText(parent.getConfiguration().login()); login.setText(parent.getConfiguration().getLogin());
login.setColumns(20); login.setColumns(20);
login.addKeyListener(new CheckCanStart()); login.addKeyListener(new CheckCanStart());
JLabel passwordLabel = new JLabel("Password:"); JLabel passwordLabel = new JLabel("Password:");
password = new JPasswordField(); password = new JPasswordField();
password.setText(parent.getConfiguration().password()); password.setText(parent.getConfiguration().getPassword());
password.setColumns(10); password.setColumns(10);
password.addKeyListener(new CheckCanStart()); password.addKeyListener(new CheckCanStart());
@@ -147,7 +147,7 @@ public class Settings implements Activity {
JLabel cacheLabel = new JLabel("Working directory:"); JLabel cacheLabel = new JLabel("Working directory:");
directory_panel.add(cacheLabel); directory_panel.add(cacheLabel);
String destination = DUMMY_CACHE_DIR; String destination = DUMMY_CACHE_DIR;
if (config.getUserHasSpecifiedACacheDir()) { if (config.isUserHasSpecifiedACacheDir()) {
destination = config.getCacheDirForSettings().getName(); destination = config.getCacheDirForSettings().getName();
} }
@@ -388,7 +388,7 @@ public class Settings implements Activity {
saveFile = new JCheckBox("Save settings", true); saveFile = new JCheckBox("Save settings", true);
general_panel.add(saveFile); general_panel.add(saveFile);
autoSignIn = new JCheckBox("Auto sign in", config.getAutoSignIn()); autoSignIn = new JCheckBox("Auto sign in", config.isAutoSignIn());
autoSignIn.addActionListener(new AutoSignInChangeAction()); autoSignIn.addActionListener(new AutoSignInChangeAction());
general_panel.add(autoSignIn); general_panel.add(autoSignIn);
@@ -413,7 +413,7 @@ public class Settings implements Activity {
constraints.gridy = currentRow; constraints.gridy = currentRow;
parent.getContentPane().add(saveButton, constraints); parent.getContentPane().add(saveButton, constraints);
if (haveAutoStarted == false && config.getAutoSignIn() && checkDisplaySaveButton()) { if (haveAutoStarted == false && config.isAutoSignIn() && checkDisplaySaveButton()) {
// auto start // auto start
haveAutoStarted = true; haveAutoStarted = true;
new SaveAction().actionPerformed(null); new SaveAction().actionPerformed(null);
@@ -548,7 +548,7 @@ public class Settings implements Activity {
config.setComputeMethod(method); config.setComputeMethod(method);
if (selected_gpu != null) { if (selected_gpu != null) {
config.setUseGPU(selected_gpu); config.setGPUDevice(selected_gpu);
} }
int cpu_cores = -1; int cpu_cores = -1;
@@ -557,7 +557,7 @@ public class Settings implements Activity {
} }
if (cpu_cores > 0) { if (cpu_cores > 0) {
config.setUseNbCores(cpu_cores); config.setNbCores(cpu_cores);
} }
long max_ram = -1; long max_ram = -1;
@@ -609,7 +609,7 @@ public class Settings implements Activity {
parent.setCredentials(login.getText(), new String(password.getPassword())); parent.setCredentials(login.getText(), new String(password.getPassword()));
String cachePath = null; String cachePath = null;
if (config.getUserHasSpecifiedACacheDir() && config.getCacheDirForSettings() != null) { if (config.isUserHasSpecifiedACacheDir() && config.getCacheDirForSettings() != null) {
cachePath = config.getCacheDirForSettings().getAbsolutePath(); cachePath = config.getCacheDirForSettings().getAbsolutePath();
} }