Clean up data source getters

This commit is contained in:
James Seibel
2025-11-06 07:42:58 -06:00
parent 5fd8ed840f
commit 9343854b4a
10 changed files with 29 additions and 61 deletions
@@ -238,7 +238,7 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
if (dataSource == null)
{
// attempt to get/generate the data source for this section
dataSource = level.getFullDataProvider().getAsync(sectionPos, false).get();
dataSource = level.getFullDataProvider().getAsync(sectionPos).get();
if (dataSource == null)
{
return DhApiResult.createFail("Unable to find/generate any data at the " + DhSectionPos.class.getSimpleName() + " [" + DhSectionPos.toString(sectionPos) + "].");
@@ -489,7 +489,7 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im
@Override
public CompletableFuture<Boolean> shouldGenerateSplitChild(long pos)
{
return GeneratedFullDataSourceProvider.this.getAsync(pos, false).thenApply(fullDataSource ->
return GeneratedFullDataSourceProvider.this.getAsync(pos).thenApply(fullDataSource ->
{
//noinspection TryFinallyCanBeTryWithResources
try
@@ -75,18 +75,18 @@ public class RemoteFullDataSourceProvider extends GeneratedFullDataSourceProvide
@Override
@Nullable
public FullDataSourceV2 get(long pos, boolean includeAdjacentData)
public FullDataSourceV2 get(long pos)
{
if (this.syncOnLoadRequestQueue == null)
{
// we have local data, but networking is unavailable.
return super.get(pos, includeAdjacentData);
return super.get(pos);
}
if (!this.visitedPositions.add(pos))
{
// This position has already been accessed before
return super.get(pos, includeAdjacentData);
return super.get(pos);
}
@@ -105,7 +105,7 @@ public class RemoteFullDataSourceProvider extends GeneratedFullDataSourceProvide
});
}
return super.get(pos, includeAdjacentData);
return super.get(pos);
}
@@ -171,7 +171,7 @@ public class FullDataSourceProviderV2 implements IDebugRenderable, AutoCloseable
*
* This call is concurrent. I.e. it supports being called by multiple threads at the same time.
*/
public CompletableFuture<FullDataSourceV2> getAsync(long pos, boolean includeAdjacentData)
public CompletableFuture<FullDataSourceV2> getAsync(long pos)
{
AbstractExecutorService executor = ThreadPoolUtil.getFileHandlerExecutor();
if (executor == null || executor.isTerminated())
@@ -182,7 +182,7 @@ public class FullDataSourceProviderV2 implements IDebugRenderable, AutoCloseable
try
{
return CompletableFuture.supplyAsync(() -> this.get(pos, includeAdjacentData), executor);
return CompletableFuture.supplyAsync(() -> this.get(pos), executor);
}
catch (RejectedExecutionException ignore)
{
@@ -193,14 +193,12 @@ public class FullDataSourceProviderV2 implements IDebugRenderable, AutoCloseable
/**
* Should only be used in internal file handler methods where we are already running on a file handler thread.
* Can return null if the repo is in the process of being shut down
* @see FullDataSourceProviderV2#getAsync(long, boolean)
* @see FullDataSourceProviderV2#getAsync(long)
*/
@Nullable
public FullDataSourceV2 get(long pos, boolean includeAdjacentData)
public FullDataSourceV2 get(long pos)
{
try(FullDataSourceV2DTO dto = includeAdjacentData
? this.repo.getByKey(pos)
: this.repo.getByPosNoAdj(pos))
try(FullDataSourceV2DTO dto = this.repo.getByPosNoAdj(pos))
{
if (dto == null)
{
@@ -245,10 +243,16 @@ public class FullDataSourceProviderV2 implements IDebugRenderable, AutoCloseable
//
// TODO name?
//
//=================//
// partial getters //
//=================//
/**
* Only returns the data row/column for the given compass-cardinal
* direction. <br>
* This is generally used for generating LOD render data
* where we only need the adjacent data, not the full thing.
*/
public FullDataSourceV2 getAdjForDirection(long pos, EDhDirection direction)
{
try(FullDataSourceV2DTO dto = this.repo.getAdjByPosAndDirection(pos, direction))
@@ -279,36 +283,6 @@ public class FullDataSourceProviderV2 implements IDebugRenderable, AutoCloseable
return null;
}
public FullDataSourceV2 getCenter(long pos)
{
try(FullDataSourceV2DTO dto = this.repo.getByPosNoAdj(pos))
{
if (dto == null)
{
return FullDataSourceV2.createEmpty(pos);
}
try
{
// load from database
return this.createDataSourceFromDto(dto);
}
catch (DataCorruptedException e)
{
this.tryLogCorruptedDataError(DhSectionPos.toString(pos), e);
this.repo.deleteWithKey(pos);
}
}
catch (InterruptedException ignore) { }
catch (IOException e)
{
LOGGER.warn("File read Error for pos ["+DhSectionPos.toString(pos)+"], error: "+e.getMessage(), e);
}
// an error occurred
return null;
}
//=======================//
@@ -183,7 +183,7 @@ public class FullDataUpdatePropagatorV2 implements IDebugRenderable, AutoCloseab
parentLocked = true;
this.dataUpdater.lockedPosSet.add(parentUpdatePos);
try (FullDataSourceV2 parentDataSource = this.provider.get(parentUpdatePos, false))
try (FullDataSourceV2 parentDataSource = this.provider.get(parentUpdatePos))
{
// will return null if the file handler is shutting down
if (parentDataSource != null)
@@ -197,7 +197,7 @@ public class FullDataUpdatePropagatorV2 implements IDebugRenderable, AutoCloseab
childReadLock.lock();
this.dataUpdater.lockedPosSet.add(childPos);
try (FullDataSourceV2 childDataSource = this.provider.get(childPos, false))
try (FullDataSourceV2 childDataSource = this.provider.get(childPos))
{
// can return null when the file handler is being shut down
if (childDataSource != null)
@@ -299,7 +299,7 @@ public class FullDataUpdatePropagatorV2 implements IDebugRenderable, AutoCloseab
parentLocked = true;
this.dataUpdater.lockedPosSet.add(parentUpdatePos);
try (FullDataSourceV2 parentDataSource = this.provider.get(parentUpdatePos, false))
try (FullDataSourceV2 parentDataSource = this.provider.get(parentUpdatePos))
{
// will return null if the file handler is shutting down
if (parentDataSource != null)
@@ -315,7 +315,7 @@ public class FullDataUpdatePropagatorV2 implements IDebugRenderable, AutoCloseab
childWriteLock.lock();
this.dataUpdater.lockedPosSet.add(childPos);
try (FullDataSourceV2 childDataSource = this.provider.get(childPos, false))
try (FullDataSourceV2 childDataSource = this.provider.get(childPos))
{
// will return null if the file handler is shutting down
if (childDataSource != null)
@@ -122,7 +122,7 @@ public class FullDataUpdaterV2 implements IDebugRenderable, AutoCloseable
// get or create the data source
try (FullDataSourceV2 recipientDataSource = this.provider.get(updatePos, false))
try (FullDataSourceV2 recipientDataSource = this.provider.get(updatePos))
{
if (recipientDataSource != null)
{
@@ -140,7 +140,7 @@ public class PregenManager
}
this.pendingGenerations.put(nextSectionPos, System.currentTimeMillis());
this.fullDataSourceProvider.getAsync(nextSectionPos, false)
this.fullDataSourceProvider.getAsync(nextSectionPos)
.thenAccept(fullDataSource ->
{
if (this.fullDataSourceProvider.isFullyGenerated(fullDataSource.columnGenerationSteps))
@@ -99,7 +99,7 @@ public class FullDataSourceRequestHandler
}
// get the server's datasource
return this.fullDataSourceProvider().get(message.sectionPos, false);
return this.fullDataSourceProvider().get(message.sectionPos);
}
catch (Exception e)
{
@@ -262,7 +262,7 @@ public class FullDataSourceRequestHandler
private void tryFulfillDataSourceRequestGroup(DataSourceRequestGroup requestGroup, long pos)
{
this.fullDataSourceProvider().getAsync(pos, false).thenAccept(fullDataSource ->
this.fullDataSourceProvider().getAsync(pos).thenAccept(fullDataSource ->
{
if (this.fullDataSourceProvider().isFullyGenerated(fullDataSource.columnGenerationSteps))
{
@@ -356,7 +356,7 @@ public class LodRenderSection implements IDebugRenderable, AutoCloseable
try (FullDataSourceV2 fullDataSource =
// no direction means get the center LOD
(direction == null)
? this.fullDataSourceProvider.getCenter(finalPos)
? this.fullDataSourceProvider.get(finalPos)
: this.fullDataSourceProvider.getAdjForDirection(finalPos, direction.opposite()))
{
getFull.end();
@@ -356,12 +356,6 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<Long, FullDataSourceV2D
" WHERE DetailLevel = ? AND PosX = ? AND PosZ = ?; \n";
public PreparedStatement createNoAdjSelectStatementByKey(Long key) throws SQLException
{
//// create shared template string
//if (this.selectSqlTemplate == null)
//{
// this.selectSqlTemplate = this.limitedSelectSqlTemplate;
//}
PreparedStatement statement = this.createPreparedStatement(this.noAdjSelectSqlTemplate);
if (statement == null)
{