1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-19 14:59:20 +00:00

Use weak references for injected Netty channels

This commit is contained in:
Tim203
2022-12-27 01:08:02 +01:00
parent d3705bfd31
commit e502e0019f
2 changed files with 54 additions and 21 deletions

View File

@@ -26,27 +26,30 @@
package org.geysermc.floodgate.inject;
import io.netty.channel.Channel;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import lombok.AccessLevel;
import lombok.Getter;
import java.util.WeakHashMap;
import org.geysermc.floodgate.api.inject.InjectorAddon;
import org.geysermc.floodgate.api.inject.PlatformInjector;
public abstract class CommonPlatformInjector implements PlatformInjector {
@Getter(AccessLevel.PROTECTED)
private final Set<Channel> injectedClients = new HashSet<>();
private final Map<Channel, ?> injectedClients =
Collections.synchronizedMap(new WeakHashMap<>());
private final Map<Class<?>, InjectorAddon> addons = new HashMap<>();
protected boolean addInjectedClient(Channel channel) {
return injectedClients.add(channel);
return injectedClients.put(channel, null) != null;
}
public boolean removeInjectedClient(Channel channel) {
return injectedClients.remove(channel);
return injectedClients.remove(channel) != null;
}
public Set<Channel> injectedClients() {
return injectedClients.keySet();
}
@Override