3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Update java version. Switch to caffeine cache to allow null values.

Dieser Commit ist enthalten in:
Seppe Volkaerts 2020-12-15 13:05:32 +01:00
Ursprung b04d5de141
Commit d0a61e8704
3 geänderte Dateien mit 14 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -9,8 +9,8 @@ apply from: '../gradle/publish.gradle'
apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'com.github.johnrengelman.shadow'
java { java {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_11
} }
sourceSets { sourceSets {
@ -19,11 +19,6 @@ sourceSets {
} }
} }
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies { dependencies {
api 'com.google.code.gson:gson:2.8.6' api 'com.google.code.gson:gson:2.8.6'
api "com.google.guava:guava:${guavaVersion}" api "com.google.guava:guava:${guavaVersion}"

Datei anzeigen

@ -9,8 +9,8 @@ apply from: '../gradle/checkstyle.gradle'
apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'com.github.johnrengelman.shadow'
java { java {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_11
} }
test { test {
@ -79,6 +79,8 @@ dependencies {
implementation 'org.lanternpowered:lmbda:2.0.0-SNAPSHOT' implementation 'org.lanternpowered:lmbda:2.0.0-SNAPSHOT'
implementation 'com.github.ben-manes.caffeine:caffeine:2.8.8'
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.1.2' compileOnly 'com.github.spotbugs:spotbugs-annotations:4.1.2'
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}" testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"

Datei anzeigen

@ -2,9 +2,8 @@ package com.velocitypowered.proxy.event;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import com.google.common.cache.CacheBuilder; import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.common.cache.CacheLoader; import com.github.benmanes.caffeine.cache.LoadingCache;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
@ -40,7 +39,6 @@ import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.lanternpowered.lmbda.LambdaFactory; import org.lanternpowered.lmbda.LambdaFactory;
import org.lanternpowered.lmbda.LambdaType; import org.lanternpowered.lmbda.LambdaType;
@ -63,20 +61,10 @@ public class VelocityEventManager implements EventManager {
private final Multimap<Class<?>, HandlerRegistration> handlersByType = HashMultimap.create(); private final Multimap<Class<?>, HandlerRegistration> handlersByType = HashMultimap.create();
private final LoadingCache<Class<?>, @Nullable HandlersCache> handlersCache = private final LoadingCache<Class<?>, @Nullable HandlersCache> handlersCache =
CacheBuilder.newBuilder().build(new CacheLoader<>() { Caffeine.newBuilder().build(this::bakeHandlers);
@Override
public @Nullable HandlersCache load(final @NonNull Class<?> key) {
return bakeHandlers(key);
}
});
private final LoadingCache<Method, UntargetedEventHandler> untargetedMethodHandlers = private final LoadingCache<Method, UntargetedEventHandler> untargetedMethodHandlers =
CacheBuilder.newBuilder().weakValues().build(new CacheLoader<>() { Caffeine.newBuilder().weakValues().build(this::buildUntargetedMethodHandler);
@Override
public UntargetedEventHandler load(final @NonNull Method key) throws Exception {
return buildUntargetedMethodHandler(key);
}
});
private final ReadWriteLock lock = new ReentrantReadWriteLock(); private final ReadWriteLock lock = new ReentrantReadWriteLock();
@ -327,7 +315,8 @@ public class VelocityEventManager implements EventManager {
continue; continue;
} }
final UntargetedEventHandler untargetedHandler = final UntargetedEventHandler untargetedHandler =
untargetedMethodHandlers.getUnchecked(info.method); untargetedMethodHandlers.get(info.method);
requireNonNull(untargetedHandler);
final EventHandler<Object> handler = event -> untargetedHandler.execute(listener, event); final EventHandler<Object> handler = event -> untargetedHandler.execute(listener, event);
registrations.add(new HandlerRegistration(pluginContainer, info.order, registrations.add(new HandlerRegistration(pluginContainer, info.order,
info.eventType, listener, handler, info.asyncType)); info.eventType, listener, handler, info.asyncType));
@ -394,7 +383,7 @@ public class VelocityEventManager implements EventManager {
@Override @Override
public void fireAndForget(final Object event) { public void fireAndForget(final Object event) {
requireNonNull(event, "event"); requireNonNull(event, "event");
final HandlersCache handlersCache = this.handlersCache.getUnchecked(event.getClass()); final HandlersCache handlersCache = this.handlersCache.get(event.getClass());
if (handlersCache == null) { if (handlersCache == null) {
// Optimization: nobody's listening. // Optimization: nobody's listening.
return; return;
@ -405,7 +394,7 @@ public class VelocityEventManager implements EventManager {
@Override @Override
public <E> CompletableFuture<E> fire(final E event) { public <E> CompletableFuture<E> fire(final E event) {
requireNonNull(event, "event"); requireNonNull(event, "event");
final HandlersCache handlersCache = this.handlersCache.getUnchecked(event.getClass()); final HandlersCache handlersCache = this.handlersCache.get(event.getClass());
if (handlersCache == null) { if (handlersCache == null) {
// Optimization: nobody's listening. // Optimization: nobody's listening.
return CompletableFuture.completedFuture(event); return CompletableFuture.completedFuture(event);