Ensure forceSync is provided when constructing chunk coordinators (#3657)

* Ensure forceSync is provided when constructing chunk coordinators

* Re-add old factory create method and deprecate for removal

* Remove old create method that Guice doesn't like
This commit is contained in:
Jordan 2022-06-12 09:47:43 +01:00 committed by GitHub
parent a238ff19bf
commit b9479405e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 10 deletions

View File

@ -92,9 +92,9 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
@Assisted final @NonNull Collection<BlockVector2> requestedChunks,
@Assisted final @NonNull Runnable whenDone,
@Assisted final @NonNull Consumer<Throwable> throwableConsumer,
@Assisted final boolean unloadAfter,
@Assisted("unloadAfter") final boolean unloadAfter,
@Assisted final @NonNull Collection<ProgressSubscriber> progressSubscribers,
@Assisted final boolean forceSync
@Assisted("forceSync") final boolean forceSync
) {
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
this.availableChunks = new LinkedBlockingQueue<>();

View File

@ -235,6 +235,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
.withConsumer(consumer)
.unloadAfter(isUnloadAfter())
.withProgressSubscribers(getProgressSubscribers())
.forceSync(isForceSync())
.build();
return super.enqueue();
}

View File

@ -25,6 +25,7 @@
*/
package com.plotsquared.core.inject.factory;
import com.google.inject.assistedinject.Assisted;
import com.plotsquared.core.queue.ChunkCoordinator;
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
import com.sk89q.worldedit.math.BlockVector2;
@ -44,8 +45,9 @@ public interface ChunkCoordinatorFactory {
final @NonNull Collection<BlockVector2> requestedChunks,
final @NonNull Runnable whenDone,
final @NonNull Consumer<Throwable> throwableConsumer,
final boolean unloadAfter,
final @NonNull Collection<ProgressSubscriber> progressSubscribers
@Assisted("unloadAfter") final boolean unloadAfter,
final @NonNull Collection<ProgressSubscriber> progressSubscribers,
@Assisted("forceSync") final boolean forceSync
);
}

View File

@ -58,6 +58,7 @@ public class ChunkCoordinatorBuilder {
private long maxIterationTime = Settings.QUEUE.MAX_ITERATION_TIME; // A little over 1 tick;
private int initialBatchSize = Settings.QUEUE.INITIAL_BATCH_SIZE;
private boolean unloadAfter = true;
private boolean forceSync = false;
@Inject
public ChunkCoordinatorBuilder(@NonNull ChunkCoordinatorFactory chunkCoordinatorFactory) {
@ -197,6 +198,18 @@ public class ChunkCoordinatorBuilder {
return this;
}
/**
* Set whether the chunks coordinator should be forced to be synchronous. This is not necessarily synchronous to the server,
* and simply effectively makes {@link ChunkCoordinator#start()} ()} a blocking operation.
*
* @param forceSync force sync or not
* @since TODO
*/
public @NonNull ChunkCoordinatorBuilder forceSync(final boolean forceSync) {
this.forceSync = forceSync;
return this;
}
public @NonNull ChunkCoordinatorBuilder withProgressSubscriber(ProgressSubscriber progressSubscriber) {
this.progressSubscribers.add(progressSubscriber);
return this;
@ -227,7 +240,8 @@ public class ChunkCoordinatorBuilder {
this.whenDone,
this.throwableConsumer,
this.unloadAfter,
this.progressSubscribers
this.progressSubscribers,
this.forceSync
);
}

View File

@ -40,14 +40,12 @@ import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import java.util.concurrent.atomic.AtomicBoolean;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
public abstract class QueueCoordinator {
@ -119,7 +117,8 @@ public abstract class QueueCoordinator {
public abstract void setModified(long modified);
/**
* Returns true if the queue should be forced to be synchronous when enqueued.
* Returns true if the queue should be forced to be synchronous when enqueued. This is not necessarily synchronous to the
* server, and simply effectively makes {@link QueueCoordinator#enqueue()} a blocking operation.
*
* @return is force sync
*/
@ -128,7 +127,8 @@ public abstract class QueueCoordinator {
}
/**
* Set whether the queue should be forced to be synchronous
* Set whether the queue should be forced to be synchronous. This is not necessarily synchronous to the server, and simply
* effectively makes {@link QueueCoordinator#enqueue()} a blocking operation.
*
* @param forceSync force sync or not
*/