Add scaling object cap for usermap, prevent huge memory usage, also config file configurable.

This commit is contained in:
KHobbits 2013-07-17 01:56:27 +01:00
parent bf675b230e
commit e8d9951ee8
3 changed files with 17 additions and 7 deletions

View File

@ -146,7 +146,7 @@ public interface ISettings extends IConf
boolean areDeathMessagesEnabled();
public void setDebug(boolean debug);
void setDebug(boolean debug);
Set<String> getNoGodWorlds();
@ -184,15 +184,17 @@ public interface ISettings extends IConf
double getMaxWalkSpeed();
public int getMailsPerMinute();
int getMailsPerMinute();
public long getEconomyLagWarning();
long getEconomyLagWarning();
public void setEssentialsChatActive(boolean b);
void setEssentialsChatActive(boolean b);
long getMaxTempban();
public Map<String, Object> getListGroupConfig();
Map<String, Object> getListGroupConfig();
public int getMaxNickLength();
int getMaxNickLength();
int getMaxUserCacheCount();
}

View File

@ -1105,4 +1105,11 @@ public class Settings implements net.ess3.api.ISettings
{
return config.getInt("max-nick-length", 30);
}
public int getMaxUserCacheCount()
{
long count = Runtime.getRuntime().maxMemory() / 1024 / 96;
return config.getInt("max-user-cache-count", (int)count);
}
}

View File

@ -17,13 +17,14 @@ import org.bukkit.entity.Player;
public class UserMap extends CacheLoader<String, User> implements IConf
{
private final transient IEssentials ess;
private final transient Cache<String, User> users = CacheBuilder.newBuilder().softValues().build(this);
private final transient Cache<String, User> users;
private final transient ConcurrentSkipListSet<String> keys = new ConcurrentSkipListSet<String>();
public UserMap(final IEssentials ess)
{
super();
this.ess = ess;
users = CacheBuilder.newBuilder().maximumSize(ess.getSettings().getMaxUserCacheCount()).softValues().build(this);
loadAllUsersAsync(ess);
}