mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
refactor: minor adjustments to error handling (ignoring) and blocking queue (#2566)
This commit is contained in:
parent
033b8e35d2
commit
a502287906
@ -612,12 +612,38 @@ public enum FaweCache implements Trimable {
|
||||
/*
|
||||
Thread stuff
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a new blocking executor with default name and FaweCache logger
|
||||
*
|
||||
* @return new blocking executor
|
||||
*/
|
||||
public ThreadPoolExecutor newBlockingExecutor() {
|
||||
return newBlockingExecutor("FAWE Blocking Executor - %d");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new blocking executor with specified name and FaweCache logger
|
||||
*
|
||||
* @return new blocking executor
|
||||
* @since TODO
|
||||
*/
|
||||
public ThreadPoolExecutor newBlockingExecutor(String name) {
|
||||
return newBlockingExecutor(name, LOGGER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new blocking executor with specified name and logger
|
||||
*
|
||||
* @return new blocking executor
|
||||
* @since TODO
|
||||
*/
|
||||
public ThreadPoolExecutor newBlockingExecutor(String name, Logger logger) {
|
||||
int nThreads = Settings.settings().QUEUE.PARALLEL_THREADS;
|
||||
ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(nThreads, true);
|
||||
return new ThreadPoolExecutor(nThreads, nThreads,
|
||||
0L, TimeUnit.MILLISECONDS, queue,
|
||||
new ThreadFactoryBuilder().setNameFormat("FAWE Blocking Executor - %d").build(),
|
||||
new ThreadFactoryBuilder().setNameFormat(name).build(),
|
||||
new ThreadPoolExecutor.CallerRunsPolicy()
|
||||
) {
|
||||
|
||||
@ -652,10 +678,10 @@ public enum FaweCache implements Trimable {
|
||||
int hash = throwable.getMessage() != null ? throwable.getMessage().hashCode() : 0;
|
||||
if (hash != lastException) {
|
||||
lastException = hash;
|
||||
LOGGER.catching(throwable);
|
||||
logger.catching(throwable);
|
||||
count = 0;
|
||||
} else if (count < Settings.settings().QUEUE.PARALLEL_THREADS) {
|
||||
LOGGER.warn(throwable.getMessage());
|
||||
logger.warn(throwable.getMessage());
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@ -665,10 +691,10 @@ public enum FaweCache implements Trimable {
|
||||
private void handleFaweException(FaweException e) {
|
||||
FaweException.Type type = e.getType();
|
||||
if (e.getType() == FaweException.Type.OTHER) {
|
||||
LOGGER.catching(e);
|
||||
logger.catching(e);
|
||||
} else if (!faweExceptionReasonsUsed[type.ordinal()]) {
|
||||
faweExceptionReasonsUsed[type.ordinal()] = true;
|
||||
LOGGER.warn("FaweException: " + e.getMessage());
|
||||
logger.warn("FaweException: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -68,7 +68,8 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
* Main "work-horse" queue for FAWE. Handles chunk submission (and chunk submission alone). Blocking in order to forcibly
|
||||
* prevent overworking/over-submission of chunk process tasks.
|
||||
*/
|
||||
private final ThreadPoolExecutor blockingExecutor = FaweCache.INSTANCE.newBlockingExecutor();
|
||||
private final ThreadPoolExecutor blockingExecutor = FaweCache.INSTANCE.newBlockingExecutor(
|
||||
"FAWE QueueHandler Blocking Executor - %d");
|
||||
/**
|
||||
* Queue for tasks to be completed on the main thread. These take priority of tasks submitted to syncWhenFree queue
|
||||
*/
|
||||
|
@ -158,6 +158,7 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen
|
||||
this.setProcessor(EmptyBatchProcessor.getInstance());
|
||||
this.setPostProcessor(EmptyBatchProcessor.getInstance());
|
||||
this.world = null;
|
||||
this.faweExceptionReasonsUsed = new boolean[FaweException.Type.values().length];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@ import com.fastasyncworldedit.core.queue.IChunkSet;
|
||||
import com.fastasyncworldedit.core.queue.IQueueChunk;
|
||||
import com.fastasyncworldedit.core.queue.IQueueExtent;
|
||||
import com.fastasyncworldedit.core.queue.Pool;
|
||||
import com.fastasyncworldedit.core.util.MemUtil;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
@ -959,7 +960,7 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
|
||||
public final IChunkGet getOrCreateGet() {
|
||||
if (chunkExisting == null) {
|
||||
chunkExisting = newWrappedGet();
|
||||
chunkExisting.trim(false);
|
||||
chunkExisting.trim(MemUtil.isMemoryLimited());
|
||||
}
|
||||
return chunkExisting;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user