Fixed ExportPaths concurrency issue with Network exporter

This commit is contained in:
Risto Lahtela 2020-03-26 11:53:33 +02:00
parent 0f8d39d6a2
commit 99885d2381
3 changed files with 20 additions and 20 deletions

View File

@ -123,8 +123,11 @@ public class ManageExportCommand extends CommandNode {
processing.submitNonCritical(() -> { processing.submitNonCritical(() -> {
try { try {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START)); sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
exporter.exportServerJSON(serverInfo.getServer()); if (exporter.exportServerJSON(serverInfo.getServer())) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
} else {
sender.sendMessage(locale.get(ManageLang.PROGRESS_FAIL).toString("see '" + ExportSettings.SERVER_JSON.getPath() + "' in config.yml"));
}
} catch (ExportException e) { } catch (ExportException e) {
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL)); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL));
sender.sendMessage("§c" + e.toString()); sender.sendMessage("§c" + e.toString());

View File

@ -98,7 +98,7 @@ public class Exporter extends FileExporter {
try { try {
Path toDirectory = config.getJSONExportPath().resolve(toFileName(server.getName())); Path toDirectory = config.getJSONExportPath().resolve(toFileName(server.getName()));
if (server.isProxy()) { if (server.isProxy()) {
networkPageExporter.exportJSON(toDirectory, server); networkPageExporter.exportJSON(new ExportPaths(), toDirectory, server);
} else { } else {
serverPageExporter.exportJSON(toDirectory, server); serverPageExporter.exportJSON(toDirectory, server);
} }

View File

@ -54,8 +54,6 @@ public class NetworkPageExporter extends FileExporter {
private final RootJSONResolver jsonHandler; private final RootJSONResolver jsonHandler;
private final Theme theme; private final Theme theme;
private final ExportPaths exportPaths;
@Inject @Inject
public NetworkPageExporter( public NetworkPageExporter(
PlanFiles files, PlanFiles files,
@ -69,8 +67,6 @@ public class NetworkPageExporter extends FileExporter {
this.pageFactory = pageFactory; this.pageFactory = pageFactory;
this.jsonHandler = jsonHandler; this.jsonHandler = jsonHandler;
this.theme = theme; this.theme = theme;
exportPaths = new ExportPaths();
} }
/** /**
@ -85,14 +81,14 @@ public class NetworkPageExporter extends FileExporter {
Database.State dbState = dbSystem.getDatabase().getState(); Database.State dbState = dbSystem.getDatabase().getState();
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return; if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
ExportPaths exportPaths = new ExportPaths();
exportPaths.put("./players", toRelativePathFromRoot("players")); exportPaths.put("./players", toRelativePathFromRoot("players"));
exportRequiredResources(toDirectory); exportRequiredResources(exportPaths, toDirectory);
exportJSON(toDirectory, server); exportJSON(exportPaths, toDirectory, server);
exportHtml(toDirectory); exportHtml(exportPaths, toDirectory);
exportPaths.clear();
} }
private void exportHtml(Path toDirectory) throws IOException { private void exportHtml(ExportPaths exportPaths, Path toDirectory) throws IOException {
Path to = toDirectory Path to = toDirectory
.resolve("network") .resolve("network")
.resolve("index.html"); .resolve("index.html");
@ -104,15 +100,16 @@ public class NetworkPageExporter extends FileExporter {
/** /**
* Perform export for a network page json payload. * Perform export for a network page json payload.
* *
* @param exportPaths
* @param toDirectory Path to Export directory * @param toDirectory Path to Export directory
* @param server Server to export as Network page, {@link Server#isProxy()} assumed true. * @param server Server to export as Network page, {@link Server#isProxy()} assumed true.
* @throws IOException If a template can not be read from jar/disk or the result written * @throws IOException If a template can not be read from jar/disk or the result written
* @throws NotFoundException If a file or resource that is being exported can not be found * @throws NotFoundException If a file or resource that is being exported can not be found
*/ */
public void exportJSON(Path toDirectory, Server server) throws IOException { public void exportJSON(ExportPaths exportPaths, Path toDirectory, Server server) throws IOException {
String serverUUID = server.getUuid().toString(); String serverUUID = server.getUuid().toString();
exportJSON(toDirectory, exportJSON(exportPaths, toDirectory,
"network/overview", "network/overview",
"network/servers", "network/servers",
"network/sessionsOverview", "network/sessionsOverview",
@ -128,13 +125,13 @@ public class NetworkPageExporter extends FileExporter {
); );
} }
private void exportJSON(Path toDirectory, String... resources) throws IOException { private void exportJSON(ExportPaths exportPaths, Path toDirectory, String... resources) throws IOException {
for (String resource : resources) { for (String resource : resources) {
exportJSON(toDirectory, resource); exportJSON(exportPaths, toDirectory, resource);
} }
} }
private void exportJSON(Path toDirectory, String resource) throws IOException { private void exportJSON(ExportPaths exportPaths, Path toDirectory, String resource) throws IOException {
Optional<Response> found = getJSONResponse(resource); Optional<Response> found = getJSONResponse(resource);
if (!found.isPresent()) { if (!found.isPresent()) {
throw new NotFoundException(resource + " was not properly exported: not found"); throw new NotFoundException(resource + " was not properly exported: not found");
@ -166,8 +163,8 @@ public class NetworkPageExporter extends FileExporter {
} }
} }
private void exportRequiredResources(Path toDirectory) throws IOException { private void exportRequiredResources(ExportPaths exportPaths, Path toDirectory) throws IOException {
exportResources(toDirectory, exportResources(exportPaths, toDirectory,
"./img/Flaticon_circle.png", "./img/Flaticon_circle.png",
"./css/sb-admin-2.css", "./css/sb-admin-2.css",
"./css/style.css", "./css/style.css",
@ -205,7 +202,7 @@ public class NetworkPageExporter extends FileExporter {
); );
} }
private void exportResources(Path toDirectory, String... resourceNames) throws IOException { private void exportResources(ExportPaths exportPaths, Path toDirectory, String... resourceNames) throws IOException {
for (String resourceName : resourceNames) { for (String resourceName : resourceNames) {
String nonRelativePath = toNonRelativePath(resourceName); String nonRelativePath = toNonRelativePath(resourceName);
exportResource(toDirectory, nonRelativePath); exportResource(toDirectory, nonRelativePath);