Ref: cleanup, organise packages
This commit is contained in:
@@ -46,9 +46,12 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.sheepit.client.Error.ServerCode;
|
||||
import com.sheepit.client.Error.Type;
|
||||
import com.sheepit.client.datamodel.Chunk;
|
||||
import com.sheepit.client.config.Configuration;
|
||||
import com.sheepit.client.config.DirectoryManager;
|
||||
import com.sheepit.client.datamodel.client.Error;
|
||||
import com.sheepit.client.datamodel.client.Error.ServerCode;
|
||||
import com.sheepit.client.datamodel.client.Error.Type;
|
||||
import com.sheepit.client.datamodel.server.Chunk;
|
||||
import com.sheepit.client.exception.SheepItException;
|
||||
import com.sheepit.client.exception.SheepItExceptionNoRendererAvailable;
|
||||
import com.sheepit.client.exception.SheepItExceptionNoRightToRender;
|
||||
@@ -60,8 +63,17 @@ import com.sheepit.client.exception.SheepItExceptionSessionDisabled;
|
||||
import com.sheepit.client.exception.SheepItExceptionSessionDisabledDenoisingNotSupported;
|
||||
import com.sheepit.client.exception.SheepItExceptionWithRequiredWait;
|
||||
import com.sheepit.client.hardware.cpu.CPU;
|
||||
import com.sheepit.client.logger.Log;
|
||||
import com.sheepit.client.network.DownloadItem;
|
||||
import com.sheepit.client.network.DownloadManager;
|
||||
import com.sheepit.client.network.ServerRequest;
|
||||
import com.sheepit.client.os.OS;
|
||||
|
||||
import com.sheepit.client.rendering.IncompatibleProcessChecker;
|
||||
import com.sheepit.client.rendering.Job;
|
||||
import com.sheepit.client.ui.Gui;
|
||||
import com.sheepit.client.utils.Pair;
|
||||
import com.sheepit.client.utils.Utils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import okhttp3.HttpUrl;
|
||||
@@ -71,7 +83,7 @@ import okhttp3.HttpUrl;
|
||||
private static final Locale LOCALE = Locale.ENGLISH;
|
||||
private DirectoryManager directoryManager;
|
||||
private Gui gui;
|
||||
private Server server;
|
||||
private ServerRequest serverRequest;
|
||||
private Configuration configuration;
|
||||
private Log log;
|
||||
private Job renderingJob;
|
||||
@@ -93,7 +105,7 @@ import okhttp3.HttpUrl;
|
||||
|
||||
public Client(Gui gui, Configuration configuration, String url) {
|
||||
this.configuration = configuration;
|
||||
this.server = new Server(url, this.configuration, this);
|
||||
this.serverRequest = new ServerRequest(url, this.configuration, this);
|
||||
this.log = Log.getInstance();
|
||||
this.gui = gui;
|
||||
this.directoryManager = new DirectoryManager(this.configuration);
|
||||
@@ -116,7 +128,7 @@ import okhttp3.HttpUrl;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return String.format("Client (configuration %s, server %s)", this.configuration, this.server);
|
||||
return String.format("Client (configuration %s, server %s)", this.configuration, this.serverRequest);
|
||||
}
|
||||
|
||||
public int run() {
|
||||
@@ -138,7 +150,7 @@ import okhttp3.HttpUrl;
|
||||
this.gui.status("Starting");
|
||||
|
||||
Error.Type ret;
|
||||
ret = this.server.getConfiguration();
|
||||
ret = this.serverRequest.getConfiguration();
|
||||
|
||||
if (ret != Error.Type.OK) {
|
||||
this.gui.error(Error.humanString(ret));
|
||||
@@ -180,7 +192,7 @@ import okhttp3.HttpUrl;
|
||||
this.directoryManager.cleanWorkingDirectory();
|
||||
|
||||
this.startTime = new Date().getTime();
|
||||
this.server.start(); // for staying alive
|
||||
this.serverRequest.start(); // for staying alive
|
||||
|
||||
// create a thread which will send the frame
|
||||
Runnable runnableSender = this::senderLoop;
|
||||
@@ -229,7 +241,7 @@ import okhttp3.HttpUrl;
|
||||
}
|
||||
if (incompatibleProcessChecker.isRunningCompatibleProcess() == false) {
|
||||
this.gui.status("Requesting Job");
|
||||
this.renderingJob = this.server.requestJob();
|
||||
this.renderingJob = this.serverRequest.requestJob();
|
||||
}
|
||||
else {
|
||||
this.gui.status("Wait until compatible process is stopped");
|
||||
@@ -254,7 +266,7 @@ import okhttp3.HttpUrl;
|
||||
}
|
||||
catch (SheepItExceptionNoSession e) {
|
||||
this.log.debug("User has no session and needs to re-authenticate");
|
||||
ret = this.server.getConfiguration();
|
||||
ret = this.serverRequest.getConfiguration();
|
||||
if (ret != Error.Type.OK) {
|
||||
this.renderingJob = null;
|
||||
}
|
||||
@@ -276,7 +288,7 @@ import okhttp3.HttpUrl;
|
||||
}
|
||||
|
||||
this.gui.status("Requesting Job");
|
||||
this.renderingJob = this.server.requestJob();
|
||||
this.renderingJob = this.serverRequest.requestJob();
|
||||
}
|
||||
catch (SheepItException e1) {
|
||||
this.renderingJob = null;
|
||||
@@ -437,28 +449,28 @@ import okhttp3.HttpUrl;
|
||||
|
||||
this.directoryManager.removeWorkingDirectory();
|
||||
|
||||
if (this.server == null) {
|
||||
if (this.serverRequest == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (this.server.getPage("logout").isEmpty() == false) {
|
||||
if (this.serverRequest.getPage("logout").isEmpty() == false) {
|
||||
this.gui.status("Disconnecting from SheepIt server");
|
||||
|
||||
try {
|
||||
this.server.HTTPRequest(this.server.getPage("logout"));
|
||||
this.serverRequest.HTTPRequest(this.serverRequest.getPage("logout"));
|
||||
}
|
||||
catch (IOException ignored) {
|
||||
// nothing to do: if the logout failed that's ok
|
||||
}
|
||||
}
|
||||
this.server.interrupt();
|
||||
this.serverRequest.interrupt();
|
||||
try {
|
||||
this.server.join();
|
||||
this.serverRequest.join();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
this.server = null;
|
||||
this.serverRequest = null;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -630,7 +642,7 @@ import okhttp3.HttpUrl;
|
||||
}
|
||||
|
||||
writer.close();
|
||||
HttpUrl.Builder remoteURL = HttpUrl.parse(this.server.getPage("error")).newBuilder();
|
||||
HttpUrl.Builder remoteURL = HttpUrl.parse(this.serverRequest.getPage("error")).newBuilder();
|
||||
remoteURL.addQueryParameter("type", error == null ? "" : Integer.toString(error.getValue()));
|
||||
if (jobToReset != null) {
|
||||
remoteURL.addQueryParameter("frame", jobToReset.getRenderSettings().getFrameNumber());
|
||||
@@ -638,7 +650,7 @@ import okhttp3.HttpUrl;
|
||||
remoteURL.addQueryParameter("render_time", Integer.toString(jobToReset.getProcessRender().getRenderDuration()));
|
||||
remoteURL.addQueryParameter("memoryused", Long.toString(jobToReset.getProcessRender().getPeakMemoryUsed()));
|
||||
}
|
||||
this.server.HTTPSendFile(remoteURL.build().toString(), tempFile.getAbsolutePath(), step, this.gui);
|
||||
this.serverRequest.HTTPSendFile(remoteURL.build().toString(), tempFile.getAbsolutePath(), step, this.gui);
|
||||
tempFile.delete();
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -807,12 +819,12 @@ import okhttp3.HttpUrl;
|
||||
for (Chunk chunk : downloadInfos.getChunks()) {
|
||||
Callable<Type> downloadTask = () -> {
|
||||
DownloadManager downloadManager = new DownloadManager(
|
||||
this.server,
|
||||
this.serverRequest,
|
||||
this.gui,
|
||||
this.log,
|
||||
this.directoryManager.getActualStoragePathFor(chunk),
|
||||
chunk.getMd5(),
|
||||
String.format(LOCALE, "%s?chunk=%s", this.server.getPage("download-chunk"), chunk.getId())
|
||||
String.format(LOCALE, "%s?chunk=%s", this.serverRequest.getPage("download-chunk"), chunk.getId())
|
||||
);
|
||||
return downloadManager.download();
|
||||
};
|
||||
@@ -954,7 +966,7 @@ import okhttp3.HttpUrl;
|
||||
timeToSleep *= 2; // exponential backoff
|
||||
}
|
||||
|
||||
ret = this.server.HTTPSendFile(urlReal, ajob.getRenderOutput().getFullImagePath(), checkpoint, this.gui);
|
||||
ret = this.serverRequest.HTTPSendFile(urlReal, ajob.getRenderOutput().getFullImagePath(), checkpoint, this.gui);
|
||||
switch (ret) {
|
||||
case OK:
|
||||
// no issue, exit the loop
|
||||
|
||||
Reference in New Issue
Block a user