mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-30 16:19:56 +08:00
[#935] Made GenerateAnalysisPageRequest run analysis async
This commit is contained in:
parent
ad2208d7ff
commit
c9c696e71d
@ -20,7 +20,9 @@ import com.djrapitops.plan.api.exceptions.connection.BadRequestException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.InternalErrorException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
||||
@ -29,6 +31,7 @@ import com.djrapitops.plugin.utilities.Verify;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* InfoRequest to generate Analysis page HTML at the receiving end.
|
||||
@ -37,20 +40,26 @@ import java.util.UUID;
|
||||
*/
|
||||
public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implements GenerateRequest {
|
||||
|
||||
private final Processing processing;
|
||||
private final WebExceptionLogger webExceptionLogger;
|
||||
private final InfoRequestFactory infoRequestFactory;
|
||||
private final ServerInfo serverInfo;
|
||||
private final InfoSystem infoSystem;
|
||||
private final PageFactory pageFactory;
|
||||
|
||||
private boolean runningAnalysis = false;
|
||||
private AtomicBoolean runningAnalysis = new AtomicBoolean(false);
|
||||
private UUID serverUUID;
|
||||
|
||||
GenerateAnalysisPageRequest(
|
||||
Processing processing,
|
||||
WebExceptionLogger webExceptionLogger,
|
||||
InfoRequestFactory infoRequestFactory,
|
||||
ServerInfo serverInfo,
|
||||
InfoSystem infoSystem,
|
||||
PageFactory pageFactory
|
||||
) {
|
||||
this.processing = processing;
|
||||
this.webExceptionLogger = webExceptionLogger;
|
||||
this.infoRequestFactory = infoRequestFactory;
|
||||
this.serverInfo = serverInfo;
|
||||
this.infoSystem = infoSystem;
|
||||
@ -59,11 +68,15 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implem
|
||||
|
||||
GenerateAnalysisPageRequest(
|
||||
UUID serverUUID,
|
||||
Processing processing,
|
||||
WebExceptionLogger webExceptionLogger,
|
||||
InfoRequestFactory infoRequestFactory,
|
||||
ServerInfo serverInfo,
|
||||
InfoSystem infoSystem,
|
||||
PageFactory pageFactory
|
||||
) {
|
||||
this.processing = processing;
|
||||
this.webExceptionLogger = webExceptionLogger;
|
||||
this.infoRequestFactory = infoRequestFactory;
|
||||
this.serverInfo = serverInfo;
|
||||
this.infoSystem = infoSystem;
|
||||
@ -86,8 +99,11 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implem
|
||||
throw new BadRequestException("Requested Analysis page from wrong server.");
|
||||
}
|
||||
|
||||
if (!runningAnalysis) {
|
||||
generateAndCache(serverUUID);
|
||||
if (!runningAnalysis.get()) {
|
||||
runningAnalysis.set(true);
|
||||
processing.submitNonCritical(() ->
|
||||
webExceptionLogger.logIfOccurs(GenerateAnalysisPageRequest.class, () -> generateAndCache(serverUUID))
|
||||
);
|
||||
}
|
||||
|
||||
return DefaultResponses.SUCCESS.get();
|
||||
@ -108,13 +124,12 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implem
|
||||
|
||||
private String analyseAndGetHtml() throws InternalErrorException {
|
||||
try {
|
||||
runningAnalysis = true;
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
return pageFactory.analysisPage(serverUUID).toHtml();
|
||||
} catch (Exception e) {
|
||||
throw new InternalErrorException("Analysis failed due to exception", e);
|
||||
} finally {
|
||||
runningAnalysis = false;
|
||||
runningAnalysis.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import com.djrapitops.plan.system.export.HtmlExport;
|
||||
import com.djrapitops.plan.system.export.JSONExport;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
@ -47,6 +48,7 @@ public class InfoRequestFactory {
|
||||
private final Lazy<Processing> processing;
|
||||
private final Lazy<InfoSystem> infoSystem;
|
||||
private final Lazy<ConnectionSystem> connectionSystem;
|
||||
private final Lazy<WebExceptionLogger> webExceptionLogger;
|
||||
private final Lazy<ServerInfo> serverInfo;
|
||||
private final Lazy<ResponseFactory> responseFactory;
|
||||
private final Lazy<PageFactory> pageFactory;
|
||||
@ -62,6 +64,7 @@ public class InfoRequestFactory {
|
||||
Lazy<Processing> processing,
|
||||
Lazy<InfoSystem> infoSystem,
|
||||
Lazy<ConnectionSystem> connectionSystem,
|
||||
Lazy<WebExceptionLogger> webExceptionLogger,
|
||||
Lazy<ServerInfo> serverInfo,
|
||||
Lazy<ResponseFactory> responseFactory,
|
||||
Lazy<PageFactory> pageFactory,
|
||||
@ -75,6 +78,7 @@ public class InfoRequestFactory {
|
||||
this.processing = processing;
|
||||
this.infoSystem = infoSystem;
|
||||
this.connectionSystem = connectionSystem;
|
||||
this.webExceptionLogger = webExceptionLogger;
|
||||
this.serverInfo = serverInfo;
|
||||
this.responseFactory = responseFactory;
|
||||
this.pageFactory = pageFactory;
|
||||
@ -107,7 +111,7 @@ public class InfoRequestFactory {
|
||||
}
|
||||
|
||||
public GenerateRequest generateAnalysisPageRequest(UUID serverUUID) {
|
||||
return new GenerateAnalysisPageRequest(serverUUID, this, serverInfo.get(), infoSystem.get(), pageFactory.get());
|
||||
return new GenerateAnalysisPageRequest(serverUUID, processing.get(), webExceptionLogger.get(), this, serverInfo.get(), infoSystem.get(), pageFactory.get());
|
||||
}
|
||||
|
||||
public GenerateRequest generateInspectPageRequest(UUID uuid) {
|
||||
@ -170,6 +174,8 @@ public class InfoRequestFactory {
|
||||
|
||||
GenerateRequest generateAnalysisPageRequest() {
|
||||
return new GenerateAnalysisPageRequest(
|
||||
factory.processing.get(),
|
||||
factory.webExceptionLogger.get(),
|
||||
factory,
|
||||
factory.serverInfo.get(),
|
||||
factory.infoSystem.get(),
|
||||
|
Loading…
Reference in New Issue
Block a user