|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.DuplicateIDChecker<K>
public final class DuplicateIDChecker<K>
Mechanism to check for replayed/duplicate messages by ID within a specified time window. This provides an optional fixed upper size; attempts to insert more items than the ceiling capacity will result in old items being removed in age order regardless of age.
Other after meeting any size limit, this always keeps entries for a specified minimum time. Optionally a larger time window may be used if the the system is not starved of memory.
Thread-safe.
A lock can be held on instances of this object to make compound operations atomic.
Does not support the full Map interface.
This aggressively trims dead/expired entries so as to minimise footprint.
| Field Summary | |
|---|---|
static float |
DEFAULT_LOAD_FACTOR
Default load factor. |
private java.util.LinkedHashMap<K,java.lang.Long> |
lhm
Underlying LinkedHashMap on which this is based; never null. |
private int |
minRetentionMs
Maximum age that we will retain IDs for (ms); strictly positive. |
private java.lang.String |
name
Name of this instance for diagnostics purposes; null if none. |
private int |
preferredRetentionMs
Optional higher maximum age that we will retain IDs for when there's plenty of memory available (ms); strictly positive. |
| Constructor Summary | |
|---|---|
private |
DuplicateIDChecker(int minRetentionMs,
int preferredRetentionMs,
int maxCapacity,
float loadFactor,
java.lang.String name)
Create an instance with the given parameters. |
| Method Summary | ||
|---|---|---|
void |
_compact()
Try to trim all dead entries to reduce memory footprint. |
|
java.lang.Long |
add(K key)
Record an ID, returning the insertion time of the previous insertion of this ID if any. |
|
java.lang.Long |
ageOfOldestEntry()
Returns the timestamp of the oldest entry currently in this Map, or null if none. |
|
void |
clear()
Clear the structure. |
|
void |
compact()
Try to trim all dead entries to reduce memory footprint. |
|
boolean |
containsKey(K key)
Returns true if we have a mapping from the supplied key (message ID), false otherwise. |
|
static
|
create(int minRetentionMs,
int preferredRetentionMs,
int maxCapacity,
float loadFactor,
java.lang.String name)
Create an instance with the given parameters. |
|
static
|
create(int minRetentionMs,
int preferredRetentionMs,
java.lang.String name)
Create an instance with the given parameters. |
|
static
|
create(int minRetentionMs,
java.lang.String name)
Create an instance with the given parameters. |
|
private boolean |
hasExpired(java.util.Map.Entry<K,java.lang.Long> entry)
Returns true when an entry has expired and can be removed. |
|
private boolean |
hasExpired(java.util.Map.Entry<K,java.lang.Long> entry,
long thresholdTime)
Returns true when an entry has expired and can be removed. |
|
java.lang.Long |
remove(K key)
Remove an ID and return the insertion time of the removed ID, if any, else null. |
|
int |
size()
Return the number of non-expired IDs held; non-negative. |
|
private long |
thresholdTime()
Compute threshold time for entry expiry. |
|
java.lang.String |
toString()
Provide a human-readable summary of status. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final float DEFAULT_LOAD_FACTOR
private final java.util.LinkedHashMap<K,java.lang.Long> lhm
private final int minRetentionMs
private final int preferredRetentionMs
private final java.lang.String name
| Constructor Detail |
|---|
private DuplicateIDChecker(int minRetentionMs,
int preferredRetentionMs,
int maxCapacity,
float loadFactor,
java.lang.String name)
minRetentionMs - the minimum time that we will keep an ID for (ms);
strictly positivepreferredRetentionMs - preferred time to retain entries if there is lots of free memory
and ineffective/ignored unless larger than minRetentionMs;
strictly positivemaxCapacity - the maximum capacity; strictly positiveloadFactor - the load factor of the underlying hash table;
in the range 0.0f to 1.0f exclusive (typically ~0.7f)| Method Detail |
|---|
public static <K> DuplicateIDChecker<K> create(int minRetentionMs,
java.lang.String name)
minRetentionMs - the minimum time that we will keep an ID for (ms);
strictly positivename - name of this instance for diagnostics purposes; null if none
public static <K> DuplicateIDChecker<K> create(int minRetentionMs,
int preferredRetentionMs,
java.lang.String name)
minRetentionMs - the minimum time that we will keep an ID for (ms);
strictly positivepreferredRetentionMs - preferred time to retain entries if there is plenty of free memory
and ineffective/ignored unless larger than minRetentionMs;
strictly positivename - name of this instance for diagnostics purposes; null if none
public static <K> DuplicateIDChecker<K> create(int minRetentionMs,
int preferredRetentionMs,
int maxCapacity,
float loadFactor,
java.lang.String name)
minRetentionMs - the minimum time that we will keep an ID for (ms);
strictly positivepreferredRetentionMs - preferred time to retain entries if there is plenty of free memory
and ineffective/ignored unless larger than minRetentionMs;
strictly positivemaxCapacity - the maximum capacity; strictly positiveloadFactor - the load factor of the underlying hash table;
in the range 0.0f to 1.0f exclusive (typically ~0.7f)name - name of this instance for diagnostics purposes; null if nonepublic void compact()
compact in interface MemoryTools.Compactablepublic void _compact()
Must only be called while the instance lock is held.
public boolean containsKey(K key)
This ignores expired values and does not add anything to the collection.
public java.lang.Long add(K key)
public java.lang.Long remove(K key)
public java.lang.Long ageOfOldestEntry()
public void clear()
public int size()
public java.lang.String toString()
toString in class java.lang.Object
private boolean hasExpired(java.util.Map.Entry<K,java.lang.Long> entry,
long thresholdTime)
entry - full entry including the timestamp; never nullthresholdTime - expiry threshold time to use,
an older entry should be expiredprivate long thresholdTime()
This is made proportional so that transients are less likely to discard a slow-to-regain acceptance window.
private boolean hasExpired(java.util.Map.Entry<K,java.lang.Long> entry)
entry - full entry including the timestamp; never null
|
DHD Multimedia Gallery V1.53.0 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||