Use JDK map for throttle

This commit is contained in:
md_5 2013-09-28 18:32:39 +10:00
parent 59b32a8621
commit 8e77cb35ff

View File

@ -2,13 +2,15 @@ package net.md_5.bungee;
import gnu.trove.map.hash.TObjectLongHashMap; import gnu.trove.map.hash.TObjectLongHashMap;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public class ConnectionThrottle public class ConnectionThrottle
{ {
private final TObjectLongHashMap<InetAddress> throttle = new TObjectLongHashMap<>(); private final Map<InetAddress, Long> throttle = new HashMap<>();
private final int throttleTime; private final int throttleTime;
public void unthrottle(InetAddress address) public void unthrottle(InetAddress address)
@ -18,10 +20,10 @@ public class ConnectionThrottle
public boolean throttle(InetAddress address) public boolean throttle(InetAddress address)
{ {
long value = throttle.get( address ); Long value = throttle.get( address );
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
throttle.put( address, currentTime ); throttle.put( address, currentTime );
return value != 0 && currentTime - value < throttleTime; return value != null && currentTime - value < throttleTime;
} }
} }