diff options
author | KHobbits <rob@khobbits.co.uk> | 2013-07-17 01:56:27 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2013-07-17 01:56:27 +0100 |
commit | 25b7a91ced74a8a21552f7222faf35af799d7a44 (patch) | |
tree | bd932bbfaf4292a88d9577435b60baa10045d802 | |
parent | 78f928655a909e1f603f73af8d60411b7a9614a9 (diff) | |
download | Essentials-25b7a91ced74a8a21552f7222faf35af799d7a44.tar Essentials-25b7a91ced74a8a21552f7222faf35af799d7a44.tar.gz Essentials-25b7a91ced74a8a21552f7222faf35af799d7a44.tar.lz Essentials-25b7a91ced74a8a21552f7222faf35af799d7a44.tar.xz Essentials-25b7a91ced74a8a21552f7222faf35af799d7a44.zip |
Add scaling object cap for usermap, prevent huge memory usage, also config file configurable.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/ISettings.java | 14 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Settings.java | 7 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/UserMap.java | 3 |
3 files changed, 17 insertions, 7 deletions
diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index b9d7c1ed0..bbf11fcb1 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -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(); } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index e3916ddde..a10477e43 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -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); + } } diff --git a/Essentials/src/com/earth2me/essentials/UserMap.java b/Essentials/src/com/earth2me/essentials/UserMap.java index c2912f377..6ee46b907 100644 --- a/Essentials/src/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/com/earth2me/essentials/UserMap.java @@ -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); } |