Skip to content

Commit

Permalink
Remove the chunk from the pending operation queue's when it is removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvandoosselaer committed Mar 9, 2020
1 parent 6eb18ed commit fc7390d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/rvandoosselaer/blocks/ChunkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public void removeChunk(Chunk chunk) {
assertInitialized();

if (chunk != null) {
cancelAllPendingOperations(chunk);

cache.evict(chunk.getLocation());
}
}
Expand Down Expand Up @@ -575,6 +577,20 @@ private void performCacheMaintenance() {
}
}

/**
* Cancel all pending operations for this chunk. When invoked, the chunk will be remove from all queues.
*
* @param chunk to cancel operations for
*/
private void cancelAllPendingOperations(Chunk chunk) {
if (log.isDebugEnabled()) {
log.debug("Stopping pending tasks for {}", chunk);
}
loadingQueue.remove(chunk.getLocation());
generatorQueue.remove(chunk.getLocation());
meshQueue.remove(chunk);
}

/**
* Helper method to add an element to a queue, making sure we don't add the same element multiple times.
*
Expand Down

0 comments on commit fc7390d

Please sign in to comment.