Fix tile-saving errors after reloading bluemap with sql storage

This commit is contained in:
Lukas Rieger (Blue) 2022-08-27 15:19:32 +02:00
parent 60a8f5f98e
commit 98780514c6
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
4 changed files with 31 additions and 0 deletions

View File

@ -84,6 +84,12 @@ public class LowresLayer {
private void saveTile(Vector2i tilePos, @Nullable LowresTile tile, RemovalCause removalCause) {
if (tile == null) return;
// check if storage is closed
if (mapStorage.getStorage().isClosed()){
Logger.global.logDebug("Tried to save tile " + tilePos + " (lod: " + lod + ") but storage is already closed.");
return;
}
// save the tile
try (OutputStream out = mapStorage.write(lod, tilePos)) {
tile.save(out);

View File

@ -59,6 +59,8 @@ public abstract class Storage implements Closeable {
return new TileStorage(mapId, lod);
}
public abstract boolean isClosed();
public class MapStorage {
private final String mapId;
@ -79,6 +81,10 @@ public abstract class Storage implements Closeable {
deleteMapTile(mapId, lod, tile);
}
public Storage getStorage() {
return Storage.this;
}
}
public class TileStorage {
@ -103,6 +109,10 @@ public abstract class Storage implements Closeable {
deleteMapTile(mapId, lod, tile);
}
public Storage getStorage() {
return Storage.this;
}
}
}

View File

@ -57,6 +57,11 @@ public class FileStorage extends Storage {
@Override
public void initialize() {}
@Override
public boolean isClosed() {
return false;
}
@Override
public void close() throws IOException {}

View File

@ -61,7 +61,11 @@ public class SQLStorage extends Storage {
.executor(BlueMap.THREAD_POOL)
.build(this::loadMapTileCompressionFK);
private volatile boolean closed;
public SQLStorage(SQLStorageSettings config) throws MalformedURLException, SQLDriverException {
this.closed = false;
try {
if (config.getDriverClass().isPresent()) {
if (config.getDriverJar().isPresent()) {
@ -478,8 +482,14 @@ public class SQLStorage extends Storage {
}
}
@Override
public boolean isClosed() {
return closed;
}
@Override
public void close() throws IOException {
this.closed = true;
if (dataSource instanceof AutoCloseable) {
try {
((AutoCloseable) dataSource).close();