Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Directly add dependent futures to the list instead of waiting for the extra boolean
Dieser Commit ist enthalten in:
Ursprung
e4bac5f81a
Commit
24ebb77860
@ -6,7 +6,6 @@ import com.google.gson.JsonIOException;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
|
||||||
import us.myles.ViaVersion.util.GsonUtil;
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -34,7 +33,6 @@ public class MappingDataLoader {
|
|||||||
|
|
||||||
public static void enableMappingsCache() {
|
public static void enableMappingsCache() {
|
||||||
cacheJsonMappings = true;
|
cacheJsonMappings = true;
|
||||||
ProtocolRegistry.setKeepExecutorLoaded(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +61,6 @@ public class ProtocolRegistry {
|
|||||||
private static Map<Class<? extends Protocol>, CompletableFuture<Void>> mappingLoaderFutures = new HashMap<>();
|
private static Map<Class<? extends Protocol>, CompletableFuture<Void>> mappingLoaderFutures = new HashMap<>();
|
||||||
private static ThreadPoolExecutor mappingLoaderExecutor;
|
private static ThreadPoolExecutor mappingLoaderExecutor;
|
||||||
private static boolean mappingsLoaded;
|
private static boolean mappingsLoaded;
|
||||||
private static boolean keepExecutorLoaded;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
mappingLoaderExecutor = new ThreadPoolExecutor(5, 16, 45L, TimeUnit.SECONDS, new SynchronousQueue<>());
|
mappingLoaderExecutor = new ThreadPoolExecutor(5, 16, 45L, TimeUnit.SECONDS, new SynchronousQueue<>());
|
||||||
@ -329,7 +328,7 @@ public class ProtocolRegistry {
|
|||||||
*/
|
*/
|
||||||
public static boolean checkForMappingCompletion() {
|
public static boolean checkForMappingCompletion() {
|
||||||
synchronized (MAPPING_LOADER_LOCK) {
|
synchronized (MAPPING_LOADER_LOCK) {
|
||||||
if (mappingsLoaded || keepExecutorLoaded) return false;
|
if (mappingsLoaded) return false;
|
||||||
|
|
||||||
for (CompletableFuture<Void> future : mappingLoaderFutures.values()) {
|
for (CompletableFuture<Void> future : mappingLoaderFutures.values()) {
|
||||||
// Return if any future hasn't completed yet
|
// Return if any future hasn't completed yet
|
||||||
@ -361,19 +360,17 @@ public class ProtocolRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Class<? extends Protocol> dependsOn, Runnable runnable) {
|
||||||
|
synchronized (MAPPING_LOADER_LOCK) {
|
||||||
|
CompletableFuture<Void> future = getMappingLoaderFuture(dependsOn).whenCompleteAsync((v, throwable) -> runnable.run(), mappingLoaderExecutor);
|
||||||
|
mappingLoaderFutures.put(protocolClass, future);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static CompletableFuture<Void> getMappingLoaderFuture(Class<? extends Protocol> protocolClass) {
|
public static CompletableFuture<Void> getMappingLoaderFuture(Class<? extends Protocol> protocolClass) {
|
||||||
synchronized (MAPPING_LOADER_LOCK) {
|
synchronized (MAPPING_LOADER_LOCK) {
|
||||||
if (mappingsLoaded) return null;
|
if (mappingsLoaded) return null;
|
||||||
return mappingLoaderFutures.get(protocolClass);
|
return mappingLoaderFutures.get(protocolClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* If set to true, the executor and mappings will stay loaded, even if all current futures have been completed.
|
|
||||||
*
|
|
||||||
* @param keepExecutorLoaded whether to keep the executor and mappings loaded, even if all current futures have been completed
|
|
||||||
*/
|
|
||||||
public static void setKeepExecutorLoaded(boolean keepExecutorLoaded) {
|
|
||||||
ProtocolRegistry.keepExecutorLoaded = keepExecutorLoaded;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren