Feat: Don't do last render image request, use local image

This commit is contained in:
Laurent Clouet
2020-04-14 17:32:22 +02:00
parent b2227e9f4f
commit 08fe55564c
5 changed files with 37 additions and 64 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@@ -329,9 +329,6 @@ public class Client {
gui.error("Client::run problem with confirmJob (returned " + ret + ")"); gui.error("Client::run problem with confirmJob (returned " + ret + ")");
sendError(step); sendError(step);
} }
else {
gui.AddFrameRendered();
}
} }
else { else {
this.jobsToValidate.add(this.renderingJob); this.jobsToValidate.add(this.renderingJob);
@@ -446,9 +443,6 @@ public class Client {
this.log.debug("Client::senderLoop confirm failed, ret: " + ret); this.log.debug("Client::senderLoop confirm failed, ret: " + ret);
sendError(step); sendError(step);
} }
else {
gui.AddFrameRendered();
}
} }
catch (InterruptedException e) { catch (InterruptedException e) {
} }
@@ -795,15 +789,17 @@ public class Client {
} }
} }
} }
this.isValidatingJob = false; this.isValidatingJob = false;
this.previousJob = ajob;
gui.AddFrameRendered();
// we can remove the frame file // we can remove the frame file
File frame = new File(ajob.getOutputImagePath()); File frame = new File(ajob.getOutputImagePath());
frame.delete(); frame.delete();
ajob.setOutputImagePath(null); ajob.setOutputImagePath(null);
this.isValidatingJob = false;
this.previousJob = ajob;
return Error.Type.OK; return Error.Type.OK;
} }

View File

@@ -686,42 +686,6 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
return ServerCode.UNKNOWN; return ServerCode.UNKNOWN;
} }
public byte[] getLastRender() {
try {
HttpURLConnection httpCon = this.HTTPRequest(this.getPage("last-render-frame"));
InputStream inStrm = httpCon.getInputStream();
if (httpCon.getResponseCode() != HttpURLConnection.HTTP_OK) {
this.log.debug("Server::getLastRender code not ok " + httpCon.getResponseCode());
return null;
}
int size = httpCon.getContentLength();
if (size <= 0) {
this.log.debug("Server::getLastRender size is negative (size: " + size + ")");
return null;
}
byte[] ret = new byte[size];
byte[] ch = new byte[512 * 1024];
int n = 0;
int i = 0;
while ((n = inStrm.read(ch)) != -1) {
System.arraycopy(ch, 0, ret, i, n);
i += n;
}
inStrm.close();
return ret;
}
catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
this.log.debug("Server::getLastRender Exception " + e + " stacktrace: " + sw.toString());
}
return null;
}
private String generateXMLForMD5cache() { private String generateXMLForMD5cache() {
List<FileMD5> md5s = new ArrayList<>(); List<FileMD5> md5s = new ArrayList<>();
for (File local_file : this.user_config.getLocalCacheFiles()) { for (File local_file : this.user_config.getLocalCacheFiles()) {

View File

@@ -27,9 +27,9 @@ import java.awt.GridLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.awt.Image;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Date; import java.util.Date;
@@ -46,11 +46,8 @@ import javax.swing.SpringLayout;
import com.sheepit.client.Client; import com.sheepit.client.Client;
import com.sheepit.client.Job; import com.sheepit.client.Job;
import com.sheepit.client.RenderProcess;
import com.sheepit.client.Server;
import com.sheepit.client.Stats; import com.sheepit.client.Stats;
import com.sheepit.client.Utils; import com.sheepit.client.Utils;
import com.sheepit.client.os.OS;
import com.sheepit.client.standalone.GuiSwing; import com.sheepit.client.standalone.GuiSwing;
import com.sheepit.client.standalone.GuiSwing.ActivityType; import com.sheepit.client.standalone.GuiSwing.ActivityType;
@@ -307,28 +304,44 @@ public class Working implements Activity {
Client client = parent.getClient(); Client client = parent.getClient();
if (client != null) { if (client != null) {
Job lastJob = client.getPreviousJob(); Job lastJob = client.getPreviousJob();
Server server = client.getServer();
if (server != null) {
byte[] data = server.getLastRender();
if (data != null) {
InputStream is = new ByteArrayInputStream(data);
try {
BufferedImage image = ImageIO.read(is);
if (image != null) {
lastRender.setIcon(new ImageIcon(image));
if (lastJob != null) { if (lastJob != null) {
// don't use lastJob.getProcessRender().getDuration() due to timezone ImageIcon icon = null;
if (lastJob.getProcessRender().getDuration() > 1) { int idInt = Integer.parseInt(lastJob.getId());
lastRenderTime.setText("Render time : " + Utils.humanDuration(new Date(lastJob.getProcessRender().getEndTime() - lastJob.getProcessRender().getStartTime()))); if (idInt == 1) {
icon = new ImageIcon(getClass().getResource("/frame_compute_method.jpg"));
} }
else if (idInt < 20) {
icon = new ImageIcon(getClass().getResource("/frame_power_detection.jpg"));
} }
else {
try {
String path = lastJob.getOutputImagePath();
BufferedImage img = ImageIO.read(new File(path));
float width = img.getWidth();
float height = img.getHeight();
float factor = 1.0f;
if (height > 200) {
factor = 200f / height;
} }
if (width * factor > 200) {
factor = Math.min(factor, 200f / width);
}
icon = new ImageIcon(img.getScaledInstance((int)(width * factor), (int)(height * factor), Image.SCALE_FAST));
} }
catch (IOException e) { catch (IOException e) {
System.out.println("Working::showLastRender() exception " + e); System.out.println("Working::showLastRender() exception " + e);
e.printStackTrace(); e.printStackTrace();
} }
} }
if (icon != null) {
lastRender.setIcon(icon);
// don't use lastJob.getProcessRender().getDuration() due to timezone
if (lastJob.getProcessRender().getDuration() > 1) {
lastRenderTime.setText("Render time : " + Utils.humanDuration(new Date(lastJob.getProcessRender().getEndTime() - lastJob.getProcessRender().getStartTime())));
}
}
} }
} }