From d687ec892ab55cb2245bdb666f0758f7dfe2e504 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 11 Mar 2023 09:50:33 -0600 Subject: [PATCH] refactoring/renaming --- .../core/file/fullDatafile/FullDataMetaFile.java | 6 +++--- .../metaData/AbstractMetaDataContainerFile.java | 16 +++++++++------- .../lod/core/generation/BatchGenerator.java | 5 ++--- .../lod/core/world/DhClientServerWorld.java | 6 +++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/com/seibel/lod/core/file/fullDatafile/FullDataMetaFile.java b/core/src/main/java/com/seibel/lod/core/file/fullDatafile/FullDataMetaFile.java index 3ef85a6a4..0b75d2bc8 100644 --- a/core/src/main/java/com/seibel/lod/core/file/fullDatafile/FullDataMetaFile.java +++ b/core/src/main/java/com/seibel/lod/core/file/fullDatafile/FullDataMetaFile.java @@ -141,10 +141,10 @@ public class FullDataMetaFile extends AbstractMetaDataContainerFile // } // } - public void addToWriteQueue(ChunkSizedFullDataSource datatype) + public void addToWriteQueue(ChunkSizedFullDataSource chunkDataSource) { debugCheck(); - DhLodPos chunkPos = new DhLodPos((byte) (datatype.dataDetail + 4), datatype.x, datatype.z); + DhLodPos chunkPos = new DhLodPos((byte) (chunkDataSource.dataDetail + 4), chunkDataSource.x, chunkDataSource.z); LodUtil.assertTrue(pos.getSectionBBoxPos().overlaps(chunkPos), "Chunk pos "+chunkPos+" doesn't overlap with section "+pos); //LOGGER.info("Write Chunk {} to file {}", chunkPos, pos); @@ -156,7 +156,7 @@ public class FullDataMetaFile extends AbstractMetaDataContainerFile appendLock.lock(); try { - writeQueue.queue.add(datatype); + writeQueue.queue.add(chunkDataSource); } finally { diff --git a/core/src/main/java/com/seibel/lod/core/file/metaData/AbstractMetaDataContainerFile.java b/core/src/main/java/com/seibel/lod/core/file/metaData/AbstractMetaDataContainerFile.java index 95a4f1365..61b376bd9 100644 --- a/core/src/main/java/com/seibel/lod/core/file/metaData/AbstractMetaDataContainerFile.java +++ b/core/src/main/java/com/seibel/lod/core/file/metaData/AbstractMetaDataContainerFile.java @@ -59,7 +59,9 @@ public abstract class AbstractMetaDataContainerFile /** * James tested this on windows (2023-02-18) and didn't have any issues, * so it will be turned on for now. If there turns out to be issues - * we can always + * we can always turn it off.

+ * + * original comment:
* Currently set to false because for some reason * Window is throwing PermissionDeniedException when trying to atomic replace a file... */ @@ -201,12 +203,12 @@ public abstract class AbstractMetaDataContainerFile tempFile = this.file; } - try (FileChannel file = FileChannel.open(tempFile.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) + try (FileChannel fileChannel = FileChannel.open(tempFile.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { - file.position(METADATA_SIZE_IN_BYTES); + fileChannel.position(METADATA_SIZE_IN_BYTES); int checksum; - try(DhUnclosableOutputStream bufferedOut = new DhUnclosableOutputStream(Channels.newOutputStream(file)); // Prevent closing the channel by anything but closing the file channel + try(DhUnclosableOutputStream bufferedOut = new DhUnclosableOutputStream(Channels.newOutputStream(fileChannel)); // Prevent closing the channel by anything but closing the file channel CheckedOutputStream checkedOut = new CheckedOutputStream(bufferedOut, new Adler32())) // TODO: Is Adler32 ok? { dataWriterFunc.writeBufferToFile(bufferedOut); // TODO it might be nice to have a DH stream we pass in instead of the base BufferedOutputStream to make it clear the streams can't be closed @@ -214,7 +216,7 @@ public abstract class AbstractMetaDataContainerFile } - file.position(0); + fileChannel.position(0); // Write metadata ByteBuffer buffer = ByteBuffer.allocate(METADATA_SIZE_IN_BYTES); buffer.putInt(METADATA_IDENTITY_BYTES); @@ -230,10 +232,10 @@ public abstract class AbstractMetaDataContainerFile buffer.putLong(Long.MAX_VALUE); //buff.putLong(this.metaData.dataVersion.get()); // not currently implemented LodUtil.assertTrue(buffer.remaining() == METADATA_RESERVED_SIZE); buffer.flip(); - file.write(buffer); + fileChannel.write(buffer); - file.close(); + fileChannel.close(); if (USE_ATOMIC_MOVE_REPLACE) { // Atomic move / replace the actual file diff --git a/core/src/main/java/com/seibel/lod/core/generation/BatchGenerator.java b/core/src/main/java/com/seibel/lod/core/generation/BatchGenerator.java index 7bf3d5a48..ac3b64645 100644 --- a/core/src/main/java/com/seibel/lod/core/generation/BatchGenerator.java +++ b/core/src/main/java/com/seibel/lod/core/generation/BatchGenerator.java @@ -146,11 +146,10 @@ public class BatchGenerator implements IDhApiWorldGenerator //=========// @Override - public void close() { this.stop(true); } - public void stop(boolean blocking) + public void close() { LOGGER.info(BatchGenerator.class.getSimpleName()+" shutting down..."); - this.generationGroup.stop(blocking); + this.generationGroup.stop(true); } diff --git a/core/src/main/java/com/seibel/lod/core/world/DhClientServerWorld.java b/core/src/main/java/com/seibel/lod/core/world/DhClientServerWorld.java index 80f30ab42..a734cb0f6 100644 --- a/core/src/main/java/com/seibel/lod/core/world/DhClientServerWorld.java +++ b/core/src/main/java/com/seibel/lod/core/world/DhClientServerWorld.java @@ -94,9 +94,9 @@ public class DhClientServerWorld extends AbstractDhWorld implements IDhClientWor if (wrapper instanceof IServerLevelWrapper) { LOGGER.info("Unloading level "+this.levelObjMap.get(wrapper)); - DhClientServerLevel level = this.levelObjMap.remove(wrapper); - this.dhLevels.remove(level); - level.close(); + DhClientServerLevel clientServerLevel = this.levelObjMap.remove(wrapper); + clientServerLevel.saveAsync().join(); + clientServerLevel.close(); } else {