mirror of
https://github.com/webbukkit/dynmap.git
synced 2025-01-21 07:01:39 +01:00
Merge pull request #3820 from mastermc05/v3.0
Try to fix rendering at shutdown
This commit is contained in:
commit
a2c1941585
@ -93,6 +93,9 @@ public class AsyncChunkProvider118_2 {
|
|||||||
}
|
}
|
||||||
//prepare data synchronously
|
//prepare data synchronously
|
||||||
CompletableFuture<?> future = CompletableFuture.supplyAsync(() -> {
|
CompletableFuture<?> future = CompletableFuture.supplyAsync(() -> {
|
||||||
|
//Null will mean that we save with spigot methods, which may be risky on async
|
||||||
|
//Since we're not in main thread, it now refuses new tasks because of shutdown, the risk is lower
|
||||||
|
if (!Bukkit.isPrimaryThread()) return null;
|
||||||
try {
|
try {
|
||||||
return getAsyncSaveData.invoke(null, world.getHandle(), c);
|
return getAsyncSaveData.invoke(null, world.getHandle(), c);
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
@ -103,15 +106,21 @@ public class AsyncChunkProvider118_2 {
|
|||||||
if (++currChunks > MapManager.mapman.getMaxChunkLoadsPerTick()) {
|
if (++currChunks > MapManager.mapman.getMaxChunkLoadsPerTick()) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(25); //hold the lock so other threads also won't stress main thread
|
Thread.sleep(25); //hold the lock so other threads also won't stress main thread
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException ignored) {}
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//save data asynchronously
|
//save data asynchronously
|
||||||
return () -> {
|
return () -> {
|
||||||
|
Object o = null;
|
||||||
try {
|
try {
|
||||||
return (NBTTagCompound) save.invoke(null, world.getHandle(), c, future.get());
|
o = future.get();
|
||||||
} catch (ReflectiveOperationException | ExecutionException | InterruptedException e) {
|
return (NBTTagCompound) save.invoke(null, world.getHandle(), c, o);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return null;
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
//We tried to use simple spigot methods at shutdown and failed, hopes for reading from disk
|
||||||
|
if (o == null) return null;
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (ReflectiveOperationException | ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,7 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,7 +61,14 @@ public class MapChunkCache118_2 extends GenericMapChunkCache {
|
|||||||
try {
|
try {
|
||||||
CompletableFuture<NBTTagCompound> nbt = provider.getChunk(((CraftWorld) w).getHandle(), chunk.x, chunk.z);
|
CompletableFuture<NBTTagCompound> nbt = provider.getChunk(((CraftWorld) w).getHandle(), chunk.x, chunk.z);
|
||||||
return () -> {
|
return () -> {
|
||||||
NBTTagCompound compound = nbt.join();
|
NBTTagCompound compound;
|
||||||
|
try {
|
||||||
|
compound = nbt.get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return null;
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
|
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
|
||||||
};
|
};
|
||||||
} catch (InvocationTargetException | IllegalAccessException ignored) {
|
} catch (InvocationTargetException | IllegalAccessException ignored) {
|
||||||
|
@ -92,6 +92,9 @@ public class AsyncChunkProvider119 {
|
|||||||
}
|
}
|
||||||
//prepare data synchronously
|
//prepare data synchronously
|
||||||
CompletableFuture<?> future = CompletableFuture.supplyAsync(() -> {
|
CompletableFuture<?> future = CompletableFuture.supplyAsync(() -> {
|
||||||
|
//Null will mean that we save with spigot methods, which may be risky on async
|
||||||
|
//Since we're not in main thread, it now refuses new tasks because of shutdown, the risk is lower
|
||||||
|
if (!Bukkit.isPrimaryThread()) return null;
|
||||||
try {
|
try {
|
||||||
return getAsyncSaveData.invoke(null, world.getHandle(), c);
|
return getAsyncSaveData.invoke(null, world.getHandle(), c);
|
||||||
} catch (ReflectiveOperationException e) {
|
} catch (ReflectiveOperationException e) {
|
||||||
@ -102,15 +105,21 @@ public class AsyncChunkProvider119 {
|
|||||||
if (++currChunks > MapManager.mapman.getMaxChunkLoadsPerTick()) {
|
if (++currChunks > MapManager.mapman.getMaxChunkLoadsPerTick()) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(25); //hold the lock so other threads also won't stress main thread
|
Thread.sleep(25); //hold the lock so other threads also won't stress main thread
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException ignored) {}
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//save data asynchronously
|
//save data asynchronously
|
||||||
return () -> {
|
return () -> {
|
||||||
|
Object o = null;
|
||||||
try {
|
try {
|
||||||
return (NBTTagCompound) save.invoke(null, world.getHandle(), c, future.get());
|
o = future.get();
|
||||||
} catch (ReflectiveOperationException | ExecutionException | InterruptedException e) {
|
return (NBTTagCompound) save.invoke(null, world.getHandle(), c, o);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return null;
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
//We tried to use simple spigot methods at shutdown and failed, hopes for reading from disk
|
||||||
|
if (o == null) return null;
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (ReflectiveOperationException | ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -19,6 +19,7 @@ import java.util.List;
|
|||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,7 +59,14 @@ public class MapChunkCache119 extends GenericMapChunkCache {
|
|||||||
try {
|
try {
|
||||||
CompletableFuture<NBTTagCompound> nbt = provider.getChunk(((CraftWorld) w).getHandle(), chunk.x, chunk.z);
|
CompletableFuture<NBTTagCompound> nbt = provider.getChunk(((CraftWorld) w).getHandle(), chunk.x, chunk.z);
|
||||||
return () -> {
|
return () -> {
|
||||||
NBTTagCompound compound = nbt.join();
|
NBTTagCompound compound;
|
||||||
|
try {
|
||||||
|
compound = nbt.get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return null;
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
|
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
|
||||||
};
|
};
|
||||||
} catch (InvocationTargetException | IllegalAccessException ignored) {
|
} catch (InvocationTargetException | IllegalAccessException ignored) {
|
||||||
|
Loading…
Reference in New Issue
Block a user