From e48e7fbf7a48f4bde14bb204c86860ad68d04fa4 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 8 Apr 2023 15:59:32 -0500 Subject: [PATCH] minor refactoring --- .../core/file/fullDatafile/FullDataMetaFile.java | 2 +- .../core/file/renderfile/RenderMetaDataFile.java | 12 ++++++------ .../file/renderfile/RenderSourceFileHandler.java | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 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 f73538a82..b84228e8a 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 @@ -42,7 +42,7 @@ public class FullDataMetaFile extends AbstractMetaDataContainerFile // SoftReference, or - Non-dirty file that can be GCed // CompletableFuture, or - File that is being loaded. No guarantee that the type is promotable or not // null - Nothing is loaded or being loaded - AtomicReference data = new AtomicReference(null); + AtomicReference data = new AtomicReference<>(null); //TODO: use ConcurrentAppendSingleSwapContainer instead of below: private static class GuardedMultiAppendQueue { diff --git a/core/src/main/java/com/seibel/lod/core/file/renderfile/RenderMetaDataFile.java b/core/src/main/java/com/seibel/lod/core/file/renderfile/RenderMetaDataFile.java index 7cb3c162e..2b0484a9d 100644 --- a/core/src/main/java/com/seibel/lod/core/file/renderfile/RenderMetaDataFile.java +++ b/core/src/main/java/com/seibel/lod/core/file/renderfile/RenderMetaDataFile.java @@ -134,28 +134,28 @@ public class RenderMetaDataFile extends AbstractMetaDataContainerFile public CompletableFuture loadOrGetCached(Executor fileReaderThreads, IDhLevel level) { Object obj = this.data.get(); - + CompletableFuture cached = this._readCached(obj); if (cached != null) { return cached; } - + // Create an empty and non-completed future. // Note: I do this before actually filling in the future so that I can ensure only // one task is submitted to the thread pool. CompletableFuture loadRenderSourceFuture = new CompletableFuture<>(); - + // Would use faster and non-nesting Compare and exchange. But java 8 doesn't have it! :( boolean worked = this.data.compareAndSet(obj, loadRenderSourceFuture); if (!worked) { return this.loadOrGetCached(fileReaderThreads, level); } - + // Now, there should only ever be one thread at a time here due to the CAS operation above. - - + + // After cas. We are in exclusive control. if (!this.doesFileExist) { diff --git a/core/src/main/java/com/seibel/lod/core/file/renderfile/RenderSourceFileHandler.java b/core/src/main/java/com/seibel/lod/core/file/renderfile/RenderSourceFileHandler.java index 06988561e..ec139c4ce 100644 --- a/core/src/main/java/com/seibel/lod/core/file/renderfile/RenderSourceFileHandler.java +++ b/core/src/main/java/com/seibel/lod/core/file/renderfile/RenderSourceFileHandler.java @@ -324,6 +324,14 @@ public class RenderSourceFileHandler implements ILodRenderSourceProvider return renderSource; } + public void onReadRenderSourceFromCache(RenderMetaDataFile file, ColumnRenderSource data) + { +// if (!this.fullDataSourceProvider.isCacheVersionValid(file.pos, file.metaData.dataVersion.get())) +// { + this.updateCache(data, file); +// } + } + private void write(ColumnRenderSource currentRenderSource, RenderMetaDataFile file, ColumnRenderSource newRenderSource) { @@ -341,14 +349,6 @@ public class RenderSourceFileHandler implements ILodRenderSourceProvider file.save(currentRenderSource); } - public void onReadRenderSourceFromCache(RenderMetaDataFile file, ColumnRenderSource data) - { -// if (!this.fullDataSourceProvider.isCacheVersionValid(file.pos, file.metaData.dataVersion.get())) -// { - this.updateCache(data, file); -// } - } - public boolean refreshRenderSource(ColumnRenderSource renderSource) { RenderMetaDataFile file = this.filesBySectionPos.get(renderSource.getSectionPos());