Skip to content

Commit

Permalink
Let EnginePlayerDataMap remember the last time entries were removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Feb 28, 2013
1 parent 84d82ff commit f03ffcf
Showing 1 changed file with 23 additions and 1 deletion.
@@ -1,5 +1,7 @@
package fr.neatmonster.nocheatplus.checks.chat.analysis.engine;

import java.util.Collection;

import fr.neatmonster.nocheatplus.checks.chat.ChatConfig;
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.processors.WordProcessor;
import fr.neatmonster.nocheatplus.utilities.ds.ManagedMap;
Expand All @@ -13,7 +15,11 @@ public class EnginePlayerDataMap extends ManagedMap<String, EnginePlayerData> {

protected long durExpire;

/** Timestamp of last time get was called.*/
protected long lastAccess = System.currentTimeMillis();

/** Timestamp of last time an entry was removed. */
protected long lastExpired = lastAccess;

public EnginePlayerDataMap(long durExpire, int defaultCapacity, float loadFactor) {
super(defaultCapacity, loadFactor);
Expand All @@ -33,7 +39,11 @@ public EnginePlayerData get(final String key, final ChatConfig cc) {
put(key, data);
}
final long ts = System.currentTimeMillis();
if (ts - lastAccess > durExpire) expire(ts - durExpire);
if (ts < lastExpired){
lastExpired = ts;
// might clear map or update all entries.
}
else if (ts - lastExpired > durExpire) expire(ts - durExpire);
lastAccess = ts;
return data;
}
Expand All @@ -47,4 +57,16 @@ public void clear(){
super.clear();
}

/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.utilities.ds.ManagedMap#expire(long)
*/
@Override
public Collection<String> expire(long ts) {
final Collection<String> rem = super.expire(ts);
if (!rem.isEmpty()) lastExpired = System.currentTimeMillis();
return rem;
}



}

0 comments on commit f03ffcf

Please sign in to comment.