mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2025-02-26 09:21:54 +01:00
Periodically save render-manager state for plugins so the render-thread continues after a crash
This commit is contained in:
parent
b7db58461f
commit
a7d46b4ee1
@ -69,6 +69,7 @@ public class Plugin {
|
||||
private RenderManager renderManager;
|
||||
private BlueMapWebServer webServer;
|
||||
|
||||
private Thread periodicalSaveThread;
|
||||
private Thread metricsThread;
|
||||
|
||||
private boolean loaded = false;
|
||||
@ -218,6 +219,23 @@ public synchronized void load() throws IOException, ParseResourceException {
|
||||
Logger.global.logError("Failed to load render-manager state!", ex);
|
||||
}
|
||||
|
||||
//create periodical-save thread
|
||||
periodicalSaveThread = new Thread(() -> {
|
||||
try {
|
||||
while (true) {
|
||||
Thread.sleep(TimeUnit.MINUTES.toMillis(5));
|
||||
try {
|
||||
saveRenderManagerState();
|
||||
} catch (IOException ex) {
|
||||
Logger.global.logError("Failed to save render-manager state!", ex);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException ex){
|
||||
return;
|
||||
}
|
||||
});
|
||||
periodicalSaveThread.start();
|
||||
|
||||
//start map updater
|
||||
this.updateHandler = new MapUpdateHandler();
|
||||
serverInterface.registerListener(updateHandler);
|
||||
@ -277,6 +295,9 @@ public synchronized void unload() {
|
||||
if (metricsThread != null) metricsThread.interrupt();
|
||||
metricsThread = null;
|
||||
|
||||
if (periodicalSaveThread != null) periodicalSaveThread.interrupt();
|
||||
periodicalSaveThread = null;
|
||||
|
||||
//stop services
|
||||
if (renderManager != null) renderManager.stop();
|
||||
if (webServer != null) webServer.close();
|
||||
@ -285,14 +306,7 @@ public synchronized void unload() {
|
||||
if (updateHandler != null) updateHandler.flushTileBuffer(); //first write all buffered tiles to the render manager to save them too
|
||||
if (renderManager != null) {
|
||||
try {
|
||||
File saveFile = config.getDataPath().resolve("rmstate").toFile();
|
||||
saveFile.getParentFile().mkdirs();
|
||||
if (saveFile.exists()) saveFile.delete();
|
||||
saveFile.createNewFile();
|
||||
|
||||
try (DataOutputStream out = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(saveFile)))) {
|
||||
renderManager.writeState(out);
|
||||
}
|
||||
saveRenderManagerState();
|
||||
} catch (IOException ex) {
|
||||
Logger.global.logError("Failed to save render-manager state!", ex);
|
||||
}
|
||||
@ -314,6 +328,17 @@ public synchronized void unload() {
|
||||
|
||||
loaded = false;
|
||||
}
|
||||
|
||||
public void saveRenderManagerState() throws IOException {
|
||||
File saveFile = config.getDataPath().resolve("rmstate").toFile();
|
||||
saveFile.getParentFile().mkdirs();
|
||||
if (saveFile.exists()) saveFile.delete();
|
||||
saveFile.createNewFile();
|
||||
|
||||
try (DataOutputStream out = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(saveFile)))) {
|
||||
renderManager.writeState(out);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void reload() throws IOException, ParseResourceException {
|
||||
unload();
|
||||
|
Loading…
Reference in New Issue
Block a user