rename/refactor FullDataSource loaders

This commit is contained in:
James Seibel
2023-02-18 09:45:56 -06:00
parent 271bdb9f12
commit 3b621ac497
6 changed files with 46 additions and 40 deletions
@@ -4,7 +4,7 @@ import com.seibel.lod.core.api.external.methods.config.DhApiConfig;
import com.seibel.lod.core.api.external.methods.data.DhApiTerrainDataRepo;
import com.seibel.lod.core.datatype.column.ColumnRenderLoader;
import com.seibel.lod.core.datatype.full.FullDataLoader;
import com.seibel.lod.core.datatype.full.SparseDataLoader;
import com.seibel.lod.core.datatype.full.SparseFullDataLoader;
import com.seibel.lod.api.DhApiMain;
import com.seibel.lod.core.datatype.full.SingleChunkFullDataLoader;
import com.seibel.lod.core.render.DhApiRenderProxy;
@@ -22,7 +22,7 @@ public class Initializer
{
ColumnRenderLoader unused = new ColumnRenderLoader(); // Auto register into the loader system
FullDataLoader unused2 = new FullDataLoader(); // Auto register into the loader system
SparseDataLoader unused3 = new SparseDataLoader(); // Auto register
SparseFullDataLoader unused3 = new SparseFullDataLoader(); // Auto register
SingleChunkFullDataLoader unused4 = new SingleChunkFullDataLoader(); // Auto register
// link Core's config to the API
@@ -8,31 +8,19 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public abstract class AbstractDataSourceLoader
public abstract class AbstractFullDataSourceLoader
{
public static final HashMultimap<Class<? extends IFullDataSource>, AbstractDataSourceLoader> loaderRegistry = HashMultimap.create();
public static final HashMultimap<Class<? extends IFullDataSource>, AbstractFullDataSourceLoader> loaderRegistry = HashMultimap.create();
public final Class<? extends IFullDataSource> clazz;
public static final HashMap<Long, Class<? extends IFullDataSource>> datatypeIdRegistry = new HashMap<>();
public static AbstractDataSourceLoader getLoader(long dataTypeId, byte dataVersion)
{
return loaderRegistry.get(datatypeIdRegistry.get(dataTypeId)).stream()
.filter(l -> Arrays.binarySearch(l.loaderSupportedVersions, dataVersion) >= 0)
.findFirst().orElse(null);
}
public static AbstractDataSourceLoader getLoader(Class<? extends IFullDataSource> clazz, byte dataVersion)
{
return loaderRegistry.get(clazz).stream()
.filter(l -> Arrays.binarySearch(l.loaderSupportedVersions, dataVersion) >= 0)
.findFirst().orElse(null);
}
public final long datatypeId;
public final byte[] loaderSupportedVersions;
public AbstractDataSourceLoader(Class<? extends IFullDataSource> clazz, long datatypeId, byte[] loaderSupportedVersions)
public AbstractFullDataSourceLoader(Class<? extends IFullDataSource> clazz, long datatypeId, byte[] loaderSupportedVersions)
{
this.datatypeId = datatypeId;
this.loaderSupportedVersions = loaderSupportedVersions;
@@ -43,16 +31,19 @@ public abstract class AbstractDataSourceLoader
throw new IllegalArgumentException("Loader for datatypeId " + datatypeId + " already registered with different class: "
+ datatypeIdRegistry.get(datatypeId) + " != " + clazz);
}
Set<AbstractDataSourceLoader> loaders = loaderRegistry.get(clazz);
if (loaders.stream().anyMatch(other -> {
// see if any loaderSupportsVersion conflicts with this one
for (byte otherVer : other.loaderSupportedVersions)
Set<AbstractFullDataSourceLoader> loaders = loaderRegistry.get(clazz);
if (loaders.stream().anyMatch(other ->
{
if (Arrays.binarySearch(loaderSupportedVersions, otherVer) >= 0)
return true;
}
return false;
}))
// see if any loaderSupportsVersion conflicts with this one
for (byte otherVer : other.loaderSupportedVersions)
{
if (Arrays.binarySearch(loaderSupportedVersions, otherVer) >= 0)
{
return true;
}
}
return false;
}))
{
throw new IllegalArgumentException("Loader for class " + clazz + " that supports one of the version in "
+ Arrays.toString(loaderSupportedVersions) + " already registered!");
@@ -65,4 +56,19 @@ public abstract class AbstractDataSourceLoader
public abstract IFullDataSource loadData(FullDataMetaFile dataFile, InputStream data, IDhLevel level) throws IOException;
public static AbstractFullDataSourceLoader getLoader(long dataTypeId, byte dataVersion)
{
return loaderRegistry.get(datatypeIdRegistry.get(dataTypeId)).stream()
.filter(l -> Arrays.binarySearch(l.loaderSupportedVersions, dataVersion) >= 0)
.findFirst().orElse(null);
}
public static AbstractFullDataSourceLoader getLoader(Class<? extends IFullDataSource> clazz, byte dataVersion)
{
return loaderRegistry.get(clazz).stream()
.filter(loader -> Arrays.binarySearch(loader.loaderSupportedVersions, dataVersion) >= 0)
.findFirst().orElse(null);
}
}
@@ -1,6 +1,6 @@
package com.seibel.lod.core.datatype.full;
import com.seibel.lod.core.datatype.AbstractDataSourceLoader;
import com.seibel.lod.core.datatype.AbstractFullDataSourceLoader;
import com.seibel.lod.core.datatype.IFullDataSource;
import com.seibel.lod.core.datatype.full.sources.FullDataSource;
import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile;
@@ -9,7 +9,7 @@ import com.seibel.lod.core.level.IDhLevel;
import java.io.IOException;
import java.io.InputStream;
public class FullDataLoader extends AbstractDataSourceLoader
public class FullDataLoader extends AbstractFullDataSourceLoader
{
public FullDataLoader()
{
@@ -1,6 +1,6 @@
package com.seibel.lod.core.datatype.full;
import com.seibel.lod.core.datatype.AbstractDataSourceLoader;
import com.seibel.lod.core.datatype.AbstractFullDataSourceLoader;
import com.seibel.lod.core.datatype.IFullDataSource;
import com.seibel.lod.core.datatype.full.sources.SingleChunkFullDataSource;
import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile;
@@ -9,7 +9,7 @@ import com.seibel.lod.core.level.IDhLevel;
import java.io.IOException;
import java.io.InputStream;
public class SingleChunkFullDataLoader extends AbstractDataSourceLoader
public class SingleChunkFullDataLoader extends AbstractFullDataSourceLoader
{
public SingleChunkFullDataLoader() {
super(SingleChunkFullDataSource.class, SingleChunkFullDataSource.TYPE_ID, new byte[]{ SingleChunkFullDataSource.LATEST_VERSION});
@@ -1,6 +1,6 @@
package com.seibel.lod.core.datatype.full;
import com.seibel.lod.core.datatype.AbstractDataSourceLoader;
import com.seibel.lod.core.datatype.AbstractFullDataSourceLoader;
import com.seibel.lod.core.datatype.IFullDataSource;
import com.seibel.lod.core.datatype.full.sources.SparseFullDataSource;
import com.seibel.lod.core.file.fullDatafile.FullDataMetaFile;
@@ -9,9 +9,9 @@ import com.seibel.lod.core.level.IDhLevel;
import java.io.IOException;
import java.io.InputStream;
public class SparseDataLoader extends AbstractDataSourceLoader
public class SparseFullDataLoader extends AbstractFullDataSourceLoader
{
public SparseDataLoader()
public SparseFullDataLoader()
{
super(SparseFullDataSource.class, SparseFullDataSource.TYPE_ID, new byte[] { SparseFullDataSource.LATEST_VERSION });
}
@@ -9,7 +9,7 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import com.seibel.lod.core.datatype.IFullDataSource;
import com.seibel.lod.core.datatype.AbstractDataSourceLoader;
import com.seibel.lod.core.datatype.AbstractFullDataSourceLoader;
import com.seibel.lod.core.datatype.full.sources.ChunkSizedFullDataSource;
import com.seibel.lod.core.dependencyInjection.SingletonInjector;
import com.seibel.lod.core.file.metaData.MetaData;
@@ -35,7 +35,7 @@ public class FullDataMetaFile extends AbstractMetaDataFile
private final IFullDataSourceProvider handler;
private boolean doesFileExist;
public AbstractDataSourceLoader loader;
public AbstractFullDataSourceLoader loader;
public Class<? extends IFullDataSource> dataType;
// The '?' type should either be:
// SoftReference<LodDataSource>, or - Non-dirty file that can be GCed
@@ -96,7 +96,7 @@ public class FullDataMetaFile extends AbstractMetaDataFile
this.handler = handler;
this.level = level;
LodUtil.assertTrue(metaData != null);
loader = AbstractDataSourceLoader.getLoader(metaData.dataTypeId, metaData.loaderVersion);
loader = AbstractFullDataSourceLoader.getLoader(metaData.dataTypeId, metaData.loaderVersion);
if (loader == null) {
throw new IOException("Invalid file: Data type loader not found: "
+ metaData.dataTypeId + "(v" + metaData.loaderVersion + ")");
@@ -258,7 +258,7 @@ public class FullDataMetaFile extends AbstractMetaDataFile
}
private static MetaData makeMetaData(IFullDataSource data) {
AbstractDataSourceLoader loader = AbstractDataSourceLoader.getLoader(data.getClass(), data.getDataVersion());
AbstractFullDataSourceLoader loader = AbstractFullDataSourceLoader.getLoader(data.getClass(), data.getDataVersion());
return new MetaData(data.getSectionPos(), -1,
data.getDataDetail(), loader == null ? 0 : loader.datatypeId, data.getDataVersion());
}
@@ -351,7 +351,7 @@ public class FullDataMetaFile extends AbstractMetaDataFile
// Write/Update data
LodUtil.assertTrue(metaData != null);
metaData.dataLevel = data.getDataDetail();
loader = AbstractDataSourceLoader.getLoader(data.getClass(), data.getDataVersion());
loader = AbstractFullDataSourceLoader.getLoader(data.getClass(), data.getDataVersion());
LodUtil.assertTrue(loader != null, "No loader for {} (v{})", data.getClass(), data.getDataVersion());
dataType = data.getClass();
metaData.dataTypeId = loader == null ? 0 : loader.datatypeId;