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'
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
sourceSets {
@ -19,11 +19,6 @@ sourceSets {
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
api 'com.google.code.gson:gson:2.8.6'
api "com.google.guava:guava:${guavaVersion}"

Datei anzeigen

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